"use strict";(self.webpackChunkfrog=self.webpackChunkfrog||[]).push([[6647],{72225:(t,e,s)=>{s.d(e,{$Q:()=>m,GF:()=>f,S9:()=>g,Vx:()=>l,ZP:()=>a,dQ:()=>c,lZ:()=>o,m5:()=>p,mF:()=>d,pi:()=>u,qE:()=>h,yJ:()=>P,zl:()=>v});var r=s(4556),i=s(37007),n=s.n(i);class a extends r.H{constructor(t){super(),this.opts=t,this.protocol="wc",this.version=2}}class o extends r.H{constructor(t,e){super(),this.core=t,this.logger=e,this.records=new Map}}class c{constructor(t,e){this.logger=t,this.core=e}}class h extends r.H{constructor(t,e){super(),this.relayer=t,this.logger=e}}class p extends r.H{constructor(t){super()}}class u{constructor(t,e,s,r){this.core=t,this.logger=e,this.name=s}}class d extends r.H{constructor(t,e){super(),this.relayer=t,this.logger=e}}class l extends r.H{constructor(t,e){super(),this.core=t,this.logger=e}}class v{constructor(t,e,s){this.core=t,this.logger=e,this.store=s}}class f{constructor(t,e){this.projectId=t,this.logger=e}}class m{constructor(t,e,s){this.core=t,this.logger=e,this.telemetryEnabled=s}}n();class g{constructor(t){this.opts=t,this.protocol="wc",this.version=2}}i.EventEmitter;class P{constructor(t){this.client=t}}},87831:(t,e,s)=>{s.d(e,{A:()=>mn});var r=s(66023),i=s(36525),n=s(29838),a=s(36647),o=s(27907),c=s(39031),h=s(37007),p=s.n(h);const u="error",d="wc@2:universal_provider:",l="https://rpc.walletconnect.org/v1/",v="generic",f=`${l}bundler`,m="default_chain_changed";var g=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof s.g<"u"?s.g:typeof self<"u"?self:{};var P=function(){this.__data__=[],this.size=0};var w=function(t,e){return t===e||t!=t&&e!=e},b=w;var y=function(t,e){for(var s=t.length;s--;)if(b(t[s][0],e))return s;return-1},C=y,_=Array.prototype.splice;var I=function(t){var e=this.__data__,s=C(e,t);return!(s<0)&&(s==e.length-1?e.pop():_.call(e,s,1),--this.size,!0)},j=y;var O=function(t){var e=this.__data__,s=j(e,t);return s<0?void 0:e[s][1]},$=y;var H=function(t){return $(this.__data__,t)>-1},q=y;var A=function(t,e){var s=this.__data__,r=q(s,t);return r<0?(++this.size,s.push([t,e])):s[r][1]=e,this},E=P,S=I,N=O,D=H,k=A;function R(t){var e=-1,s=null==t?0:t.length;for(this.clear();++e-1&&t%1==0&&t<=9007199254740991},fs=pt,ms=vs;var gs=function(t){return null!=t&&ms(t.length)&&!fs(t)},Ps=gs,ws=ss;var bs=function(t){return ws(t)&&Ps(t)},ys={exports:{}};var Cs=function(){return!1};!function(t,e){var s=W,r=Cs,i=e&&!e.nodeType&&e,n=i&&t&&!t.nodeType&&t,a=n&&n.exports===i?s.Buffer:void 0,o=(a?a.isBuffer:void 0)||r;t.exports=o}(ys,ys.exports);var _s=nt,Is=Qe,js=ss,Os=Function.prototype,$s=Object.prototype,Hs=Os.toString,qs=$s.hasOwnProperty,As=Hs.call(Object);var Es=function(t){if(!js(t)||"[object Object]"!=_s(t))return!1;var e=Is(t);if(null===e)return!0;var s=qs.call(e,"constructor")&&e.constructor;return"function"==typeof s&&s instanceof s&&Hs.call(s)==As},Ss=nt,Ns=vs,Ds=ss,ks={};ks["[object Float32Array]"]=ks["[object Float64Array]"]=ks["[object Int8Array]"]=ks["[object Int16Array]"]=ks["[object Int32Array]"]=ks["[object Uint8Array]"]=ks["[object Uint8ClampedArray]"]=ks["[object Uint16Array]"]=ks["[object Uint32Array]"]=!0,ks["[object Arguments]"]=ks["[object Array]"]=ks["[object ArrayBuffer]"]=ks["[object Boolean]"]=ks["[object DataView]"]=ks["[object Date]"]=ks["[object Error]"]=ks["[object Function]"]=ks["[object Map]"]=ks["[object Number]"]=ks["[object Object]"]=ks["[object RegExp]"]=ks["[object Set]"]=ks["[object String]"]=ks["[object WeakMap]"]=!1;var Rs=function(t){return Ds(t)&&Ns(t.length)&&!!ks[Ss(t)]};var xs=function(t){return function(e){return t(e)}},zs={exports:{}};!function(t,e){var s=J,r=e&&!e.nodeType&&e,i=r&&t&&!t.nodeType&&t,n=i&&i.exports===r&&s.process,a=function(){try{return i&&i.require&&i.require("util").types||n&&n.binding&&n.binding("util")}catch{}}();t.exports=a}(zs,zs.exports);var Fs=Rs,Ts=xs,Us=zs.exports,Ms=Us&&Us.isTypedArray,Js=Ms?Ts(Ms):Fs;var Ls=function(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]},Bs=Se,Ws=w,Vs=Object.prototype.hasOwnProperty;var Gs=function(t,e,s){var r=t[e];(!Vs.call(t,e)||!Ws(r,s)||void 0===s&&!(e in t))&&Bs(t,e,s)},Qs=Gs,Ys=Se;var Zs=function(t,e,s,r){var i=!s;s||(s={});for(var n=-1,a=e.length;++n-1&&t%1==0&&t0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}},ii=ri(ei),ni=Wr,ai=Yr,oi=ii;var ci=function(t,e){return oi(ai(t,e,ni),t+"")},hi=w,pi=gs,ui=tr,di=at;var li=function(t,e,s){if(!di(s))return!1;var r=typeof e;return!!("number"==r?pi(s)&&ui(e,s.length):"string"==r&&e in s)&&hi(s[e],t)},vi=ci,fi=li;var mi=function(t){return vi((function(e,s){var r=-1,i=s.length,n=i>1?s[i-1]:void 0,a=i>2?s[2]:void 0;for(n=t.length>3&&"function"==typeof n?(i--,n):void 0,a&&fi(s[0],s[1],a)&&(n=i<3?void 0:n,i=1),e=Object(e);++re in t?bi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,$i=(t,e)=>{for(var s in e||(e={}))Ii.call(e,s)&&Oi(t,s,e[s]);if(_i)for(var s of _i(e))ji.call(e,s)&&Oi(t,s,e[s]);return t},Hi=(t,e)=>yi(t,Ci(e));function qi(t,e,s){var r;const n=(0,i._Yb)(t);return(null==(r=e.rpcMap)?void 0:r[n.reference])||`${l}?chainId=${n.namespace}:${n.reference}&projectId=${s}`}function Ai(t){return t.includes(":")?t.split(":")[1]:t}function Ei(t){return t.map((t=>`${t.split(":")[0]}:${t.split(":")[1]}`))}function Si(t={},e={}){const s=Ni(t),r=Ni(e);return wi(s,r)}function Ni(t){var e,s,r,n;const a={};if(!(0,i.aF0)(t))return a;for(const[o,c]of Object.entries(t)){const t=(0,i.nWe)(o)?[o]:c.chains,h=c.methods||[],p=c.events||[],u=c.rpcMap||{},d=(0,i.kob)(o);a[d]=Hi($i($i({},a[d]),c),{chains:(0,i.TRk)(t,null==(e=a[d])?void 0:e.chains),methods:(0,i.TRk)(h,null==(s=a[d])?void 0:s.methods),events:(0,i.TRk)(p,null==(r=a[d])?void 0:r.events),rpcMap:$i($i({},u),null==(n=a[d])?void 0:n.rpcMap)})}return a}function Di(t){return t.includes(":")?t.split(":")[2]:t}function ki(t){const e={};for(const[s,r]of Object.entries(t)){const t=r.methods||[],n=r.events||[],a=r.accounts||[],o=(0,i.nWe)(s)?[s]:r.chains?r.chains:Ei(r.accounts);e[s]={chains:o,methods:t,events:n,accounts:a}}return e}function Ri(t){return"number"==typeof t?t:t.includes("0x")?parseInt(t,16):(t=t.includes(":")?t.split(":")[1]:t,isNaN(Number(t))?t:Number(t))}const xi={},zi=t=>xi[t],Fi=(t,e)=>{xi[t]=e};class Ti{constructor(t){this.name="polkadot",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,e){this.httpProviders[t]||this.setHttpProvider(t,e),this.chainId=t,this.events.emit(m,`${this.name}:${t}`)}getAccounts(){const t=this.namespace.accounts;return t&&t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2]))||[]}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{var s;const r=Ai(e);t[r]=this.createHttpProvider(r,null==(s=this.namespace.rpcMap)?void 0:s[e])})),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||qi(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new o.F(new a.A(s,zi("disableProviderPing")))}}var Ui=Object.defineProperty,Mi=Object.defineProperties,Ji=Object.getOwnPropertyDescriptors,Li=Object.getOwnPropertySymbols,Bi=Object.prototype.hasOwnProperty,Wi=Object.prototype.propertyIsEnumerable,Vi=(t,e,s)=>e in t?Ui(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,Gi=(t,e)=>{for(var s in e||(e={}))Bi.call(e,s)&&Vi(t,s,e[s]);if(Li)for(var s of Li(e))Wi.call(e,s)&&Vi(t,s,e[s]);return t},Qi=(t,e)=>Mi(t,Ji(e));class Yi{constructor(t){this.name="eip155",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.httpProviders=this.createHttpProviders(),this.chainId=parseInt(this.getDefaultChain())}async request(t){switch(t.request.method){case"eth_requestAccounts":case"eth_accounts":return this.getAccounts();case"wallet_switchEthereumChain":return await this.handleSwitchChain(t);case"eth_chainId":return parseInt(this.getDefaultChain());case"wallet_getCapabilities":return await this.getCapabilities(t);case"wallet_getCallsStatus":return await this.getCallStatus(t)}return this.namespace.methods.includes(t.request.method)?await this.client.request(t):this.getHttpProvider().request(t.request)}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}setDefaultChain(t,e){this.httpProviders[t]||this.setHttpProvider(parseInt(t),e),this.chainId=parseInt(t),this.events.emit(m,`${this.name}:${t}`)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId.toString();if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}createHttpProvider(t,e){const s=e||qi(`${this.name}:${t}`,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new o.F(new a.V(s,zi("disableProviderPing")))}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{var s;const r=parseInt(Ai(e));t[r]=this.createHttpProvider(r,null==(s=this.namespace.rpcMap)?void 0:s[e])})),t}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2])))]:[]}getHttpProvider(){const t=this.chainId,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}async handleSwitchChain(t){var e,s;let r=t.request.params?null==(e=t.request.params[0])?void 0:e.chainId:"0x0";r=r.startsWith("0x")?r:`0x${r}`;const i=parseInt(r,16);if(this.isChainApproved(i))this.setDefaultChain(`${i}`);else{if(!this.namespace.methods.includes("wallet_switchEthereumChain"))throw new Error(`Failed to switch to chain 'eip155:${i}'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method.`);await this.client.request({topic:t.topic,request:{method:t.request.method,params:[{chainId:r}]},chainId:null==(s=this.namespace.chains)?void 0:s[0]}),this.setDefaultChain(`${i}`)}return null}isChainApproved(t){return this.namespace.chains.includes(`${this.name}:${t}`)}async getCapabilities(t){var e,s,r;const i=null==(s=null==(e=t.request)?void 0:e.params)?void 0:s[0];if(!i)throw new Error("Missing address parameter in `wallet_getCapabilities` request");const n=this.client.session.get(t.topic),a=(null==(r=n?.sessionProperties)?void 0:r.capabilities)||{};if(null!=a&&a[i])return a?.[i];const o=await this.client.request(t);try{await this.client.session.update(t.topic,{sessionProperties:Qi(Gi({},n.sessionProperties||{}),{capabilities:Qi(Gi({},a||{}),{[i]:o})})})}catch(t){}return o}async getCallStatus(t){var e,s;const r=this.client.session.get(t.topic),i=null==(e=r.sessionProperties)?void 0:e.bundler_name;if(i){const e=this.getBundlerUrl(t.chainId,i);try{return await this.getUserOperationReceipt(e,t)}catch(t){}}const n=null==(s=r.sessionProperties)?void 0:s.bundler_url;if(n)try{return await this.getUserOperationReceipt(n,t)}catch(t){}if(this.namespace.methods.includes(t.request.method))return await this.client.request(t);throw new Error("Fetching call status not approved by the wallet.")}async getUserOperationReceipt(t,e){var s;const r=new URL(t),i=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify((0,c.formatJsonRpcRequest)("eth_getUserOperationReceipt",[null==(s=e.request.params)?void 0:s[0]]))});if(!i.ok)throw new Error(`Failed to fetch user operation receipt - ${i.status}`);return await i.json()}getBundlerUrl(t,e){return`${f}?projectId=${this.client.core.projectId}&chainId=${t}&bundler=${e}`}}class Zi{constructor(t){this.name="solana",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,e){this.httpProviders[t]||this.setHttpProvider(t,e),this.chainId=t,this.events.emit(m,`${this.name}:${t}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2])))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{var s;const r=Ai(e);t[r]=this.createHttpProvider(r,null==(s=this.namespace.rpcMap)?void 0:s[e])})),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||qi(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new o.F(new a.A(s,zi("disableProviderPing")))}}class Ki{constructor(t){this.name="cosmos",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,e){this.httpProviders[t]||this.setHttpProvider(t,e),this.chainId=t,this.events.emit(m,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2])))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{var s;const r=Ai(e);t[r]=this.createHttpProvider(r,null==(s=this.namespace.rpcMap)?void 0:s[e])})),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||qi(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new o.F(new a.A(s,zi("disableProviderPing")))}}class Xi{constructor(t){this.name="algorand",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,e){if(!this.httpProviders[t]){const s=e||qi(`${this.name}:${t}`,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);this.setHttpProvider(t,s)}this.chainId=t,this.events.emit(m,`${this.name}:${this.chainId}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2])))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{var s;t[e]=this.createHttpProvider(e,null==(s=this.namespace.rpcMap)?void 0:s[e])})),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||qi(t,this.namespace,this.client.core.projectId);return typeof s>"u"?void 0:new o.F(new a.A(s,zi("disableProviderPing")))}}class tn{constructor(t){this.name="cip34",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,e){this.httpProviders[t]||this.setHttpProvider(t,e),this.chainId=t,this.events.emit(m,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2])))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{const s=this.getCardanoRPCUrl(e),r=Ai(e);t[r]=this.createHttpProvider(r,s)})),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}getCardanoRPCUrl(t){const e=this.namespace.rpcMap;if(e)return e[t]}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||this.getCardanoRPCUrl(t);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new o.F(new a.A(s,zi("disableProviderPing")))}}class en{constructor(t){this.name="elrond",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,e){this.httpProviders[t]||this.setHttpProvider(t,e),this.chainId=t,this.events.emit(m,`${this.name}:${t}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2])))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{var s;const r=Ai(e);t[r]=this.createHttpProvider(r,null==(s=this.namespace.rpcMap)?void 0:s[e])})),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||qi(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new o.F(new a.A(s,zi("disableProviderPing")))}}class sn{constructor(t){this.name="multiversx",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,e){this.httpProviders[t]||this.setHttpProvider(t,e),this.chainId=t,this.events.emit(m,`${this.name}:${t}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2])))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{var s;const r=Ai(e);t[r]=this.createHttpProvider(r,null==(s=this.namespace.rpcMap)?void 0:s[e])})),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||qi(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new o.F(new a.A(s,zi("disableProviderPing")))}}class rn{constructor(t){this.name="near",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,e){if(this.chainId=t,!this.httpProviders[t]){const s=e||qi(`${this.name}:${t}`,this.namespace);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);this.setHttpProvider(t,s)}this.events.emit(m,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t&&t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2]))||[]}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{var s;t[e]=this.createHttpProvider(e,null==(s=this.namespace.rpcMap)?void 0:s[e])})),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||qi(t,this.namespace);return typeof s>"u"?void 0:new o.F(new a.A(s,zi("disableProviderPing")))}}class nn{constructor(t){this.name="tezos",this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,e){if(this.chainId=t,!this.httpProviders[t]){const s=e||qi(`${this.name}:${t}`,this.namespace);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);this.setHttpProvider(t,s)}this.events.emit(m,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t&&t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2]))||[]}createHttpProviders(){const t={};return this.namespace.chains.forEach((e=>{t[e]=this.createHttpProvider(e)})),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||qi(t,this.namespace);return typeof s>"u"?void 0:new o.F(new a.A(s))}}class an{constructor(t){this.name=v,this.namespace=t.namespace,this.events=zi("events"),this.client=zi("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace.chains=[...new Set((this.namespace.chains||[]).concat(t.chains||[]))],this.namespace.accounts=[...new Set((this.namespace.accounts||[]).concat(t.accounts||[]))],this.namespace.methods=[...new Set((this.namespace.methods||[]).concat(t.methods||[]))],this.namespace.events=[...new Set((this.namespace.events||[]).concat(t.events||[]))],this.httpProviders=this.createHttpProviders()}requestAccounts(){return this.getAccounts()}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider(t.chainId).request(t.request)}setDefaultChain(t,e){this.httpProviders[t]||this.setHttpProvider(t,e),this.chainId=t,this.events.emit(m,`${this.name}:${t}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter((t=>t.split(":")[1]===this.chainId.toString())).map((t=>t.split(":")[2])))]:[]}createHttpProviders(){var t,e;const s={};return null==(e=null==(t=this.namespace)?void 0:t.accounts)||e.forEach((t=>{const e=(0,i._Yb)(t);s[`${e.namespace}:${e.reference}`]=this.createHttpProvider(t)})),s}getHttpProvider(t){const e=this.httpProviders[t];if(typeof e>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return e}setHttpProvider(t,e){const s=this.createHttpProvider(t,e);s&&(this.httpProviders[t]=s)}createHttpProvider(t,e){const s=e||qi(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new o.F(new a.A(s,zi("disableProviderPing")))}}var on=Object.defineProperty,cn=Object.defineProperties,hn=Object.getOwnPropertyDescriptors,pn=Object.getOwnPropertySymbols,un=Object.prototype.hasOwnProperty,dn=Object.prototype.propertyIsEnumerable,ln=(t,e,s)=>e in t?on(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,vn=(t,e)=>{for(var s in e||(e={}))un.call(e,s)&&ln(t,s,e[s]);if(pn)for(var s of pn(e))dn.call(e,s)&&ln(t,s,e[s]);return t},fn=(t,e)=>cn(t,hn(e));class mn{constructor(t){this.events=new(p()),this.rpcProviders={},this.shouldAbortPairingAttempt=!1,this.maxPairingAttempts=10,this.disableProviderPing=!1,this.providerOpts=t,this.logger=typeof t?.logger<"u"&&"string"!=typeof t?.logger?t.logger:(0,n.h6)((0,n.iP)({level:t?.logger||u})),this.disableProviderPing=t?.disableProviderPing||!1}static async init(t){const e=new mn(t);return await e.initialize(),e}async request(t,e,s){const[r,i]=this.validateChain(e);if(!this.session)throw new Error("Please call connect() before request()");return await this.getProvider(r).request({request:vn({},t),chainId:`${r}:${i}`,topic:this.session.topic,expiry:s})}sendAsync(t,e,s,r){const i=(new Date).getTime();this.request(t,s,r).then((t=>e(null,(0,c.formatJsonRpcResult)(i,t)))).catch((t=>e(t,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 t;if(!this.session)throw new Error("Please call connect() before enable()");await this.client.disconnect({topic:null==(t=this.session)?void 0:t.topic,reason:(0,i.Hjj)("USER_DISCONNECTED")}),await this.cleanup()}async connect(t){if(!this.client)throw new Error("Sign Client not initialized");if(this.setNamespaces(t),await this.cleanupPendingPairings(),!t.skipPairing)return await this.pair(t.pairingTopic)}async authenticate(t,e){if(!this.client)throw new Error("Sign Client not initialized");this.setNamespaces(t),await this.cleanupPendingPairings();const{uri:s,response:r}=await this.client.authenticate(t,e);s&&(this.uri=s,this.events.emit("display_uri",s));const i=await r();if(this.session=i.session,this.session){const t=ki(this.session.namespaces);this.namespaces=Si(this.namespaces,t),this.persist("namespaces",this.namespaces),this.onConnect()}return i}on(t,e){this.events.on(t,e)}once(t,e){this.events.once(t,e)}removeListener(t,e){this.events.removeListener(t,e)}off(t,e){this.events.off(t,e)}get isWalletConnect(){return!0}async pair(t){this.shouldAbortPairingAttempt=!1;let e=0;do{if(this.shouldAbortPairingAttempt)throw new Error("Pairing aborted");if(e>=this.maxPairingAttempts)throw new Error("Max auto pairing attempts reached");const{uri:s,approval:i}=await this.client.connect({pairingTopic:t,requiredNamespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties});s&&(this.uri=s,this.events.emit("display_uri",s)),await i().then((t=>{this.session=t;const e=ki(t.namespaces);this.namespaces=Si(this.namespaces,e),this.persist("namespaces",this.namespaces)})).catch((t=>{if(t.message!==r.L6)throw t;e++}))}while(!this.session);return this.onConnect(),this.session}setDefaultChain(t,e){try{if(!this.session)return;const[s,r]=this.validateChain(t),i=this.getProvider(s);i.name===v?i.setDefaultChain(`${s}:${r}`,e):i.setDefaultChain(r,e)}catch(t){if(!/Please call connect/.test(t.message))throw t}}async cleanupPendingPairings(t={}){this.logger.info("Cleaning up inactive pairings...");const e=this.client.pairing.getAll();if((0,i.OP1)(e)){for(const s of e)t.deletePairings?this.client.core.expirer.set(s.topic,0):await this.client.core.relayer.subscriber.unsubscribe(s.topic);this.logger.info(`Inactive pairings cleared: ${e.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 t=this.client.session.keys.length-1;this.session=this.client.session.get(this.client.session.keys[t]),this.createProviders()}}async initialize(){this.logger.trace("Initialized"),await this.createClient(),await this.checkStorage(),this.registerEventListeners()}async createClient(){this.client=this.providerOpts.client||await r.Ay.init({core:this.providerOpts.core,logger:this.providerOpts.logger||u,relayUrl:this.providerOpts.relayUrl||"wss://relay.walletconnect.org",projectId:this.providerOpts.projectId,metadata:this.providerOpts.metadata,storageOptions:this.providerOpts.storageOptions,storage:this.providerOpts.storage,name:this.providerOpts.name,customStoragePrefix:this.providerOpts.customStoragePrefix,telemetryEnabled:this.providerOpts.telemetryEnabled}),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()");const t=[...new Set(Object.keys(this.session.namespaces).map((t=>(0,i.kob)(t))))];Fi("client",this.client),Fi("events",this.events),Fi("disableProviderPing",this.disableProviderPing),t.forEach((t=>{if(!this.session)return;const e=function(t,e){const s=Object.keys(e.namespaces).filter((e=>e.includes(t)));if(!s.length)return[];const r=[];return s.forEach((t=>{const s=e.namespaces[t].accounts;r.push(...s)})),r}(t,this.session),s=Ei(e),r=Si(this.namespaces,this.optionalNamespaces),i=fn(vn({},r[t]),{accounts:e,chains:s});switch(t){case"eip155":this.rpcProviders[t]=new Yi({namespace:i});break;case"algorand":this.rpcProviders[t]=new Xi({namespace:i});break;case"solana":this.rpcProviders[t]=new Zi({namespace:i});break;case"cosmos":this.rpcProviders[t]=new Ki({namespace:i});break;case"polkadot":this.rpcProviders[t]=new Ti({namespace:i});break;case"cip34":this.rpcProviders[t]=new tn({namespace:i});break;case"elrond":this.rpcProviders[t]=new en({namespace:i});break;case"multiversx":this.rpcProviders[t]=new sn({namespace:i});break;case"near":this.rpcProviders[t]=new rn({namespace:i});break;case"tezos":this.rpcProviders[t]=new nn({namespace:i});break;default:this.rpcProviders[v]?this.rpcProviders[v].updateNamespace(i):this.rpcProviders[v]=new an({namespace:i})}}))}registerEventListeners(){if(typeof this.client>"u")throw new Error("Sign Client is not initialized");this.client.on("session_ping",(t=>{this.events.emit("session_ping",t)})),this.client.on("session_event",(t=>{const{params:e}=t,{event:s}=e;if("accountsChanged"===s.name){const t=s.data;t&&(0,i.OP1)(t)&&this.events.emit("accountsChanged",t.map(Di))}else if("chainChanged"===s.name){const t=e.chainId,s=e.event.data,r=(0,i.kob)(t),n=Ri(t)!==Ri(s)?`${r}:${Ri(s)}`:t;this.onChainChanged(n)}else this.events.emit(s.name,s.data);this.events.emit("session_event",t)})),this.client.on("session_update",(({topic:t,params:e})=>{var s;const{namespaces:r}=e,i=null==(s=this.client)?void 0:s.session.get(t);this.session=fn(vn({},i),{namespaces:r}),this.onSessionUpdate(),this.events.emit("session_update",{topic:t,params:e})})),this.client.on("session_delete",(async t=>{await this.cleanup(),this.events.emit("session_delete",t),this.events.emit("disconnect",fn(vn({},(0,i.Hjj)("USER_DISCONNECTED")),{data:t.topic}))})),this.on(m,(t=>{this.onChainChanged(t,!0)}))}getProvider(t){return this.rpcProviders[t]||this.rpcProviders[v]}onSessionUpdate(){Object.keys(this.rpcProviders).forEach((t=>{var e;this.getProvider(t).updateNamespace(null==(e=this.session)?void 0:e.namespaces[t])}))}setNamespaces(t){const{namespaces:e,optionalNamespaces:s,sessionProperties:r}=t;e&&Object.keys(e).length&&(this.namespaces=e),s&&Object.keys(s).length&&(this.optionalNamespaces=s),this.sessionProperties=r,this.persist("namespaces",e),this.persist("optionalNamespaces",s)}validateChain(t){const[e,s]=t?.split(":")||["",""];if(!this.namespaces||!Object.keys(this.namespaces).length)return[e,s];if(e&&!Object.keys(this.namespaces||{}).map((t=>(0,i.kob)(t))).includes(e))throw new Error(`Namespace '${e}' is not configured. Please call connect() first with namespace config.`);if(e&&s)return[e,s];const r=(0,i.kob)(Object.keys(this.namespaces)[0]);return[r,this.rpcProviders[r].getDefaultChain()]}async requestAccounts(){const[t]=this.validateChain();return await this.getProvider(t).requestAccounts()}onChainChanged(t,e=!1){if(!this.namespaces)return;const[s,r]=this.validateChain(t);r&&(e||this.getProvider(s).setDefaultChain(r),this.namespaces[s]?this.namespaces[s].defaultChain=r:this.namespaces[`${s}:${r}`]?this.namespaces[`${s}:${r}`].defaultChain=r:this.namespaces[`${s}:${r}`]={defaultChain:r},this.persist("namespaces",this.namespaces),this.events.emit("chainChanged",r))}onConnect(){this.createProviders(),this.events.emit("connect",{session:this.session})}async cleanup(){this.session=void 0,this.namespaces=void 0,this.optionalNamespaces=void 0,this.sessionProperties=void 0,this.persist("namespaces",void 0),this.persist("optionalNamespaces",void 0),this.persist("sessionProperties",void 0),await this.cleanupPendingPairings({deletePairings:!0})}persist(t,e){this.client.core.storage.setItem(`${d}/${t}`,e)}async getFromStore(t){return await this.client.core.storage.getItem(`${d}/${t}`)}}}}]);