@dcl/auth-site 5.2.4-35645238913.commit-2a3f536 → 5.2.4

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.
Files changed (118) hide show
  1. package/assets/{ConstantsUtil-D7xdYTzX.js → ConstantsUtil-D_enledC.js} +1 -1
  2. package/assets/{ContentfulRichText-N_tI1YrF.js → ContentfulRichText-BXnB1WV1.js} +1 -1
  3. package/assets/{ExchangeController-R7XduMmW.js → ExchangeController-BJsWuKo_.js} +1 -1
  4. package/assets/{HelpersUtil-B5qkwRbQ.js → HelpersUtil-BsSg6bfU.js} +1 -1
  5. package/assets/LoginPage-kPG7oNcO.js +1 -0
  6. package/assets/{NetworkUtil-C1rybiNd.js → NetworkUtil-CiM7Scbw.js} +1 -1
  7. package/assets/{SwapController-8FmDcFRh.js → SwapController-BScC5qd4.js} +1 -1
  8. package/assets/{W3MFrameProviderSingleton-E5SkKECN.js → W3MFrameProviderSingleton-CSN4WYmh.js} +3 -3
  9. package/assets/{biconomy-DTefqawp.js → biconomy-DD7sQSaz.js} +1 -1
  10. package/assets/{browser-UvVty22h.js → browser-VEJcULwE.js} +1 -1
  11. package/assets/browser-ponyfill-CvvEnW1h.js +1 -0
  12. package/assets/{ccip-2xsClTDH.js → ccip-ChnHaTUO.js} +1 -1
  13. package/assets/{ccip-C35xgxGF.js → ccip-DrwSftXk.js} +1 -1
  14. package/assets/{chains-Jb2c--GZ.js → chains-CPIGtRno.js} +1 -1
  15. package/assets/{common-CyBw93hx.js → common-ByH20NJd.js} +1 -1
  16. package/assets/{controller-CJkfmKAp.js → controller-Bp73byMe.js} +2 -2
  17. package/assets/{data-capture-BYPIeiap.js → data-capture-BYysc2fz.js} +1 -1
  18. package/assets/{email--JxRIW6I.js → email-_gS30lxI.js} +1 -1
  19. package/assets/{embedded-wallet-CftJOrgl.js → embedded-wallet-CTRbsA33.js} +1 -1
  20. package/assets/{engine-CmlX8y2o.js → engine-Bcfvj1aj.js} +1 -1
  21. package/assets/{estimate-l1-fee-DGOtknnY.js → estimate-l1-fee-D3MWsNoD.js} +1 -1
  22. package/assets/{ethereum-AGK2C1RS.js → ethereum-8HMgNHU3.js} +1 -1
  23. package/assets/{extractIPFS-BdGeTzmP.js → extractIPFS-lFDmgORY.js} +1 -1
  24. package/assets/{features-DBeIXFoA.js → features-Cj_r41By.js} +1 -1
  25. package/assets/{fetchTokenMetadata-DS76kwol.js → fetchTokenMetadata-CTZiqyxr.js} +1 -1
  26. package/assets/{fortmatic-ClhV7rIw.js → fortmatic-Y4wiObUv.js} +1 -1
  27. package/assets/{get-ecosystem-wallet-info-DwP2v3Cu.js → get-ecosystem-wallet-info-Dc5Z_L5f.js} +1 -1
  28. package/assets/{getBalance-DUUszDk5.js → getBalance-oS7oD7kU.js} +1 -1
  29. package/assets/{getInstalledModules-Cvf5qGj4.js → getInstalledModules-Bdy2sE4C.js} +1 -1
  30. package/assets/{getNFT-DJtJxk1o.js → getNFT-BTxPXbfZ.js} +1 -1
  31. package/assets/{getNFT-DIbUYKA5.js → getNFT-DY_RXAaw.js} +2 -2
  32. package/assets/{if-defined-DgYdT9p1.js → if-defined-BmEfu7it.js} +1 -1
  33. package/assets/{in-app-BLyWvKUh.js → in-app-BDRqXNf4.js} +2 -2
  34. package/assets/{in-app-wallet-calls-DAlsysOc.js → in-app-wallet-calls-wleupQm2.js} +1 -1
  35. package/assets/{index-3pu2Fona.js → index-0Wy1jTru.js} +1 -1
  36. package/assets/{index-WaHU1l7x.js → index-3IJjv21_.js} +1 -1
  37. package/assets/{index-udx2Pfwz.js → index-B6w3cZ2_.js} +1 -1
  38. package/assets/{index-DhnOX83w.js → index-B6zHc0RV.js} +1 -1
  39. package/assets/{index-Doz8uLZj.js → index-B9pSvVDo.js} +1 -1
  40. package/assets/{index-C5yTlPzp.js → index-BGsdKBUY.js} +1 -1
  41. package/assets/{index-Bhc069C3.js → index-BLmcG3T6.js} +3 -3
  42. package/assets/{index-Djx_R6pq.js → index-BMHprEmP.js} +1 -1
  43. package/assets/{index-CRUV6j-X.js → index-BRZTUq3G.js} +1 -1
  44. package/assets/{index-DCEwjzZh.js → index-BTOcjE8I.js} +1 -1
  45. package/assets/{index-CVGqbHQW.js → index-BVOdDYFz.js} +1 -1
  46. package/assets/{index-DVQ0xmo9.js → index-Ba6beR5r.js} +1 -1
  47. package/assets/{index-Dz56_MBD.js → index-Bh0Uy4df.js} +1 -1
  48. package/assets/{index-90oLTOPt.js → index-BjFPNaXK.js} +1 -1
  49. package/assets/{index-BTBuff3_.js → index-BprPpDAF.js} +1 -1
  50. package/assets/{index-pkttUrUM.js → index-BtteQKjU.js} +1 -1
  51. package/assets/{index-9ltz1Dki.js → index-Bvesp-l9.js} +1 -1
  52. package/assets/{index-JVwf6Qfp.js → index-Bxs1rvuY.js} +1 -1
  53. package/assets/{index-GrnS-OV5.js → index-ByHLNXek.js} +1 -1
  54. package/assets/{index-BHzAh_03.js → index-C3fcqdqf.js} +1 -1
  55. package/assets/{index-BPu7-DUC.js → index-C67nnJf7.js} +1 -1
  56. package/assets/{index-DW1wWkyh.js → index-C6ZNtMYG.js} +1 -1
  57. package/assets/{index-eH-KBF3w.js → index-CAlJE1dj.js} +2 -2
  58. package/assets/{index-CRlpilrZ.js → index-CEPLe-GH.js} +1 -1
  59. package/assets/index-CFDU0CkD.css +1 -0
  60. package/assets/{index-DmOWX3bp.js → index-CRp8FXcP.js} +1 -1
  61. package/assets/{index-8rhqZtsb.js → index-CWVA-6zM.js} +1 -1
  62. package/assets/{index-Bm8GWzS1.js → index-CZUYadtr.js} +1 -1
  63. package/assets/{index-D0yg7C5q.js → index-Cc8ZrWmS.js} +3 -3
  64. package/assets/{index-Rj0p-Sn0.js → index-Cc__xqxY.js} +1 -1
  65. package/assets/{index-IaJn7kS8.js → index-CewAVMPB.js} +1 -1
  66. package/assets/{index-BuplIhvx.js → index-Ckxei1Mz.js} +1 -1
  67. package/assets/{index-BDPMGjeJ.js → index-CpbALHlw.js} +1 -1
  68. package/assets/{index-BKkJdu1O.js → index-CqiXzNt7.js} +1 -1
  69. package/assets/{index-Bh78uoUi.js → index-CuCUiVC-.js} +1 -1
  70. package/assets/{index-QRbWm9Wq.js → index-CzuR5hG_.js} +1 -1
  71. package/assets/{index-D9ITMMUp.js → index-D04ATMUc.js} +1 -1
  72. package/assets/{index-gllcimxK.js → index-D0N_JKAA.js} +1 -1
  73. package/assets/{index-TTIU5eca.js → index-D8FnAr7D.js} +1 -1
  74. package/assets/{index-BqHNs9qE.js → index-DNXa2sg0.js} +11 -11
  75. package/assets/{index-C32ig9vp.js → index-DPcFZqgi.js} +2 -2
  76. package/assets/{index-DjIHCuXa.js → index-DVj2BZRd.js} +1 -1
  77. package/assets/{index-Ce7N9G3e.js → index-FWalyQvc.js} +1 -1
  78. package/assets/{index-D3OVZnGW.js → index-Khos7cq5.js} +1 -1
  79. package/assets/{index-DeGx1I-e.js → index-Z96qEFLR.js} +1 -1
  80. package/assets/{index-BzSHANfq.js → index-aKCQIKBi.js} +1 -1
  81. package/assets/{index-B6fRhRwC.js → index-fFOJZ_09.js} +1 -1
  82. package/assets/{index-BwkHDX6G.js → index-oiDSpXvo.js} +1 -1
  83. package/assets/{index-CKywYW2-.js → index-zNKCPkIo.js} +3 -3
  84. package/assets/{index.es-C5gSxx0B.js → index.es-CNFHn-du.js} +1 -1
  85. package/assets/{index.es-D2xtIl02.js → index.es-sCbnotK4.js} +1 -1
  86. package/assets/{linkAccount-B5qtCVO2.js → linkAccount-B8uktXqT.js} +1 -1
  87. package/assets/{native-CaAmRbKE.js → native-BA2tCAg7.js} +1 -1
  88. package/assets/{networks-DOO6qDtl.js → networks-Bf4CrkJq.js} +3 -3
  89. package/assets/{onramp-BR2TZgb5.js → onramp-T_SH3pHw.js} +1 -1
  90. package/assets/{openzeppelin-Dfo-50-T.js → openzeppelin-C3UewUmp.js} +1 -1
  91. package/assets/{ownerOf-C85D5p3Y.js → ownerOf-C3L089de.js} +1 -1
  92. package/assets/{parseNft-BGw-J6fE.js → parseNft-Bm6e4djQ.js} +2 -2
  93. package/assets/{pay-with-exchange-B4z2HrWm.js → pay-with-exchange-BRWBppDL.js} +1 -1
  94. package/assets/{qr-overlay-BAhaKdAR.js → qr-overlay-CxgX_0NT.js} +3 -3
  95. package/assets/{receive-DkWRaw4a.js → receive-B-W2Jbej.js} +1 -1
  96. package/assets/{ref-CDy7rmAx.js → ref-Baiy8I6Z.js} +1 -1
  97. package/assets/{resolveImplementation-geBunBfL.js → resolveImplementation-CgW3h08A.js} +1 -1
  98. package/assets/{secp256k1-DiEbvKuL.js → secp256k1-BW7o3kSy.js} +1 -1
  99. package/assets/{send-Bbm4hDBE.js → send-BN9jzbVc.js} +1 -1
  100. package/assets/{send-eip712-transaction-CLbB15Vc.js → send-eip712-transaction-CCCpoMyz.js} +1 -1
  101. package/assets/{send-gasless-transaction-5r2N4e3N.js → send-gasless-transaction-BoGI-8Fx.js} +2 -2
  102. package/assets/{session-proposal-B732ctWY.js → session-proposal-tXoBJjrl.js} +1 -1
  103. package/assets/{session-request-BWIxUHKB.js → session-request-ChbL5OgY.js} +2 -2
  104. package/assets/{socials-DlUEgZW6.js → socials-CrLQu5sF.js} +1 -1
  105. package/assets/{swaps-DoKGZX9t.js → swaps-bVhoZi4N.js} +1 -1
  106. package/assets/{thirdweb-DaGoGHaJ.js → thirdweb-DCTNjMNu.js} +5 -5
  107. package/assets/{totalSupply-Bg0OMT_d.js → totalSupply-0xe8Ex-_.js} +1 -1
  108. package/assets/{transactions-BVfs8y_y.js → transactions-DxlJ5s5s.js} +1 -1
  109. package/assets/{ui-BjvItYqm.js → ui-D3rNG5Q7.js} +5 -5
  110. package/assets/{vendor-CwdbX2q9.js → vendor-BwjdGo6X.js} +1 -1
  111. package/assets/{w3m-modal-B5WX8XEk.js → w3m-modal-Deqbdj72.js} +1 -1
  112. package/assets/{wallets-DEM4N7hD.js → wallets-BhWOoOxj.js} +4 -4
  113. package/assets/{web-connector-BW74xrQd.js → web-connector-Bm612qdn.js} +3 -3
  114. package/index.html +5 -5
  115. package/package.json +3 -3
  116. package/assets/LoginPage-DFw3BgI9.js +0 -1
  117. package/assets/browser-ponyfill-CqE0UlVr.js +0 -1
  118. package/assets/index-BklUL2ST.css +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-eH-KBF3w.js","assets/thirdweb-DaGoGHaJ.js","assets/index-BqHNs9qE.js","assets/ui-BjvItYqm.js","assets/vendor-CwdbX2q9.js","assets/index-BklUL2ST.css","assets/W3MFrameProviderSingleton-E5SkKECN.js","assets/index-BwkHDX6G.js","assets/browser-ponyfill-CqE0UlVr.js","assets/NetworkUtil-C1rybiNd.js","assets/store-CraP4F4Y.js"])))=>i.map(i=>d[i]);
2
- import{e as _e,C as P,i as ct,a9 as $e,aa as Y,u as x,A as D,I as at,k as B,O as F,a5 as ut,p as dt,s as lt,a as re,a1 as ht,a6 as Z,ab as O,D as ft,U as ee,ac as te,G as Re,a2 as gt}from"./W3MFrameProviderSingleton-E5SkKECN.js";import{C as S,N as be}from"./NetworkUtil-C1rybiNd.js";import{bb as mt,j as K,bc as Fe,bd as pt,be as wt,bf as Ct,bg as bt,bh as yt,bi as It,bj as Be,bk as vt,bl as He,bm as At,bn as Et,bo as Nt,bp as St,bq as Pt,br as Tt,c as _t,bs as $t,bt as Rt,S as ke,n as Oe,U,bu as kt,bv as he,b5 as Ot}from"./index-BqHNs9qE.js";import"./ui-BjvItYqm.js";import"./index-BwkHDX6G.js";import"./browser-ponyfill-CqE0UlVr.js";import{aF as Ut,_ as Ve}from"./thirdweb-DaGoGHaJ.js";import{c as jt}from"./store-CraP4F4Y.js";function Mt(n,{errorInstance:e=new Error("timed out"),timeout:t,signal:i}){return new Promise((s,r)=>{(async()=>{let u;try{const o=new AbortController;t>0&&(u=setTimeout(()=>{i?o.abort():r(e)},t)),s(await n({signal:(o==null?void 0:o.signal)||null}))}catch(o){(o==null?void 0:o.name)==="AbortError"&&r(e),r(o)}finally{clearTimeout(u)}})()})}function T(n,e,t){const i=n[e.name];if(typeof i=="function")return i;const s=n[t];return typeof s=="function"?s:r=>e(n,r)}const oe="2.22.1",xt=()=>`@wagmi/core@${oe}`;var Ge=function(n,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?n!==e||!i:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(n):i?i.value:e.get(n)},ae,Ke;let L=class ye extends Error{get docsBaseUrl(){return"https://wagmi.sh/core"}get version(){return xt()}constructor(e,t={}){var r;super(),ae.add(this),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"WagmiCoreError"});const i=t.cause instanceof ye?t.cause.details:(r=t.cause)!=null&&r.message?t.cause.message:t.details,s=t.cause instanceof ye&&t.cause.docsPath||t.docsPath;this.message=[e||"An error occurred.","",...t.metaMessages?[...t.metaMessages,""]:[],...s?[`Docs: ${this.docsBaseUrl}${s}.html${t.docsSlug?`#${t.docsSlug}`:""}`]:[],...i?[`Details: ${i}`]:[],`Version: ${this.version}`].join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CAlJE1dj.js","assets/thirdweb-DCTNjMNu.js","assets/index-DNXa2sg0.js","assets/ui-D3rNG5Q7.js","assets/vendor-BwjdGo6X.js","assets/index-CFDU0CkD.css","assets/W3MFrameProviderSingleton-CSN4WYmh.js","assets/index-oiDSpXvo.js","assets/browser-ponyfill-CvvEnW1h.js","assets/NetworkUtil-CiM7Scbw.js","assets/store-CraP4F4Y.js"])))=>i.map(i=>d[i]);
2
+ import{e as _e,C as P,i as ct,a9 as $e,aa as Y,u as x,A as D,I as at,k as B,O as F,a5 as ut,p as dt,s as lt,a as re,a1 as ht,a6 as Z,ab as O,D as ft,U as ee,ac as te,G as Re,a2 as gt}from"./W3MFrameProviderSingleton-CSN4WYmh.js";import{C as S,N as be}from"./NetworkUtil-CiM7Scbw.js";import{bb as mt,j as K,bc as Fe,bd as pt,be as wt,bf as Ct,bg as bt,bh as yt,bi as It,bj as Be,bk as vt,bl as He,bm as At,bn as Et,bo as Nt,bp as St,bq as Pt,br as Tt,c as _t,bs as $t,bt as Rt,S as ke,n as Oe,U,bu as kt,bv as he,b5 as Ot}from"./index-DNXa2sg0.js";import"./ui-D3rNG5Q7.js";import"./index-oiDSpXvo.js";import"./browser-ponyfill-CvvEnW1h.js";import{aF as Ut,_ as Ve}from"./thirdweb-DCTNjMNu.js";import{c as jt}from"./store-CraP4F4Y.js";function Mt(n,{errorInstance:e=new Error("timed out"),timeout:t,signal:i}){return new Promise((s,r)=>{(async()=>{let u;try{const o=new AbortController;t>0&&(u=setTimeout(()=>{i?o.abort():r(e)},t)),s(await n({signal:(o==null?void 0:o.signal)||null}))}catch(o){(o==null?void 0:o.name)==="AbortError"&&r(e),r(o)}finally{clearTimeout(u)}})()})}function T(n,e,t){const i=n[e.name];if(typeof i=="function")return i;const s=n[t];return typeof s=="function"?s:r=>e(n,r)}const oe="2.22.1",xt=()=>`@wagmi/core@${oe}`;var Ge=function(n,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?n!==e||!i:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(n):i?i.value:e.get(n)},ae,Ke;let L=class ye extends Error{get docsBaseUrl(){return"https://wagmi.sh/core"}get version(){return xt()}constructor(e,t={}){var r;super(),ae.add(this),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"WagmiCoreError"});const i=t.cause instanceof ye?t.cause.details:(r=t.cause)!=null&&r.message?t.cause.message:t.details,s=t.cause instanceof ye&&t.cause.docsPath||t.docsPath;this.message=[e||"An error occurred.","",...t.metaMessages?[...t.metaMessages,""]:[],...s?[`Docs: ${this.docsBaseUrl}${s}.html${t.docsSlug?`#${t.docsSlug}`:""}`]:[],...i?[`Details: ${i}`]:[],`Version: ${this.version}`].join(`
3
3
  `),t.cause&&(this.cause=t.cause),this.details=i,this.docsPath=s,this.metaMessages=t.metaMessages,this.shortMessage=e}walk(e){return Ge(this,ae,"m",Ke).call(this,this,e)}};ae=new WeakSet,Ke=function n(e,t){return t!=null&&t(e)?e:e.cause?Ge(this,ae,"m",n).call(this,e.cause,t):e};class X extends L{constructor(){super("Chain not configured."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ChainNotConfiguredError"})}}class Wt extends L{constructor(){super("Connector already connected."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ConnectorAlreadyConnectedError"})}}class qt extends L{constructor(){super("Connector not connected."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ConnectorNotConnectedError"})}}class Lt extends L{constructor({address:e,connector:t}){super(`Account "${e}" not found for connector "${t.name}".`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ConnectorAccountNotFoundError"})}}class zt extends L{constructor({connectionChainId:e,connectorChainId:t}){super(`The current chain of the connector (id: ${t}) does not match the connection's chain (id: ${e}).`,{metaMessages:[`Current Chain ID: ${t}`,`Expected Chain ID: ${e}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ConnectorChainMismatchError"})}}class Dt extends L{constructor({connector:e}){super(`Connector "${e.name}" unavailable while reconnecting.`,{details:["During the reconnection step, the only connector methods guaranteed to be available are: `id`, `name`, `type`, `uid`.","All other methods are not guaranteed to be available until reconnection completes and connectors are fully restored.","This error commonly occurs for connectors that asynchronously inject after reconnection has already started."].join(" ")}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ConnectorUnavailableReconnectingError"})}}async function fe(n,e){var i;let t;if(typeof e.connector=="function"?t=n._internal.connectors.setup(e.connector):t=e.connector,t.uid===n.state.current)throw new Wt;try{n.setState(o=>({...o,status:"connecting"})),t.emitter.emit("message",{type:"connecting"});const{connector:s,...r}=e,u=await t.connect(r);return t.emitter.off("connect",n._internal.events.connect),t.emitter.on("change",n._internal.events.change),t.emitter.on("disconnect",n._internal.events.disconnect),await((i=n.storage)==null?void 0:i.setItem("recentConnectorId",t.id)),n.setState(o=>({...o,connections:new Map(o.connections).set(t.uid,{accounts:r.withCapabilities?u.accounts.map(a=>typeof a=="object"?a.address:a):u.accounts,chainId:u.chainId,connector:t}),current:t.uid,status:"connected"})),{accounts:r.withCapabilities?u.accounts.map(o=>typeof o=="object"?o:{address:o,capabilities:{}}):u.accounts,chainId:u.chainId}}catch(s){throw n.setState(r=>({...r,status:r.current?"connected":"disconnected"})),s}}async function ue(n,e={}){const{assertChainId:t=!0}=e;let i;if(e.connector){const{connector:c}=e;if(n.state.status==="reconnecting"&&!c.getAccounts&&!c.getChainId)throw new Dt({connector:c});const[l,h]=await Promise.all([c.getAccounts().catch(f=>{if(e.account===null)return[];throw f}),c.getChainId()]);i={accounts:l,chainId:h,connector:c}}else i=n.state.connections.get(n.state.current);if(!i)throw new qt;const s=e.chainId??i.chainId,r=await i.connector.getChainId();if(t&&r!==s)throw new zt({connectionChainId:s,connectorChainId:r});const u=i.connector;if(u.getClient)return u.getClient({chainId:s});const o=mt(e.account??i.accounts[0]);if(o&&(o.address=K(o.address)),e.account&&!i.accounts.some(c=>c.toLowerCase()===o.address.toLowerCase()))throw new Lt({address:o.address,connector:u});const a=n.chains.find(c=>c.id===s),d=await i.connector.getProvider({chainId:s});return Fe({account:o,chain:a,name:"Connector Client",transport:c=>pt(d)({...c,retryCount:0})})}async function Ue(n,e={}){var s,r;let t;if(e.connector)t=e.connector;else{const{connections:u,current:o}=n.state,a=u.get(o);t=a==null?void 0:a.connector}const i=n.state.connections;t&&(await t.disconnect(),t.emitter.off("change",n._internal.events.change),t.emitter.off("disconnect",n._internal.events.disconnect),t.emitter.on("connect",n._internal.events.connect),i.delete(t.uid)),n.setState(u=>{if(i.size===0)return{...u,connections:new Map,current:null,status:"disconnected"};const o=i.values().next().value;return{...u,connections:new Map(i),current:o.connector.uid}});{const u=n.state.current;if(!u)return;const o=(s=n.state.connections.get(u))==null?void 0:s.connector;if(!o)return;await((r=n.storage)==null?void 0:r.setItem("recentConnectorId",o.id))}}function Je(n){return typeof n=="number"?n:n==="wei"?0:Math.abs(wt[n])}async function Ft(n,e){const{chainId:t,connector:i,...s}=e;let r;e.account?r=e.account:r=(await ue(n,{account:e.account,assertChainId:!1,chainId:t,connector:i})).account;const u=n.getClient({chainId:t});return T(u,Ct,"estimateGas")({...s,account:r})}function J(n){const e=n.state.current,t=n.state.connections.get(e),i=t==null?void 0:t.accounts,s=i==null?void 0:i[0],r=n.chains.find(o=>o.id===(t==null?void 0:t.chainId)),u=n.state.status;switch(u){case"connected":return{address:s,addresses:i,chain:r,chainId:t==null?void 0:t.chainId,connector:t==null?void 0:t.connector,isConnected:!0,isConnecting:!1,isDisconnected:!1,isReconnecting:!1,status:u};case"reconnecting":return{address:s,addresses:i,chain:r,chainId:t==null?void 0:t.chainId,connector:t==null?void 0:t.connector,isConnected:!!s,isConnecting:!1,isDisconnected:!1,isReconnecting:!0,status:u};case"connecting":return{address:s,addresses:i,chain:r,chainId:t==null?void 0:t.chainId,connector:t==null?void 0:t.connector,isConnected:!1,isConnecting:!0,isDisconnected:!1,isReconnecting:!1,status:u};case"disconnected":return{address:void 0,addresses:void 0,chain:void 0,chainId:void 0,connector:void 0,isConnected:!1,isConnecting:!1,isDisconnected:!0,isReconnecting:!1,status:u}}}async function Bt(n,e){const{allowFailure:t=!0,chainId:i,contracts:s,...r}=e,u=n.getClient({chainId:i});return T(u,bt,"multicall")({allowFailure:t,contracts:s,...r})}function Ht(n,e){const{chainId:t,...i}=e,s=n.getClient({chainId:t});return T(s,yt,"readContract")(i)}async function Vt(n,e){var o;const{allowFailure:t=!0,blockNumber:i,blockTag:s,...r}=e,u=e.contracts;try{const a={};for(const[h,f]of u.entries()){const p=f.chainId??n.state.chainId;a[p]||(a[p]=[]),(o=a[p])==null||o.push({contract:f,index:h})}const d=()=>Object.entries(a).map(([h,f])=>Bt(n,{...r,allowFailure:t,blockNumber:i,blockTag:s,chainId:Number.parseInt(h,10),contracts:f.map(({contract:p})=>p)})),c=(await Promise.all(d())).flat(),l=Object.values(a).flatMap(h=>h.map(({index:f})=>f));return c.reduce((h,f,p)=>(h&&(h[l[p]]=f),h),[])}catch(a){if(a instanceof It)throw a;const d=()=>u.map(c=>Ht(n,{...c,blockNumber:i,blockTag:s}));return t?(await Promise.allSettled(d())).map(c=>c.status==="fulfilled"?{result:c.value,status:"success"}:{error:c.reason,result:void 0,status:"failure"}):await Promise.all(d())}}async function Gt(n,e){const{address:t,blockNumber:i,blockTag:s,chainId:r,token:u,unit:o="ether"}=e;if(u)try{return await je(n,{balanceAddress:t,chainId:r,symbolType:"string",tokenAddress:u})}catch(h){if(h.name==="ContractFunctionExecutionError"){const f=await je(n,{balanceAddress:t,chainId:r,symbolType:"bytes32",tokenAddress:u}),p=Be(vt(f.symbol,{dir:"right"}));return{...f,symbol:p}}throw h}const a=n.getClient({chainId:r}),c=await T(a,At,"getBalance")(i?{address:t,blockNumber:i}:{address:t,blockTag:s}),l=n.chains.find(h=>h.id===r)??a.chain;return{decimals:l.nativeCurrency.decimals,formatted:He(c,Je(o)),symbol:l.nativeCurrency.symbol,value:c}}async function je(n,e){const{balanceAddress:t,chainId:i,symbolType:s,tokenAddress:r,unit:u}=e,o={abi:[{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{type:"address"}],outputs:[{type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{type:"uint8"}]},{type:"function",name:"symbol",stateMutability:"view",inputs:[],outputs:[{type:s}]}],address:r},[a,d,c]=await Vt(n,{allowFailure:!1,contracts:[{...o,functionName:"balanceOf",args:[t],chainId:i},{...o,functionName:"decimals",chainId:i},{...o,functionName:"symbol",chainId:i}]}),l=He(a??"0",Je(u??d));return{decimals:d,formatted:l,symbol:c,value:a}}function Q(n,e){if(n===e)return!0;if(n&&e&&typeof n=="object"&&typeof e=="object"){if(n.constructor!==e.constructor)return!1;let t,i;if(Array.isArray(n)&&Array.isArray(e)){if(t=n.length,t!==e.length)return!1;for(i=t;i--!==0;)if(!Q(n[i],e[i]))return!1;return!0}if(typeof n.valueOf=="function"&&n.valueOf!==Object.prototype.valueOf)return n.valueOf()===e.valueOf();if(typeof n.toString=="function"&&n.toString!==Object.prototype.toString)return n.toString()===e.toString();const s=Object.keys(n);if(t=s.length,t!==Object.keys(e).length)return!1;for(i=t;i--!==0;)if(!Object.hasOwn(e,s[i]))return!1;for(i=t;i--!==0;){const r=s[i];if(r&&!Q(n[r],e[r]))return!1}return!0}return n!==n&&e!==e}let ne=[];function M(n){const e=[...n.state.connections.values()];return n.state.status==="reconnecting"||Q(ne,e)?ne:(ne=e,e)}async function Kt(n,e){const{account:t,chainId:i,...s}=e,r=t??J(n).address,u=n.getClient({chainId:i});return T(u,Et,"prepareTransactionRequest")({...s,...r?{account:r}:{}})}let ge=!1;async function me(n,e={}){var d,c;if(ge)return[];ge=!0,n.setState(l=>({...l,status:l.current?"reconnecting":"connecting"}));const t=[];if((d=e.connectors)!=null&&d.length)for(const l of e.connectors){let h;typeof l=="function"?h=n._internal.connectors.setup(l):h=l,t.push(h)}else t.push(...n.connectors);let i;try{i=await((c=n.storage)==null?void 0:c.getItem("recentConnectorId"))}catch{}const s={};for(const[,l]of n.state.connections)s[l.connector.id]=1;i&&(s[i]=0);const r=Object.keys(s).length>0?[...t].sort((l,h)=>(s[l.id]??10)-(s[h.id]??10)):t;let u=!1;const o=[],a=[];for(const l of r){const h=await l.getProvider().catch(()=>{});if(!h||a.some(m=>m===h)||!await l.isAuthorized())continue;const p=await l.connect({isReconnecting:!0}).catch(()=>null);p&&(l.emitter.off("connect",n._internal.events.connect),l.emitter.on("change",n._internal.events.change),l.emitter.on("disconnect",n._internal.events.disconnect),n.setState(m=>{const b=new Map(u?m.connections:new Map).set(l.uid,{accounts:p.accounts,chainId:p.chainId,connector:l});return{...m,current:u?m.current:l.uid,connections:b}}),o.push({accounts:p.accounts,chainId:p.chainId,connector:l}),a.push(h),u=!0)}return(n.state.status==="reconnecting"||n.state.status==="connecting")&&(u?n.setState(l=>({...l,status:"connected"})):n.setState(l=>({...l,connections:new Map,current:null,status:"disconnected"}))),ge=!1,o}async function Jt(n,e){const{account:t,chainId:i,connector:s,...r}=e;let u;return typeof t=="object"&&(t==null?void 0:t.type)==="local"?u=n.getClient({chainId:i}):u=await ue(n,{account:t??void 0,assertChainId:!1,chainId:i,connector:s}),await T(u,Nt,"sendTransaction")({...r,...t?{account:t}:{},chain:i?{id:i}:null,gas:r.gas??void 0})}async function Xt(n,e){const{account:t,connector:i,...s}=e;let r;return typeof t=="object"&&t.type==="local"?r=n.getClient():r=await ue(n,{account:t,connector:i}),T(r,St,"signMessage")({...s,...t?{account:t}:{}})}class W extends L{constructor(){super("Provider not found."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ProviderNotFoundError"})}}class Qt extends L{constructor({connector:e}){super(`"${e.name}" does not support programmatic chain switching.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SwitchChainNotSupportedError"})}}async function Me(n,e){var u;const{addEthereumChainParameter:t,chainId:i}=e,s=n.state.connections.get(((u=e.connector)==null?void 0:u.uid)??n.state.current);if(s){const o=s.connector;if(!o.switchChain)throw new Qt({connector:o});return await o.switchChain({addEthereumChainParameter:t,chainId:i})}const r=n.chains.find(o=>o.id===i);if(!r)throw new X;return n.setState(o=>({...o,chainId:i})),r}async function Yt(n,e){const{chainId:t,timeout:i=0,...s}=e,r=n.getClient({chainId:t}),o=await T(r,Pt,"waitForTransactionReceipt")({...s,timeout:i});if(o.status==="reverted"){const a=T(r,Tt,"getTransaction"),{from:d,...c}=await a({hash:o.transactionHash}),h=await T(r,_t,"call")({...c,account:d,data:c.input,gasPrice:c.type!=="eip1559"?c.gasPrice:void 0,maxFeePerGas:c.type==="eip1559"?c.maxFeePerGas:void 0,maxPriorityFeePerGas:c.type==="eip1559"?c.maxPriorityFeePerGas:void 0}),f=h!=null&&h.data?Be(`0x${h.data.substring(138)}`):"unknown reason";throw new Error(f)}return{...o,chainId:r.chain.id}}function Zt(n,e){const{onChange:t}=e;return n.subscribe(()=>J(n),t,{equalityFn(i,s){const{connector:r,...u}=i,{connector:o,...a}=s;return Q(u,a)&&(r==null?void 0:r.id)===(o==null?void 0:o.id)&&(r==null?void 0:r.uid)===(o==null?void 0:o.uid)}})}function en(n,e){const{onChange:t}=e;return n.subscribe(()=>M(n),t,{equalityFn:Q})}function tn(n,e){const{onChange:t}=e;return n._internal.connectors.subscribe((i,s)=>{t(Object.values(i),s)})}function nn(n,e){const{syncConnectedChain:t=n._internal.syncConnectedChain,...i}=e;let s;const r=a=>{s&&s();const d=n.getClient({chainId:a});return s=T(d,$t,"watchPendingTransactions")(i),s},u=r(e.chainId);let o;return t&&!e.chainId&&(o=n.subscribe(({chainId:a})=>a,async a=>r(a))),()=>{u==null||u(),o==null||o()}}async function sn(n,e){const{account:t,chainId:i,connector:s,...r}=e;let u;return typeof t=="object"&&(t==null?void 0:t.type)==="local"?u=n.getClient({chainId:i}):u=await ue(n,{account:t??void 0,assertChainId:!1,chainId:i,connector:s}),await T(u,Rt,"writeContract")({...r,...t?{account:t}:{},chain:i?{id:i}:null})}function Zn(n){return n}de.type="injected";function de(n={}){const{shimDisconnect:e=!0,unstable_shimAsyncInject:t}=n;function i(){const a=n.target;if(typeof a=="function"){const d=a();if(d)return d}return typeof a=="object"?a:typeof a=="string"?{...rn[a]??{id:a,name:`${a[0].toUpperCase()}${a.slice(1)}`,provider:`is${a[0].toUpperCase()}${a.slice(1)}`}}:{id:"injected",name:"Injected",provider(d){return d==null?void 0:d.ethereum}}}let s,r,u,o;return a=>({get icon(){return i().icon},get id(){return i().id},get name(){return i().name},get supportsSimulation(){return!0},type:de.type,async setup(){const d=await this.getProvider();d!=null&&d.on&&n.target&&(u||(u=this.onConnect.bind(this),d.on("connect",u)),s||(s=this.onAccountsChanged.bind(this),d.on("accountsChanged",s)))},async connect({chainId:d,isReconnecting:c,withCapabilities:l}={}){var p,m,b,I,y,N;const h=await this.getProvider();if(!h)throw new W;let f=[];if(c)f=await this.getAccounts().catch(()=>[]);else if(e)try{f=(I=(b=(m=(p=(await h.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}))[0])==null?void 0:p.caveats)==null?void 0:m[0])==null?void 0:b.value)==null?void 0:I.map(g=>K(g)),f.length>0&&(f=await this.getAccounts())}catch(A){const g=A;if(g.code===U.code)throw new U(g);if(g.code===he.code)throw g}try{!(f!=null&&f.length)&&!c&&(f=(await h.request({method:"eth_requestAccounts"})).map(w=>K(w))),u&&(h.removeListener("connect",u),u=void 0),s||(s=this.onAccountsChanged.bind(this),h.on("accountsChanged",s)),r||(r=this.onChainChanged.bind(this),h.on("chainChanged",r)),o||(o=this.onDisconnect.bind(this),h.on("disconnect",o));let A=await this.getChainId();if(d&&A!==d){const g=await this.switchChain({chainId:d}).catch(w=>{if(w.code===U.code)throw w;return{id:A}});A=(g==null?void 0:g.id)??A}return e&&await((y=a.storage)==null?void 0:y.removeItem(`${this.id}.disconnected`)),n.target||await((N=a.storage)==null?void 0:N.setItem("injected.connected",!0)),{accounts:l?f.map(g=>({address:g,capabilities:{}})):f,chainId:A}}catch(A){const g=A;throw g.code===U.code?new U(g):g.code===he.code?new he(g):g}},async disconnect(){var c,l;const d=await this.getProvider();if(!d)throw new W;r&&(d.removeListener("chainChanged",r),r=void 0),o&&(d.removeListener("disconnect",o),o=void 0),u||(u=this.onConnect.bind(this),d.on("connect",u));try{await Mt(()=>d.request({method:"wallet_revokePermissions",params:[{eth_accounts:{}}]}),{timeout:100})}catch{}e&&await((c=a.storage)==null?void 0:c.setItem(`${this.id}.disconnected`,!0)),n.target||await((l=a.storage)==null?void 0:l.removeItem("injected.connected"))},async getAccounts(){const d=await this.getProvider();if(!d)throw new W;return(await d.request({method:"eth_accounts"})).map(l=>K(l))},async getChainId(){const d=await this.getProvider();if(!d)throw new W;const c=await d.request({method:"eth_chainId"});return Number(c)},async getProvider(){if(typeof window>"u")return;let d;const c=i();return typeof c.provider=="function"?d=c.provider(window):typeof c.provider=="string"?d=ce(window,c.provider):d=c.provider,d&&!d.removeListener&&("off"in d&&typeof d.off=="function"?d.removeListener=d.off:d.removeListener=()=>{}),d},async isAuthorized(){var d,c;try{if(e&&await((d=a.storage)==null?void 0:d.getItem(`${this.id}.disconnected`))||!n.target&&!await((c=a.storage)==null?void 0:c.getItem("injected.connected")))return!1;if(!await this.getProvider()){if(t!==void 0&&t!==!1){const p=async()=>(typeof window<"u"&&window.removeEventListener("ethereum#initialized",p),!!await this.getProvider()),m=typeof t=="number"?t:1e3;if(await Promise.race([...typeof window<"u"?[new Promise(I=>window.addEventListener("ethereum#initialized",()=>I(p()),{once:!0}))]:[],new Promise(I=>setTimeout(()=>I(p()),m))]))return!0}throw new W}return!!(await kt(()=>this.getAccounts())).length}catch{return!1}},async switchChain({addEthereumChainParameter:d,chainId:c}){var p,m,b,I;const l=await this.getProvider();if(!l)throw new W;const h=a.chains.find(y=>y.id===c);if(!h)throw new ke(new X);const f=new Promise(y=>{const N=A=>{"chainId"in A&&A.chainId===c&&(a.emitter.off("change",N),y())};a.emitter.on("change",N)});try{return await Promise.all([l.request({method:"wallet_switchEthereumChain",params:[{chainId:Oe(c)}]}).then(async()=>{await this.getChainId()===c&&a.emitter.emit("change",{chainId:c})}),f]),h}catch(y){const N=y;if(N.code===4902||((m=(p=N==null?void 0:N.data)==null?void 0:p.originalError)==null?void 0:m.code)===4902)try{const{default:A,...g}=h.blockExplorers??{};let w;d!=null&&d.blockExplorerUrls?w=d.blockExplorerUrls:A&&(w=[A.url,...Object.values(g).map(v=>v.url)]);let C;(b=d==null?void 0:d.rpcUrls)!=null&&b.length?C=d.rpcUrls:C=[((I=h.rpcUrls.default)==null?void 0:I.http[0])??""];const E={blockExplorerUrls:w,chainId:Oe(c),chainName:(d==null?void 0:d.chainName)??h.name,iconUrls:d==null?void 0:d.iconUrls,nativeCurrency:(d==null?void 0:d.nativeCurrency)??h.nativeCurrency,rpcUrls:C};return await Promise.all([l.request({method:"wallet_addEthereumChain",params:[E]}).then(async()=>{if(await this.getChainId()===c)a.emitter.emit("change",{chainId:c});else throw new U(new Error("User rejected switch after adding network."))}),f]),h}catch(A){throw new U(A)}throw N.code===U.code?new U(N):new ke(N)}},async onAccountsChanged(d){var c;if(d.length===0)this.onDisconnect();else if(a.emitter.listenerCount("connect")){const l=(await this.getChainId()).toString();this.onConnect({chainId:l}),e&&await((c=a.storage)==null?void 0:c.removeItem(`${this.id}.disconnected`))}else a.emitter.emit("change",{accounts:d.map(l=>K(l))})},onChainChanged(d){const c=Number(d);a.emitter.emit("change",{chainId:c})},async onConnect(d){const c=await this.getAccounts();if(c.length===0)return;const l=Number(d.chainId);a.emitter.emit("connect",{accounts:c,chainId:l});const h=await this.getProvider();h&&(u&&(h.removeListener("connect",u),u=void 0),s||(s=this.onAccountsChanged.bind(this),h.on("accountsChanged",s)),r||(r=this.onChainChanged.bind(this),h.on("chainChanged",r)),o||(o=this.onDisconnect.bind(this),h.on("disconnect",o)))},async onDisconnect(d){const c=await this.getProvider();d&&d.code===1013&&c&&(await this.getAccounts()).length||(a.emitter.emit("disconnect"),c&&(r&&(c.removeListener("chainChanged",r),r=void 0),o&&(c.removeListener("disconnect",o),o=void 0),u||(u=this.onConnect.bind(this),c.on("connect",u))))}})}const rn={coinbaseWallet:{id:"coinbaseWallet",name:"Coinbase Wallet",provider(n){return n!=null&&n.coinbaseWalletExtension?n.coinbaseWalletExtension:ce(n,"isCoinbaseWallet")}},metaMask:{id:"metaMask",name:"MetaMask",provider(n){return ce(n,e=>{if(!e.isMetaMask||e.isBraveWallet&&!e._events&&!e._state)return!1;const t=["isApexWallet","isAvalanche","isBitKeep","isBlockWallet","isKuCoinWallet","isMathWallet","isOkxWallet","isOKExWallet","isOneInchIOSWallet","isOneInchAndroidWallet","isOpera","isPhantom","isPortal","isRabby","isTokenPocket","isTokenary","isUniswapWallet","isZerion"];for(const i of t)if(e[i])return!1;return!0})}},phantom:{id:"phantom",name:"Phantom",provider(n){var e,t;return(e=n==null?void 0:n.phantom)!=null&&e.ethereum?(t=n.phantom)==null?void 0:t.ethereum:ce(n,"isPhantom")}}};function ce(n,e){function t(s){return typeof e=="function"?e(s):typeof e=="string"?s[e]:!0}const i=n.ethereum;if(i!=null&&i.providers)return i.providers.find(s=>t(s));if(i&&t(i))return i}const on=n=>(e,t,i)=>{const s=i.subscribe;return i.subscribe=(u,o,a)=>{let d=u;if(o){const c=(a==null?void 0:a.equalityFn)||Object.is;let l=u(i.getState());d=h=>{const f=u(h);if(!c(l,f)){const p=l;o(l=f,p)}},a!=null&&a.fireImmediately&&o(l,l)}return s(d)},n(e,t,i)},cn=on;function an(n,e){let t;try{t=n()}catch{return}return{getItem:s=>{var r;const u=a=>a===null?null:JSON.parse(a,void 0),o=(r=t.getItem(s))!=null?r:null;return o instanceof Promise?o.then(u):u(o)},setItem:(s,r)=>t.setItem(s,JSON.stringify(r,void 0)),removeItem:s=>t.removeItem(s)}}const Ie=n=>e=>{try{const t=n(e);return t instanceof Promise?t:{then(i){return Ie(i)(t)},catch(i){return this}}}catch(t){return{then(i){return this},catch(i){return Ie(i)(t)}}}},un=(n,e)=>(t,i,s)=>{let r={storage:an(()=>localStorage),partialize:m=>m,version:0,merge:(m,b)=>({...b,...m}),...e},u=!1;const o=new Set,a=new Set;let d=r.storage;if(!d)return n((...m)=>{console.warn(`[zustand persist middleware] Unable to update item '${r.name}', the given storage is currently unavailable.`),t(...m)},i,s);const c=()=>{const m=r.partialize({...i()});return d.setItem(r.name,{state:m,version:r.version})},l=s.setState;s.setState=(m,b)=>{l(m,b),c()};const h=n((...m)=>{t(...m),c()},i,s);s.getInitialState=()=>h;let f;const p=()=>{var m,b;if(!d)return;u=!1,o.forEach(y=>{var N;return y((N=i())!=null?N:h)});const I=((b=r.onRehydrateStorage)==null?void 0:b.call(r,(m=i())!=null?m:h))||void 0;return Ie(d.getItem.bind(d))(r.name).then(y=>{if(y)if(typeof y.version=="number"&&y.version!==r.version){if(r.migrate)return[!0,r.migrate(y.state,y.version)];console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,y.state];return[!1,void 0]}).then(y=>{var N;const[A,g]=y;if(f=r.merge(g,(N=i())!=null?N:h),t(f,!0),A)return c()}).then(()=>{I==null||I(f,void 0),f=i(),u=!0,a.forEach(y=>y(f))}).catch(y=>{I==null||I(void 0,y)})};return s.persist={setOptions:m=>{r={...r,...m},m.storage&&(d=m.storage)},clearStorage:()=>{d==null||d.removeItem(r.name)},getOptions:()=>r,rehydrate:()=>p(),hasHydrated:()=>u,onHydrate:m=>(o.add(m),()=>{o.delete(m)}),onFinishHydration:m=>(a.add(m),()=>{a.delete(m)})},r.skipHydration||p(),f||h},dn=un,xe=n=>{let e;const t=new Set,i=(d,c)=>{const l=typeof d=="function"?d(e):d;if(!Object.is(l,e)){const h=e;e=c??(typeof l!="object"||l===null)?l:Object.assign({},e,l),t.forEach(f=>f(e,h))}},s=()=>e,o={setState:i,getState:s,getInitialState:()=>a,subscribe:d=>(t.add(d),()=>t.delete(d))},a=e=n(i,s,o);return o},pe=n=>n?xe(n):xe;class ln{constructor(e){Object.defineProperty(this,"uid",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_emitter",{enumerable:!0,configurable:!0,writable:!0,value:new Ut})}on(e,t){this._emitter.on(e,t)}once(e,t){this._emitter.once(e,t)}off(e,t){this._emitter.off(e,t)}emit(e,...t){const i=t[0];this._emitter.emit(e,{uid:this.uid,...i})}listenerCount(e){return this._emitter.listenerCount(e)}}function hn(n){return new ln(n)}function fn(n,e){return JSON.parse(n,(t,i)=>{let s=i;return(s==null?void 0:s.__type)==="bigint"&&(s=BigInt(s.value)),(s==null?void 0:s.__type)==="Map"&&(s=new Map(s.value)),(e==null?void 0:e(t,s))??s})}function We(n,e){return n.slice(0,e).join(".")||"."}function qe(n,e){const{length:t}=n;for(let i=0;i<t;++i)if(n[i]===e)return i+1;return 0}function gn(n,e){const t=typeof n=="function",i=typeof e=="function",s=[],r=[];return function(o,a){if(typeof a=="object")if(s.length){const d=qe(s,this);d===0?s[s.length]=this:(s.splice(d),r.splice(d)),r[r.length]=o;const c=qe(s,a);if(c!==0)return i?e.call(this,o,a,We(r,c)):`[ref=${We(r,c)}]`}else s[0]=a,r[0]=o;return t?n.call(this,o,a):a}}function mn(n,e,t,i){return JSON.stringify(n,gn((s,r)=>{let u=r;return typeof u=="bigint"&&(u={__type:"bigint",value:r.toString()}),u instanceof Map&&(u={__type:"Map",value:Array.from(r.entries())}),(e==null?void 0:e(s,u))??u},i),t??void 0)}function pn(n){const{deserialize:e=fn,key:t="wagmi",serialize:i=mn,storage:s=Xe}=n;function r(u){return u instanceof Promise?u.then(o=>o).catch(()=>null):u}return{...s,key:t,async getItem(u,o){const a=s.getItem(`${t}.${u}`),d=await r(a);return d?e(d)??null:o??null},async setItem(u,o){const a=`${t}.${u}`;o===null?await r(s.removeItem(a)):await r(s.setItem(a,i(o)))},async removeItem(u){await r(s.removeItem(`${t}.${u}`))}}}const Xe={getItem:()=>null,setItem:()=>{},removeItem:()=>{}};function wn(){const n=typeof window<"u"&&window.localStorage?window.localStorage:Xe;return{getItem(e){return n.getItem(e)},removeItem(e){n.removeItem(e)},setItem(e,t){try{n.setItem(e,t)}catch{}}}}const ve=256;let ie=ve,se;function Cn(n=11){if(!se||ie+n>ve*2){se="",ie=0;for(let e=0;e<ve;e++)se+=(256+Math.random()*256|0).toString(16).substring(1)}return se.substring(ie,ie+++n)}function bn(n){const{multiInjectedProviderDiscovery:e=!0,storage:t=pn({storage:wn()}),syncConnectedChain:i=!0,ssr:s=!1,...r}=n,u=typeof window<"u"&&e?jt():void 0,o=pe(()=>r.chains),a=pe(()=>{const g=[],w=new Set;for(const C of r.connectors??[]){const E=d(C);if(g.push(E),!s&&E.rdns){const v=typeof E.rdns=="string"?[E.rdns]:E.rdns;for(const _ of v)w.add(_)}}if(!s&&u){const C=u.getProviders();for(const E of C)w.has(E.info.rdns)||g.push(d(c(E)))}return g});function d(g){var E;const w=hn(Cn()),C={...g({emitter:w,chains:o.getState(),storage:t,transports:r.transports}),emitter:w,uid:w.uid};return w.on("connect",N),(E=C.setup)==null||E.call(C),C}function c(g){const{info:w}=g,C=g.provider;return de({target:{...w,id:w.rdns,provider:C}})}const l=new Map;function h(g={}){const w=g.chainId??b.getState().chainId,C=o.getState().find(v=>v.id===w);if(g.chainId&&!C)throw new X;{const v=l.get(b.getState().chainId);if(v&&!C)return v;if(!C)throw new X}{const v=l.get(w);if(v)return v}let E;if(r.client)E=r.client({chain:C});else{const v=C.id,_=o.getState().map($=>$.id),k={},Te=Object.entries(r);for(const[$,z]of Te)if(!($==="chains"||$==="client"||$==="connectors"||$==="transports"))if(typeof z=="object")if(v in z)k[$]=z[v];else{if(_.some(ot=>ot in z))continue;k[$]=z}else k[$]=z;E=Fe({...k,chain:C,batch:k.batch??{multicall:!0},transport:$=>r.transports[v]({...$,connectors:a})})}return l.set(w,E),E}function f(){return{chainId:o.getState()[0].id,connections:new Map,current:null,status:"disconnected"}}let p;const m="0.0.0-canary-";oe.startsWith(m)?p=Number.parseInt(oe.replace(m,""),10):p=Number.parseInt(oe.split(".")[0]??"0",10);const b=pe(cn(t?dn(f,{migrate(g,w){if(w===p)return g;const C=f(),E=I(g,C.chainId);return{...C,chainId:E}},name:"store",partialize(g){return{connections:{__type:"Map",value:Array.from(g.connections.entries()).map(([w,C])=>{const{id:E,name:v,type:_,uid:k}=C.connector;return[w,{...C,connector:{id:E,name:v,type:_,uid:k}}]})},chainId:g.chainId,current:g.current}},merge(g,w){typeof g=="object"&&g&&"status"in g&&delete g.status;const C=I(g,w.chainId);return{...w,...g,chainId:C}},skipHydration:s,storage:t,version:p}):f));b.setState(f());function I(g,w){return g&&typeof g=="object"&&"chainId"in g&&typeof g.chainId=="number"&&o.getState().some(C=>C.id===g.chainId)?g.chainId:w}i&&b.subscribe(({connections:g,current:w})=>{var C;return w?(C=g.get(w))==null?void 0:C.chainId:void 0},g=>{if(o.getState().some(C=>C.id===g))return b.setState(C=>({...C,chainId:g??C.chainId}))}),u==null||u.subscribe(g=>{const w=new Set,C=new Set;for(const v of a.getState())if(w.add(v.id),v.rdns){const _=typeof v.rdns=="string"?[v.rdns]:v.rdns;for(const k of _)C.add(k)}const E=[];for(const v of g){if(C.has(v.info.rdns))continue;const _=d(c(v));w.has(_.id)||E.push(_)}t&&!b.persist.hasHydrated()||a.setState(v=>[...v,...E],!0)});function y(g){b.setState(w=>{const C=w.connections.get(g.uid);return C?{...w,connections:new Map(w.connections).set(g.uid,{accounts:g.accounts??C.accounts,chainId:g.chainId??C.chainId,connector:C.connector})}:w})}function N(g){b.getState().status==="connecting"||b.getState().status==="reconnecting"||b.setState(w=>{const C=a.getState().find(E=>E.uid===g.uid);return C?(C.emitter.listenerCount("connect")&&C.emitter.off("connect",y),C.emitter.listenerCount("change")||C.emitter.on("change",y),C.emitter.listenerCount("disconnect")||C.emitter.on("disconnect",A),{...w,connections:new Map(w.connections).set(g.uid,{accounts:g.accounts,chainId:g.chainId,connector:C}),current:g.uid,status:"connected"}):w})}function A(g){b.setState(w=>{const C=w.connections.get(g.uid);if(C){const v=C.connector;v.emitter.listenerCount("change")&&C.connector.emitter.off("change",y),v.emitter.listenerCount("disconnect")&&C.connector.emitter.off("disconnect",A),v.emitter.listenerCount("connect")||C.connector.emitter.on("connect",N)}if(w.connections.delete(g.uid),w.connections.size===0)return{...w,connections:new Map,current:null,status:"disconnected"};const E=w.connections.values().next().value;return{...w,connections:new Map(w.connections),current:E.connector.uid}})}return{get chains(){return o.getState()},get connectors(){return a.getState()},storage:t,getClient:h,get state(){return b.getState()},setState(g){let w;typeof g=="function"?w=g(b.getState()):w=g;const C=f();typeof w!="object"&&(w=C),Object.keys(C).some(v=>!(v in w))&&(w=C),b.setState(w,!0)},subscribe(g,w,C){return b.subscribe(g,w,C?{...C,fireImmediately:C.emitImmediately}:void 0)},_internal:{mipd:u,async revalidate(){const g=b.getState(),w=g.connections;let C=g.current;for(const[,E]of w){const v=E.connector;v.isAuthorized&&await v.isAuthorized()||(w.delete(v.uid),C===v.uid&&(C=null))}b.setState(E=>({...E,connections:w,current:C}))},store:b,ssr:!!s,syncConnectedChain:i,transports:r.transports,chains:{setState(g){const w=typeof g=="function"?g(o.getState()):g;if(w.length!==0)return o.setState(w,!0)},subscribe(g){return o.subscribe(g)}},connectors:{providerDetailToConnector:c,setup:d,setState(g){return a.setState(typeof g=="function"?g(a.getState()):g,!0)},subscribe(g){return a.subscribe(g)}},events:{change:y,connect:N,disconnect:A}}}}function Ee(n,{strict:e=!0}={}){return!n||typeof n!="string"?!1:e?/^0x[0-9a-fA-F]*$/.test(n):n.startsWith("0x")}function Le(n){return Ee(n,{strict:!1})?Math.ceil((n.length-2)/2):n.length}const Qe="2.47.5";let V={getDocsUrl:({docsBaseUrl:n,docsPath:e="",docsSlug:t})=>e?`${n??"https://viem.sh"}${e}${t?`#${t}`:""}`:void 0,version:`viem@${Qe}`};class R extends Error{constructor(e,t={}){var o;const i=(()=>{var a;return t.cause instanceof R?t.cause.details:(a=t.cause)!=null&&a.message?t.cause.message:t.details})(),s=t.cause instanceof R&&t.cause.docsPath||t.docsPath,r=(o=V.getDocsUrl)==null?void 0:o.call(V,{...t,docsPath:s}),u=[e||"An error occurred.","",...t.metaMessages?[...t.metaMessages,""]:[],...r?[`Docs: ${r}`]:[],...i?[`Details: ${i}`]:[],...V.version?[`Version: ${V.version}`]:[]].join(`
4
- `);super(u,t.cause?{cause:t.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=i,this.docsPath=s,this.metaMessages=t.metaMessages,this.name=t.name??this.name,this.shortMessage=e,this.version=Qe}walk(e){return Ye(this,e)}}function Ye(n,e){return e!=null&&e(n)?n:n&&typeof n=="object"&&"cause"in n&&n.cause!==void 0?Ye(n.cause,e):e?null:n}class Ze extends R{constructor({size:e,targetSize:t,type:i}){super(`${i.charAt(0).toUpperCase()}${i.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:"SizeExceedsPaddingSizeError"})}}function le(n,{dir:e,size:t=32}={}){return typeof n=="string"?yn(n,{dir:e,size:t}):In(n,{dir:e,size:t})}function yn(n,{dir:e,size:t=32}={}){if(t===null)return n;const i=n.replace("0x","");if(i.length>t*2)throw new Ze({size:Math.ceil(i.length/2),targetSize:t,type:"hex"});return`0x${i[e==="right"?"padEnd":"padStart"](t*2,"0")}`}function In(n,{dir:e,size:t=32}={}){if(t===null)return n;if(n.length>t)throw new Ze({size:n.length,targetSize:t,type:"bytes"});const i=new Uint8Array(t);for(let s=0;s<t;s++){const r=e==="right";i[r?s:t-s-1]=n[r?s:n.length-s-1]}return i}class vn extends R{constructor({max:e,min:t,signed:i,size:s,value:r}){super(`Number "${r}" is not in safe ${s?`${s*8}-bit ${i?"signed":"unsigned"} `:""}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:"IntegerOutOfRangeError"})}}class An extends R{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function Ne(n,{size:e}){if(Le(n)>e)throw new An({givenSize:Le(n),maxSize:e})}function Ae(n,e={}){const{signed:t,size:i}=e,s=BigInt(n);let r;i?t?r=(1n<<BigInt(i)*8n-1n)-1n:r=2n**(BigInt(i)*8n)-1n:typeof n=="number"&&(r=BigInt(Number.MAX_SAFE_INTEGER));const u=typeof r=="bigint"&&t?-r-1n:0;if(r&&s>r||s<u){const a=typeof n=="bigint"?"n":"";throw new vn({max:r?`${r}${a}`:void 0,min:`${u}${a}`,signed:t,size:i,value:`${n}${a}`})}const o=`0x${(t&&s<0?(1n<<BigInt(i*8))+BigInt(s):s).toString(16)}`;return i?le(o,{size:i}):o}const En=new TextEncoder;function Nn(n,e={}){return typeof n=="number"||typeof n=="bigint"?Pn(n,e):typeof n=="boolean"?Sn(n,e):Ee(n)?et(n,e):tt(n,e)}function Sn(n,e={}){const t=new Uint8Array(1);return t[0]=Number(n),typeof e.size=="number"?(Ne(t,{size:e.size}),le(t,{size:e.size})):t}const j={zero:48,nine:57,A:65,F:70,a:97,f:102};function ze(n){if(n>=j.zero&&n<=j.nine)return n-j.zero;if(n>=j.A&&n<=j.F)return n-(j.A-10);if(n>=j.a&&n<=j.f)return n-(j.a-10)}function et(n,e={}){let t=n;e.size&&(Ne(t,{size:e.size}),t=le(t,{dir:"right",size:e.size}));let i=t.slice(2);i.length%2&&(i=`0${i}`);const s=i.length/2,r=new Uint8Array(s);for(let u=0,o=0;u<s;u++){const a=ze(i.charCodeAt(o++)),d=ze(i.charCodeAt(o++));if(a===void 0||d===void 0)throw new R(`Invalid byte sequence ("${i[o-2]}${i[o-1]}" in "${i}").`);r[u]=a*16+d}return r}function Pn(n,e){const t=Ae(n,e);return et(t)}function tt(n,e={}){const t=En.encode(n);return typeof e.size=="number"?(Ne(t,{size:e.size}),le(t,{dir:"right",size:e.size})):t}function Tn(n,e){return Ot(Ee(n,{strict:!1})?Nn(n):n)}class _n extends R{constructor({address:e}){super(`Address "${e}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class nt extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){const i=super.keys().next().value;i!==void 0&&super.delete(i)}return this}}const we=new nt(8192);function Se(n,e){if(we.has(`${n}.${e}`))return we.get(`${n}.${e}`);const t=e?`${e}${n.toLowerCase()}`:n.substring(2).toLowerCase(),i=Tn(tt(t)),s=(e?t.substring(`${e}0x`.length):t).split("");for(let u=0;u<40;u+=2)i[u>>1]>>4>=8&&s[u]&&(s[u]=s[u].toUpperCase()),(i[u>>1]&15)>=8&&s[u+1]&&(s[u+1]=s[u+1].toUpperCase());const r=`0x${s.join("")}`;return we.set(`${n}.${e}`,r),r}function it(n,e){if(!Rn(n,{strict:!1}))throw new _n({address:n});return Se(n,e)}const $n=/^0x[a-fA-F0-9]{40}$/,Ce=new nt(8192);function Rn(n,e){const{strict:t=!0}=e??{},i=`${n}.${t}`;if(Ce.has(i))return Ce.get(i);const s=$n.test(n)?n.toLowerCase()===n?!0:t?Se(n)===n:!0:!1;return Ce.set(i,s),s}const kn=(n,e,t)=>JSON.stringify(n,(i,s)=>typeof s=="bigint"?s.toString():s,t);function On(n,e){let t=n.toString();const i=t.startsWith("-");i&&(t=t.slice(1)),t=t.padStart(e,"0");let[s,r]=[t.slice(0,t.length-e),t.slice(t.length-e)];return r=r.replace(/(0+)$/,""),`${i?"-":""}${s||"0"}${r?`.${r}`:""}`}const Un=n=>n;class jn extends R{constructor({body:e,error:t,url:i}){super("RPC Request failed.",{cause:t,details:t.message,metaMessages:[`URL: ${Un(i)}`,`Request body: ${kn(e)}`],name:"RpcRequestError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"url",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.code=t.code,this.data=t.data,this.url=i}}const Mn=-1;class xn extends R{constructor(e,{code:t,docsPath:i,metaMessages:s,name:r,shortMessage:u}){super(u,{cause:e,docsPath:i,metaMessages:s||(e==null?void 0:e.metaMessages),name:r||"RpcError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=r||e.name,this.code=e instanceof jn?e.code:t??Mn}}class st extends xn{constructor(e,t){super(e,t),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=t.data}}class q extends st{constructor(e){super(e,{code:q.code,name:"UserRejectedRequestError",shortMessage:"User rejected the request."})}}Object.defineProperty(q,"code",{enumerable:!0,configurable:!0,writable:!0,value:4001});class H extends st{constructor(e){super(e,{code:H.code,name:"SwitchChainError",shortMessage:"An error occurred when attempting to switch chain."})}}Object.defineProperty(H,"code",{enumerable:!0,configurable:!0,writable:!0,value:4902});class Wn extends R{constructor({value:e}){super(`Number \`${e}\` is not a valid decimal number.`,{name:"InvalidDecimalNumberError"})}}function qn(n,e){if(!/^(-?)([0-9]*)\.?([0-9]*)$/.test(n))throw new Wn({value:n});let[t,i="0"]=n.split(".");const s=t.startsWith("-");if(s&&(t=t.slice(1)),i=i.replace(/(0+)$/,""),e===0)Math.round(+`.${i}`)===1&&(t=`${BigInt(t)+1n}`),i="";else if(i.length>e){const[r,u,o]=[i.slice(0,e-1),i.slice(e-1,e),i.slice(e)],a=Math.round(+`${u}.${o}`);a>9?i=`${BigInt(r)+BigInt(1)}0`.padStart(r.length+1,"0"):i=`${r}${a}`,i.length>e&&(i=i.slice(1),t=`${BigInt(t)+1n}`),i=i.slice(0,e)}else i=i.padEnd(e,"0");return BigInt(`${s?"-":""}${t}${i}`)}function rt(n){let e=[],t,i;function s(o){var c,l;const a=P.getCaipNetworks(S.CHAIN.EVM);let d=Number(be.parseEvmChainId(o));if(!a.some(h=>String(h.id)===String(o))){const h=((c=P.getActiveCaipNetwork(S.CHAIN.EVM))==null?void 0:c.id)||((l=a[0])==null?void 0:l.id);h&&Number.isInteger(Number(h))&&(d=Number(h))}if(!d)throw new Error("ChainId not found in networks");return d}function r(){var o;return t||(t=$e.getInstance({projectId:n.options.projectId,chainId:(o=Y())==null?void 0:o.caipNetworkId,enableLogger:n.options.enableAuthLogger,onTimeout:a=>{a==="iframe_load_failed"?D.open(x.ALERT_ERRORS.IFRAME_LOAD_FAILED,"error"):a==="iframe_request_timeout"?D.open(x.ALERT_ERRORS.IFRAME_REQUEST_TIMEOUT,"error"):a==="unverified_domain"&&D.open(x.ALERT_ERRORS.UNVERIFIED_DOMAIN,"error")},abortController:x.EmbeddedWalletAbortController,getActiveCaipNetwork:a=>Y(a),getCaipNetworks:a=>P.getCaipNetworks(a)})),t}async function u(o={}){var m;const a=r();let d=o.chainId;if(o.isReconnecting){const b=be.parseEvmChainId(a.getLastUsedChainId()||""),I=(m=n.chains)==null?void 0:m[0].id;if(d=b||I,!d)throw new Error("ChainId not found in provider")}const c=_e("eip155"),{address:l,chainId:h,accounts:f}=await at.authConnectorAuthenticate({authConnector:a,chainId:d,preferredAccountType:c,socialUri:o.socialUri,chainNamespace:S.CHAIN.EVM});e=(f==null?void 0:f.map(b=>b.address))||[l];const p=s(h);return{accounts:e,account:l,chainId:p,chain:{id:p,unsupported:!1}}}return o=>({id:S.CONNECTOR_ID.AUTH,name:S.CONNECTOR_NAMES.AUTH,type:"AUTH",chain:S.CHAIN.EVM,async connect(a={}){if(i){const c=await i;return{accounts:a.withCapabilities?c.accounts.map(l=>({address:l,capabilities:{}})):c.accounts,chainId:c.chainId}}i||(i=new Promise(c=>{c(u(a))}));const d=await i;return i=void 0,{accounts:a.withCapabilities?d.accounts.map(c=>({address:c,capabilities:{}})):d.accounts,chainId:d.chainId}},async disconnect(){await(await this.getProvider()).disconnect()},getAccounts(){return e!=null&&e.length?(o.emitter.emit("change",{accounts:e}),Promise.resolve(e)):Promise.resolve([])},async getProvider(){var a;return this.provider||(this.provider=$e.getInstance({projectId:n.options.projectId,chainId:(a=Y())==null?void 0:a.caipNetworkId,enableLogger:n.options.enableAuthLogger,abortController:x.EmbeddedWalletAbortController,onTimeout:d=>{d==="iframe_load_failed"?D.open(x.ALERT_ERRORS.IFRAME_LOAD_FAILED,"error"):d==="iframe_request_timeout"?D.open(x.ALERT_ERRORS.IFRAME_REQUEST_TIMEOUT,"error"):d==="unverified_domain"&&D.open(x.ALERT_ERRORS.UNVERIFIED_DOMAIN,"error")},getActiveCaipNetwork:d=>Y(d),getCaipNetworks:d=>P.getCaipNetworks(d)})),Promise.resolve(this.provider)},async getChainId(){const a=await this.getProvider(),{chainId:d}=await a.getChainId();return s(d)},async isAuthorized(){const d=P.state.activeChain===S.CHAIN.EVM;if(S.AUTH_CONNECTOR_SUPPORTED_CHAINS.some(h=>ct.getConnectorId(h)===S.CONNECTOR_ID.AUTH)&&!d)return!1;const l=await this.getProvider();return Promise.resolve(l.getLoginEmailUsed())},async switchChain({chainId:a}){var d;try{const c=o.chains.find(p=>p.id===a);if(!c)throw new H(new Error("chain not found on connector."));const l=await this.getProvider(),h=_e("eip155"),f=await l.connect({chainId:a,preferredAccountType:h});return e=((d=f==null?void 0:f.accounts)==null?void 0:d.map(p=>p.address))||[f.address],o.emitter.emit("change",{chainId:Number(a),accounts:e}),c}catch(c){throw c instanceof Error?new H(c):c}},onAccountsChanged(a){a.length===0?this.onDisconnect():o.emitter.emit("change",{accounts:a.map(it)})},onChainChanged(a){const d=Number(a);o.emitter.emit("change",{chainId:d})},async onDisconnect(a){await(await this.getProvider()).disconnect()}})}Pe.type="walletConnect";function Pe(n){const e=n.isNewChainsStale??!0;let t,i,s,r,u,o,a;return d=>({id:"walletConnect",name:"WalletConnect",type:Pe.type,provider:n.universalProvider,async setup(){const c=await this.getProvider().catch(()=>null);c&&(r||(r=this.onConnect.bind(this),c.on("connect",r)),o||(o=this.onSessionDelete.bind(this),c.on("session_delete",o)))},async connect({...c}={}){var l,h,f;try{const p=P.getCaipNetworks(),m=await this.getProvider();if(!m)throw new W;u||(u=this.onDisplayUri,m.on("display_uri",u));const b=await this.isChainsStale();m.session&&b&&await m.disconnect();const I=F.state.universalProviderConfigOverride;if(!m.session||b){const E=ut.createNamespaces(p,I);await m.connect({optionalNamespaces:E,..."pairingTopic"in c?{pairingTopic:c.pairingTopic}:{}}),this.setRequestedChainsIds(p.map(v=>Number(v.id)))}const y=await this.getAccounts(),N=await this.getChainId(),A=(f=(h=(l=m.session)==null?void 0:l.namespaces)==null?void 0:h.eip155)==null?void 0:f.chains,g=A==null?void 0:A.some(E=>Number(E.split(":")[1])===N);let w=1;g?w=N:A!=null&&A[0]&&(w=Number(A[0].split(":")[1])),u&&(m.removeListener("display_uri",u),u=void 0),r&&(m.removeListener("connect",r),r=void 0),i||(i=this.onAccountsChanged.bind(this),m.on("accountsChanged",i)),s||(s=this.onChainChanged.bind(this),m.on("chainChanged",s)),a||(a=this.onDisconnect.bind(this),m.on("disconnect",a)),o||(o=this.onSessionDelete.bind(this),m.on("session_delete",o));const C=I==null?void 0:I.defaultChain;return m.setDefaultChain(C??`eip155:${w}`),{accounts:y,chainId:w}}catch(p){throw/(user rejected|connection request reset)/i.test(p==null?void 0:p.message)?new q(p):p}},async disconnect(){const c=await this.getProvider();try{await(c==null?void 0:c.disconnect())}catch(l){if(!/No matching key/i.test(l.message))throw l}finally{s&&(c==null||c.removeListener("chainChanged",s),s=void 0),a&&(c==null||c.removeListener("disconnect",a),a=void 0),r||(r=this.onConnect.bind(this),c==null||c.on("connect",r)),i&&(c==null||c.removeListener("accountsChanged",i),i=void 0),o&&(c==null||c.removeListener("session_delete",o),o=void 0),this.setRequestedChainsIds([])}},async getAccounts(){var m,b,I;const c=await this.getProvider();if(!((m=c==null?void 0:c.session)!=null&&m.namespaces))return[];const l=(I=(b=c==null?void 0:c.session)==null?void 0:b.namespaces[S.CHAIN.EVM])==null?void 0:I.accounts,h=(l==null?void 0:l.map(y=>y.split(":")[2]))??[],f=new Set;return h.filter(y=>{const N=y==null?void 0:y.toLowerCase();return f.has(N)?!1:(f.add(N),!0)})},async getProvider({chainId:c}={}){var f,p;t||(t=n.universalProvider,t==null||t.events.setMaxListeners(Number.POSITIVE_INFINITY));const l=B.getActiveNamespace(),h=(f=P.getActiveCaipNetwork())==null?void 0:f.id;if(c&&h!==c&&l){const m=B.getStoredActiveCaipNetworkId(),b=l?P.getCaipNetworks(l):[],I=b==null?void 0:b.find(y=>y.id===m);I&&I.chainNamespace===S.CHAIN.EVM&&await((p=this.switchChain)==null?void 0:p.call(this,{chainId:Number(I.id)}))}return t},async getChainId(){var p,m,b,I;const c=(p=P.getActiveCaipNetwork(S.CHAIN.EVM))==null?void 0:p.id;if(c)return c;const h=(I=(b=(m=(await this.getProvider()).session)==null?void 0:m.namespaces[S.CHAIN.EVM])==null?void 0:b.chains)==null?void 0:I[0],f=P.getCaipNetworks().find(y=>y.id===h);return f==null?void 0:f.id},async isAuthorized(){try{const[c,l]=await Promise.all([this.getAccounts(),this.getProvider()]);return c.length?await this.isChainsStale()&&l.session?(await l.disconnect().catch(()=>{}),!1):!0:!1}catch{return!1}},async switchChain({addEthereumChainParameter:c,chainId:l}){var p,m,b,I;const h=await this.getProvider();if(!h)throw new W;const f=P.getCaipNetworks().find(y=>y.id===l);if(!f)throw new H(new X);try{await h.request({method:"wallet_switchEthereumChain",params:[{chainId:Ae(l)}]}),f!=null&&f.caipNetworkId&&h.setDefaultChain(f==null?void 0:f.caipNetworkId),d.emitter.emit("change",{chainId:Number(l)});const y=await this.getRequestedChainsIds();return this.setRequestedChainsIds([...y,l]),{...f,id:f.id}}catch(y){const N=y;if(/(?:user rejected)/iu.test(N.message))throw new q(N);try{let A;c!=null&&c.blockExplorerUrls?A=c.blockExplorerUrls:A=(p=f.blockExplorers)!=null&&p.default.url?[(m=f.blockExplorers)==null?void 0:m.default.url]:[];const g=((I=(b=f.rpcUrls)==null?void 0:b.chainDefault)==null?void 0:I.http)||[],w={blockExplorerUrls:A,chainId:Ae(l),chainName:f.name,iconUrls:c==null?void 0:c.iconUrls,nativeCurrency:f.nativeCurrency,rpcUrls:g};await h.request({method:"wallet_addEthereumChain",params:[w]});const C=await this.getRequestedChainsIds();return this.setRequestedChainsIds([...C,l]),{...f,id:f.id}}catch(A){throw new q(A)}}},onAccountsChanged(c){c.length===0?this.onDisconnect():d.emitter.emit("change",{accounts:c.map(l=>it(l))})},onChainChanged(c){const l=Number(c);d.emitter.emit("change",{chainId:l})},onConnect(c){this.setRequestedChainsIds(P.getCaipNetworks().map(l=>Number(l.id)))},async onDisconnect(c){this.setRequestedChainsIds([]),d.emitter.emit("disconnect");const l=await this.getProvider();i&&(l.removeListener("accountsChanged",i),i=void 0),s&&(l.removeListener("chainChanged",s),s=void 0),a&&(l.removeListener("disconnect",a),a=void 0),o&&(l.removeListener("session_delete",o),o=void 0),r||(r=this.onConnect.bind(this),l.on("connect",r))},onDisplayUri(c){d.emitter.emit("message",{type:"display_uri",data:c})},onSessionDelete(){this.onDisconnect()},getNamespaceChainsIds(){var h,f,p;if(!((h=t==null?void 0:t.session)!=null&&h.namespaces))return[];const c=(p=(f=t==null?void 0:t.session)==null?void 0:f.namespaces[S.CHAIN.EVM])==null?void 0:p.accounts;return(c==null?void 0:c.map(m=>Number.parseInt(m.split(":")[1]??"")))??[]},async getRequestedChainsIds(){var l;const c=await((l=d.storage)==null?void 0:l.getItem(this.requestedChainsStorageKey))??[];return[...new Set(c)]},async isChainsStale(){if(!e)return!1;const c=d.chains.map(f=>f.id),l=this.getNamespaceChainsIds();if(l.length&&!l.some(f=>c.includes(f)))return!1;const h=await this.getRequestedChainsIds();return!c.every(f=>h.includes(Number(f)))},async setRequestedChainsIds(c){var l;await((l=d.storage)==null?void 0:l.setItem(this.requestedChainsStorageKey,c))},get requestedChainsStorageKey(){return`${this.id}.requestedChains`}})}const G=dt({pendingTransactions:0}),De={state:G,subscribeKey(n,e){return lt(G,n,e)},increase(n){G[n]+=1},decrease(n){G[n]-=1},reset(n){G[n]=0}};async function Ln(n){if(re.isSafeApp()){const{safe:e}=await Ve(async()=>{const{safe:t}=await import("./index-eH-KBF3w.js");return{safe:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));if(e&&!n.some(t=>t.type==="safe"))return e()}return null}async function zn(n){try{const{baseAccount:e}=await Ve(async()=>{const{baseAccount:t}=await import("./index-eH-KBF3w.js");return{baseAccount:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));if(e&&!n.some(t=>t.id==="baseAccount"))return e()}catch(e){console.error("Failed to import Coinbase Wallet SDK:",e)}return null}const Dn={enable:!1,pollingInterval:3e4};class Fn extends ht{constructor(e){const t=Z.extendCaipNetworks(e.networks,{projectId:e.projectId,customNetworkImageUrls:{},customRpcUrls:e.customRpcUrls});super(),this.balancePromises={},this.namespace=S.CHAIN.EVM,this.adapterType=S.ADAPTER_TYPES.WAGMI,this.projectId=e.projectId,this.pendingTransactionsFilter={...Dn,...e.pendingTransactionsFilter??{}},this.createConfig({...e,networks:t}),this.checkChainId()}construct(e){this.checkChainId(),this.setupWatchers()}async getAccounts(e){const t=this.getWagmiConnector(e.id);if(!t)return{accounts:[]};if(t.id===S.CONNECTOR_ID.AUTH){const u=await t.getProvider();if(!(u!=null&&u.user))return{accounts:[]};const{address:o,accounts:a,chainId:d}=u.user;return Promise.resolve({accounts:(a||[{address:o,type:"eoa"}]).map(c=>re.createAccount({caipAddress:`eip155:${d}:${c.address}`,type:c.type}))})}const{addresses:i,address:s,chainId:r}=J(this.wagmiConfig);return Promise.resolve({accounts:r?[...new Set(i||[s])].map(u=>re.createAccount({caipAddress:`eip155:${r}:${u||""}`,type:"eoa"})):[]})}checkChainId(){const{chainId:e}=J(this.wagmiConfig);e&&this.emit("switchNetwork",{chainId:e})}getWagmiConnector(e){return this.wagmiConfig.connectors.find(t=>t.id===e)}createConfig(e){this.wagmiChains=e.networks.filter(s=>s.chainNamespace===S.CHAIN.EVM);const t={},i=[...e.connectors??[]];this.wagmiChains.forEach(s=>{var o,a;const r=(o=e.transports)==null?void 0:o[s.id],u=Z.getCaipNetworkId(s);r?t[s.id]=Z.extendWagmiTransports(s,e.projectId,r):t[s.id]=Z.getViemTransport(s,e.projectId,(a=e.customRpcUrls)==null?void 0:a[u])}),this.wagmiConfig=bn({...e,chains:this.wagmiChains,connectors:i,transports:t})}setupWatchPendingTransactions(){if(!this.pendingTransactionsFilter.enable||this.unwatchPendingTransactions)return;this.unwatchPendingTransactions=nn(this.wagmiConfig,{pollingInterval:this.pendingTransactionsFilter.pollingInterval,onError:()=>{},onTransactions:()=>{this.emit("pendingTransactions"),De.increase("pendingTransactions")}});const e=De.subscribeKey("pendingTransactions",t=>{var i;t>=S.LIMITS.PENDING_TRANSACTIONS&&((i=this.unwatchPendingTransactions)==null||i.call(this),e())})}setupWatchers(){en(this.wagmiConfig,{onChange:e=>{this.clearConnections(),this.addConnection(...e.map(t=>{const i=this.getCaipNetworks().find(r=>r.id===t.chainId),s=t.connector.id===S.CONNECTOR_ID.AUTH;return{accounts:t.accounts.map(r=>({address:this.toChecksummedAddress(r)})),caipNetwork:i,connectorId:t.connector.id,auth:s?{name:B.getConnectedSocialProvider(),username:B.getConnectedSocialUsername()}:void 0}}))}}),Zt(this.wagmiConfig,{onChange:(e,t)=>{var i;if(e.status==="disconnected"&&t.address&&this.emit("disconnect"),e!=null&&e.chainId&&(e==null?void 0:e.chainId)!==(t==null?void 0:t.chainId)&&this.emit("switchNetwork",{chainId:e.chainId}),e.status==="connected"){const s=e.address!==(t==null?void 0:t.address),r=e.connector.id!==((i=t.connector)==null?void 0:i.id),u=t.status!=="connected";(s||r||u)&&(this.setupWatchPendingTransactions(),this.handleAccountChanged({address:e.address,chainId:e.chainId,connector:e.connector}))}}})}async addThirdPartyConnectors(){const e=[],{enableCoinbase:t}=F.state||{};if(t!==!1){const s=await zn(this.wagmiConfig.connectors);s&&e.push(s)}const i=await Ln(this.wagmiConfig.connectors);i&&e.push(i),await Promise.all(e.map(s=>{const r=this.configureInternalConnector(s);return this.addWagmiConnector(r)}))}addWagmiConnectors(){const e=[];F.state.enableInjected!==!1&&e.push(de({shimDisconnect:!0}));const{features:t,remoteFeatures:i,projectId:s,enableAuthLogger:r}=F.state,u=(i==null?void 0:i.email)??(t==null?void 0:t.email)??!0,o=(i==null?void 0:i.socials)??(t==null?void 0:t.socials),a=Array.isArray(o)&&(o==null?void 0:o.length)>0;(u||a)&&e.push(rt({chains:this.wagmiChains,options:{projectId:s,enableAuthLogger:r}})),e.forEach(d=>{this.configureInternalConnector(d)})}configureInternalConnector(e){const t=this.wagmiConfig._internal.connectors.setup(e);return this.wagmiConfig._internal.connectors.setState(i=>[...i,t]),t}async handleAccountChanged({address:e,chainId:t,connector:i}){if(!this.namespace)throw new Error("WagmiAdapter:handleAccountChanged - namespace is required");const s=await i.getProvider().catch(()=>{});this.emit("accountChanged",{address:this.toChecksummedAddress(e),chainId:t,connector:{id:i.id,name:O.ConnectorNamesMap[i.id]??i.name,imageId:O.ConnectorImageIds[i.id],type:O.ConnectorTypesMap[i.type]??"EXTERNAL",info:i.id===S.CONNECTOR_ID.INJECTED?void 0:{rdns:i.id},provider:s,chain:this.namespace,chains:[]}})}async writeSolanaTransaction(){return Promise.resolve({hash:""})}async signMessage(e){try{return{signature:await Xt(this.wagmiConfig,{message:e.message,account:e.address})}}catch{throw new Error("WagmiAdapter:signMessage - Sign message failed")}}async sendTransaction(e){var o;const{chainId:t,address:i}=J(this.wagmiConfig),s=(o=this.wagmiChains)==null?void 0:o.find(a=>a.id===t),r={account:i,to:e.to,value:Number.isNaN(Number(e.value))?BigInt(0):BigInt(e.value),gas:e.gas?BigInt(e.gas):void 0,gasPrice:e.gasPrice?BigInt(e.gasPrice):void 0,data:e.data,chain:s,type:"legacy",parameters:["nonce"]};await Kt(this.wagmiConfig,r);const u=await Jt(this.wagmiConfig,r);return await Yt(this.wagmiConfig,{hash:u,timeout:25e3}),{hash:u}}async writeContract(e){var o;const{caipNetwork:t,...i}=e,s=Number(be.caipNetworkIdToNumber(t.caipNetworkId)),r=(o=this.wagmiChains)==null?void 0:o.find(a=>a.id===s);return{hash:await sn(this.wagmiConfig,{chain:r,address:i.tokenAddress,account:i.fromAddress,abi:i.abi,functionName:i.method,args:i.args,__mode:"prepared"})}}async estimateGas(e){try{return{gas:await Ft(this.wagmiConfig,{account:e.address,to:e.to,data:e.data,type:"legacy"})}}catch{throw new Error("WagmiAdapter:estimateGas - error estimating gas")}}parseUnits(e){return qn(e.value,e.decimals)}formatUnits(e){return On(e.value,e.decimals)}async addWagmiConnector(e){if(!this.namespace)throw new Error("WagmiAdapter:addWagmiConnector - namespace is required");const{enableEIP6963:t}=F.state||{};if(e.type===S.CONNECTOR_ID.INJECTED&&t===!1||e.id===S.CONNECTOR_ID.AUTH||e.id===S.CONNECTOR_ID.WALLET_CONNECT)return;let i;e.id!==S.CONNECTOR_ID.BASE_ACCOUNT&&(i=await e.getProvider().catch(()=>{}));const s=ft.state.connectorImages;this.addConnector({id:e.id,explorerId:O.ConnectorExplorerIds[e.id]??O.ConnectorExplorerIds[e.name],imageUrl:(s==null?void 0:s[e.id])??e.icon,name:O.ConnectorNamesMap[e.id]??e.name,imageId:O.ConnectorImageIds[e.id],type:O.ConnectorTypesMap[e.type]??"EXTERNAL",info:e.id===S.CONNECTOR_ID.INJECTED?void 0:{rdns:e.id},provider:i,chain:this.namespace,chains:[]})}async syncConnectors(){tn(this.wagmiConfig,{onChange:e=>{e.forEach(t=>this.addWagmiConnector(t))}}),this.addWagmiConnectors(),await Promise.all(this.wagmiConfig.connectors.map(e=>this.addWagmiConnector(e))),await this.addThirdPartyConnectors()}async syncConnections(){const e=this.connectors.filter(t=>{const{hasDisconnected:i,hasConnected:s}=ee.getConnectorStorageInfo(t.id,this.namespace);return!i&&s}).map(t=>this.getWagmiConnector(t.id)).filter(Boolean);await me(this.wagmiConfig,{connectors:e})}async syncConnection(e){var d,c;const{id:t,chainId:i}=e,r=M(this.wagmiConfig).find(l=>l.connector.id===t),u=this.getWagmiConnector(t),o=await(u==null?void 0:u.getProvider());if(re.isSafeApp()&&t===S.CONNECTOR_ID.SAFE&&!(r!=null&&r.accounts.length)){const l=this.getWagmiConnector("safe");if(l){const h=await fe(this.wagmiConfig,{connector:l,chainId:Number(i)}),f=await l.getProvider();return{chainId:Number(i),address:this.toChecksummedAddress(h.accounts[0]),provider:f,type:(d=r==null?void 0:r.connector.type)==null?void 0:d.toUpperCase(),id:r==null?void 0:r.connector.id}}}return{chainId:Number(r==null?void 0:r.chainId),address:this.toChecksummedAddress(r==null?void 0:r.accounts[0]),provider:o,type:(c=r==null?void 0:r.connector.type)==null?void 0:c.toUpperCase(),id:r==null?void 0:r.connector.id}}async connectWalletConnect(e){try{const t=this.getWalletConnectConnector();await t.authenticate();const i=this.getWagmiConnector("walletConnect");if(!i)throw new Error("UniversalAdapter:connectWalletConnect - connector not found");const s=await fe(this.wagmiConfig,{connector:i,chainId:e?Number(e):void 0});return s.chainId!==Number(e)&&await Me(this.wagmiConfig,{chainId:s.chainId}),{clientId:await t.provider.client.core.crypto.getClientId()}}catch(t){throw t instanceof q?new te(t):Re.isUserRejectedRequestError(t)?new te(t):t}}async connect(e){var t,i,s,r,u;try{const{id:o,address:a,provider:d,type:c,info:l,chainId:h,socialUri:f}=e,p=this.getWagmiConnector(o);if(!p)throw new Error("connectionControllerClient:connectExternal - connector is undefined");d&&l&&p.id===S.CONNECTOR_ID.EIP6963&&((t=p.setEip6963Wallet)==null||t.call(p,{provider:d,info:l}));const m=(s=(i=this.wagmiConfig.state)==null?void 0:i.connections)==null?void 0:s.get(p.uid);if(m){await((r=this.wagmiConfig.storage)==null?void 0:r.setItem("recentConnectorId",p.id));const y=[...m.accounts].sort((N,A)=>ee.isLowerCaseMatch(N,a)?-1:ee.isLowerCaseMatch(A,a)?1:0);return(u=this.wagmiConfig)==null||u.setState(N=>({...N,connections:new Map(N.connections).set(p.uid,{accounts:y,chainId:m.chainId,connector:m.connector}),current:p.uid,status:"connected"})),{address:this.toChecksummedAddress(y[0]),chainId:m.chainId,provider:d,type:c,id:o}}const b=await fe(this.wagmiConfig,{connector:p,chainId:h?Number(h):void 0,socialUri:f}),I=d??await p.getProvider();return{address:this.toChecksummedAddress(b.accounts[0]),chainId:b.chainId,provider:I,type:c,id:o}}catch(o){throw o instanceof q?new te(o):Re.isUserRejectedRequestError(o)?new te(o):o}}get connections(){return Array.from(this.wagmiConfig.state.connections.values()).map(e=>({accounts:e.accounts.map(t=>({address:this.toChecksummedAddress(t)})),connectorId:e.connector.id}))}async reconnect(e){const{id:t}=e,i=this.getWagmiConnector(t);if(!i)throw new Error("connectionControllerClient:connectExternal - connector is undefined");await me(this.wagmiConfig,{connectors:[i]})}async getBalance(e){const t=e.address,i=this.getCaipNetworks().find(s=>s.id===e.chainId);if(!t)return Promise.resolve({balance:"0.00",symbol:"ETH"});if(i&&this.wagmiConfig){const s=`${i.caipNetworkId}:${e.address}`,r=this.balancePromises[s];if(r)return r;const u=B.getNativeBalanceCacheForCaipAddress(s);return u?{balance:u.balance,symbol:u.symbol}:(this.balancePromises[s]=new Promise(async o=>{var a,d;try{const c=Number(e.chainId),l=await Gt(this.wagmiConfig,{address:e.address,chainId:c,token:(d=(a=e.tokens)==null?void 0:a[i.caipNetworkId])==null?void 0:d.address});B.updateNativeBalanceCache({caipAddress:s,balance:l.formatted,symbol:l.symbol,timestamp:Date.now()}),o({balance:l.formatted,symbol:l.symbol})}catch(c){console.warn("Appkit:WagmiAdapter:getBalance - Error getting balance",c),o({balance:"0.00",symbol:"ETH"})}}).finally(()=>{delete this.balancePromises[s]}),this.balancePromises[s]||{balance:"0.00",symbol:"ETH"})}return{balance:"",symbol:""}}getWalletConnectProvider(){var e;return(e=this.getWagmiConnector("walletConnect"))==null?void 0:e.provider}async disconnect(e){if(e.id){const t=this.getWagmiConnector(e.id),s=M(this.wagmiConfig).find(r=>ee.isLowerCaseMatch(r.connector.id,e.id));return await Ue(this.wagmiConfig,{connector:t}),F.state.enableReconnect===!1&&this.deleteConnection(e.id),s?{connections:[{accounts:s.accounts.map(r=>({address:this.toChecksummedAddress(r)})),connectorId:s.connector.id}]}:{connections:[]}}return this.disconnectAll()}async disconnectAll(){const e=M(this.wagmiConfig),t=await Promise.allSettled(e.map(async i=>{const s=this.getWagmiConnector(i.connector.id);return s&&await Ue(this.wagmiConfig,{connector:s}),i}));return this.wagmiConfig.state.connections.clear(),{connections:t.filter(i=>i.status==="fulfilled").map(({value:i})=>({accounts:i.accounts.map(s=>({address:this.toChecksummedAddress(s)})),connectorId:i.connector.id}))}}async switchNetwork(e){var f,p,m,b,I;const{caipNetwork:t}=e,i=this.wagmiConfig.chains.find(y=>y.id.toString()===t.id.toString());if(!i)throw new Error("connectionControllerClient:switchNetwork - wagmiChain is undefined");const{name:s,nativeCurrency:r,rpcUrls:u,blockExplorers:o,id:a}=i,d=((m=(p=(f=t.rpcUrls)==null?void 0:f.chainDefault)==null?void 0:p.http)==null?void 0:m[0])??u.default.http[0]??"",c=(o==null?void 0:o.default.url)??((I=(b=t.blockExplorers)==null?void 0:b.default)==null?void 0:I.url)??"",l=r??t.nativeCurrency,h=s??t.name;await Me(this.wagmiConfig,{chainId:a,addEthereumChainParameter:{chainName:h,nativeCurrency:l,rpcUrls:[d],blockExplorerUrls:[c]}}),await super.switchNetwork(e)}async getCapabilities(e){if(!this.wagmiConfig)throw new Error("connectionControllerClient:getCapabilities - wagmiConfig is undefined");const i=M(this.wagmiConfig)[0],s=i?this.getWagmiConnector(i.connector.id):null;if(!s)throw new Error("connectionControllerClient:getCapabilities - connector is undefined");const r=await s.getProvider();if(!r)throw new Error("connectionControllerClient:getCapabilities - provider is undefined");return await r.request({method:"wallet_getCapabilities",params:[e]})}async grantPermissions(e){if(!this.wagmiConfig)throw new Error("connectionControllerClient:grantPermissions - wagmiConfig is undefined");const i=M(this.wagmiConfig)[0],s=i?this.getWagmiConnector(i.connector.id):null;if(!s)throw new Error("connectionControllerClient:grantPermissions - connector is undefined");const r=await s.getProvider();if(!r)throw new Error("connectionControllerClient:grantPermissions - provider is undefined");return r.request({method:"wallet_grantPermissions",params:e})}async revokePermissions(e){if(!this.wagmiConfig)throw new Error("connectionControllerClient:revokePermissions - wagmiConfig is undefined");const i=M(this.wagmiConfig)[0],s=i?this.getWagmiConnector(i.connector.id):null;if(!s)throw new Error("connectionControllerClient:revokePermissions - connector is undefined");const r=await s.getProvider();if(!r)throw new Error("connectionControllerClient:revokePermissions - provider is undefined");return r.request({method:"wallet_revokePermissions",params:e})}async walletGetAssets(e){if(!this.wagmiConfig)throw new Error("connectionControllerClient:walletGetAssets - wagmiConfig is undefined");const i=M(this.wagmiConfig)[0],s=i?this.getWagmiConnector(i.connector.id):null;if(!s)throw new Error("connectionControllerClient:walletGetAssets - connector is undefined");const r=await s.getProvider();if(!r)throw new Error("connectionControllerClient:walletGetAssets - provider is undefined");return r.request({method:"wallet_getAssets",params:[e]})}setAuthProvider(e){if(!this.namespace)throw new Error("WagmiAdapter:setAuthProvider - namespace is required");this.addConnector({id:S.CONNECTOR_ID.AUTH,type:"AUTH",name:S.CONNECTOR_NAMES.AUTH,provider:e,imageId:O.ConnectorImageIds[S.CONNECTOR_ID.AUTH],chain:this.namespace,chains:[]})}async setUniversalProvider(e){e.on("connect",()=>{const i=M(this.wagmiConfig),s=this.getWagmiConnector("walletConnect");if(s&&!i.find(r=>r.connector.id===s.id)){if(P.state.activeChain==="eip155")return;me(this.wagmiConfig,{connectors:[s]})}});const t=Pe({universalProvider:e});return this.configureInternalConnector(t),this.addConnector(new gt({provider:e,caipNetworks:this.getCaipNetworks(),namespace:"eip155"})),Promise.resolve()}toChecksummedAddress(e){return Se(e.toLowerCase())}}const ei=Object.freeze(Object.defineProperty({__proto__:null,WagmiAdapter:Fn,authConnector:rt},Symbol.toStringTag,{value:"Module"}));export{X as C,W as P,ei as a,Zn as c,de as i,Mt as w};
4
+ `);super(u,t.cause?{cause:t.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=i,this.docsPath=s,this.metaMessages=t.metaMessages,this.name=t.name??this.name,this.shortMessage=e,this.version=Qe}walk(e){return Ye(this,e)}}function Ye(n,e){return e!=null&&e(n)?n:n&&typeof n=="object"&&"cause"in n&&n.cause!==void 0?Ye(n.cause,e):e?null:n}class Ze extends R{constructor({size:e,targetSize:t,type:i}){super(`${i.charAt(0).toUpperCase()}${i.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:"SizeExceedsPaddingSizeError"})}}function le(n,{dir:e,size:t=32}={}){return typeof n=="string"?yn(n,{dir:e,size:t}):In(n,{dir:e,size:t})}function yn(n,{dir:e,size:t=32}={}){if(t===null)return n;const i=n.replace("0x","");if(i.length>t*2)throw new Ze({size:Math.ceil(i.length/2),targetSize:t,type:"hex"});return`0x${i[e==="right"?"padEnd":"padStart"](t*2,"0")}`}function In(n,{dir:e,size:t=32}={}){if(t===null)return n;if(n.length>t)throw new Ze({size:n.length,targetSize:t,type:"bytes"});const i=new Uint8Array(t);for(let s=0;s<t;s++){const r=e==="right";i[r?s:t-s-1]=n[r?s:n.length-s-1]}return i}class vn extends R{constructor({max:e,min:t,signed:i,size:s,value:r}){super(`Number "${r}" is not in safe ${s?`${s*8}-bit ${i?"signed":"unsigned"} `:""}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:"IntegerOutOfRangeError"})}}class An extends R{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function Ne(n,{size:e}){if(Le(n)>e)throw new An({givenSize:Le(n),maxSize:e})}function Ae(n,e={}){const{signed:t,size:i}=e,s=BigInt(n);let r;i?t?r=(1n<<BigInt(i)*8n-1n)-1n:r=2n**(BigInt(i)*8n)-1n:typeof n=="number"&&(r=BigInt(Number.MAX_SAFE_INTEGER));const u=typeof r=="bigint"&&t?-r-1n:0;if(r&&s>r||s<u){const a=typeof n=="bigint"?"n":"";throw new vn({max:r?`${r}${a}`:void 0,min:`${u}${a}`,signed:t,size:i,value:`${n}${a}`})}const o=`0x${(t&&s<0?(1n<<BigInt(i*8))+BigInt(s):s).toString(16)}`;return i?le(o,{size:i}):o}const En=new TextEncoder;function Nn(n,e={}){return typeof n=="number"||typeof n=="bigint"?Pn(n,e):typeof n=="boolean"?Sn(n,e):Ee(n)?et(n,e):tt(n,e)}function Sn(n,e={}){const t=new Uint8Array(1);return t[0]=Number(n),typeof e.size=="number"?(Ne(t,{size:e.size}),le(t,{size:e.size})):t}const j={zero:48,nine:57,A:65,F:70,a:97,f:102};function ze(n){if(n>=j.zero&&n<=j.nine)return n-j.zero;if(n>=j.A&&n<=j.F)return n-(j.A-10);if(n>=j.a&&n<=j.f)return n-(j.a-10)}function et(n,e={}){let t=n;e.size&&(Ne(t,{size:e.size}),t=le(t,{dir:"right",size:e.size}));let i=t.slice(2);i.length%2&&(i=`0${i}`);const s=i.length/2,r=new Uint8Array(s);for(let u=0,o=0;u<s;u++){const a=ze(i.charCodeAt(o++)),d=ze(i.charCodeAt(o++));if(a===void 0||d===void 0)throw new R(`Invalid byte sequence ("${i[o-2]}${i[o-1]}" in "${i}").`);r[u]=a*16+d}return r}function Pn(n,e){const t=Ae(n,e);return et(t)}function tt(n,e={}){const t=En.encode(n);return typeof e.size=="number"?(Ne(t,{size:e.size}),le(t,{dir:"right",size:e.size})):t}function Tn(n,e){return Ot(Ee(n,{strict:!1})?Nn(n):n)}class _n extends R{constructor({address:e}){super(`Address "${e}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class nt extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){const i=super.keys().next().value;i!==void 0&&super.delete(i)}return this}}const we=new nt(8192);function Se(n,e){if(we.has(`${n}.${e}`))return we.get(`${n}.${e}`);const t=e?`${e}${n.toLowerCase()}`:n.substring(2).toLowerCase(),i=Tn(tt(t)),s=(e?t.substring(`${e}0x`.length):t).split("");for(let u=0;u<40;u+=2)i[u>>1]>>4>=8&&s[u]&&(s[u]=s[u].toUpperCase()),(i[u>>1]&15)>=8&&s[u+1]&&(s[u+1]=s[u+1].toUpperCase());const r=`0x${s.join("")}`;return we.set(`${n}.${e}`,r),r}function it(n,e){if(!Rn(n,{strict:!1}))throw new _n({address:n});return Se(n,e)}const $n=/^0x[a-fA-F0-9]{40}$/,Ce=new nt(8192);function Rn(n,e){const{strict:t=!0}=e??{},i=`${n}.${t}`;if(Ce.has(i))return Ce.get(i);const s=$n.test(n)?n.toLowerCase()===n?!0:t?Se(n)===n:!0:!1;return Ce.set(i,s),s}const kn=(n,e,t)=>JSON.stringify(n,(i,s)=>typeof s=="bigint"?s.toString():s,t);function On(n,e){let t=n.toString();const i=t.startsWith("-");i&&(t=t.slice(1)),t=t.padStart(e,"0");let[s,r]=[t.slice(0,t.length-e),t.slice(t.length-e)];return r=r.replace(/(0+)$/,""),`${i?"-":""}${s||"0"}${r?`.${r}`:""}`}const Un=n=>n;class jn extends R{constructor({body:e,error:t,url:i}){super("RPC Request failed.",{cause:t,details:t.message,metaMessages:[`URL: ${Un(i)}`,`Request body: ${kn(e)}`],name:"RpcRequestError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"url",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.code=t.code,this.data=t.data,this.url=i}}const Mn=-1;class xn extends R{constructor(e,{code:t,docsPath:i,metaMessages:s,name:r,shortMessage:u}){super(u,{cause:e,docsPath:i,metaMessages:s||(e==null?void 0:e.metaMessages),name:r||"RpcError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=r||e.name,this.code=e instanceof jn?e.code:t??Mn}}class st extends xn{constructor(e,t){super(e,t),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=t.data}}class q extends st{constructor(e){super(e,{code:q.code,name:"UserRejectedRequestError",shortMessage:"User rejected the request."})}}Object.defineProperty(q,"code",{enumerable:!0,configurable:!0,writable:!0,value:4001});class H extends st{constructor(e){super(e,{code:H.code,name:"SwitchChainError",shortMessage:"An error occurred when attempting to switch chain."})}}Object.defineProperty(H,"code",{enumerable:!0,configurable:!0,writable:!0,value:4902});class Wn extends R{constructor({value:e}){super(`Number \`${e}\` is not a valid decimal number.`,{name:"InvalidDecimalNumberError"})}}function qn(n,e){if(!/^(-?)([0-9]*)\.?([0-9]*)$/.test(n))throw new Wn({value:n});let[t,i="0"]=n.split(".");const s=t.startsWith("-");if(s&&(t=t.slice(1)),i=i.replace(/(0+)$/,""),e===0)Math.round(+`.${i}`)===1&&(t=`${BigInt(t)+1n}`),i="";else if(i.length>e){const[r,u,o]=[i.slice(0,e-1),i.slice(e-1,e),i.slice(e)],a=Math.round(+`${u}.${o}`);a>9?i=`${BigInt(r)+BigInt(1)}0`.padStart(r.length+1,"0"):i=`${r}${a}`,i.length>e&&(i=i.slice(1),t=`${BigInt(t)+1n}`),i=i.slice(0,e)}else i=i.padEnd(e,"0");return BigInt(`${s?"-":""}${t}${i}`)}function rt(n){let e=[],t,i;function s(o){var c,l;const a=P.getCaipNetworks(S.CHAIN.EVM);let d=Number(be.parseEvmChainId(o));if(!a.some(h=>String(h.id)===String(o))){const h=((c=P.getActiveCaipNetwork(S.CHAIN.EVM))==null?void 0:c.id)||((l=a[0])==null?void 0:l.id);h&&Number.isInteger(Number(h))&&(d=Number(h))}if(!d)throw new Error("ChainId not found in networks");return d}function r(){var o;return t||(t=$e.getInstance({projectId:n.options.projectId,chainId:(o=Y())==null?void 0:o.caipNetworkId,enableLogger:n.options.enableAuthLogger,onTimeout:a=>{a==="iframe_load_failed"?D.open(x.ALERT_ERRORS.IFRAME_LOAD_FAILED,"error"):a==="iframe_request_timeout"?D.open(x.ALERT_ERRORS.IFRAME_REQUEST_TIMEOUT,"error"):a==="unverified_domain"&&D.open(x.ALERT_ERRORS.UNVERIFIED_DOMAIN,"error")},abortController:x.EmbeddedWalletAbortController,getActiveCaipNetwork:a=>Y(a),getCaipNetworks:a=>P.getCaipNetworks(a)})),t}async function u(o={}){var m;const a=r();let d=o.chainId;if(o.isReconnecting){const b=be.parseEvmChainId(a.getLastUsedChainId()||""),I=(m=n.chains)==null?void 0:m[0].id;if(d=b||I,!d)throw new Error("ChainId not found in provider")}const c=_e("eip155"),{address:l,chainId:h,accounts:f}=await at.authConnectorAuthenticate({authConnector:a,chainId:d,preferredAccountType:c,socialUri:o.socialUri,chainNamespace:S.CHAIN.EVM});e=(f==null?void 0:f.map(b=>b.address))||[l];const p=s(h);return{accounts:e,account:l,chainId:p,chain:{id:p,unsupported:!1}}}return o=>({id:S.CONNECTOR_ID.AUTH,name:S.CONNECTOR_NAMES.AUTH,type:"AUTH",chain:S.CHAIN.EVM,async connect(a={}){if(i){const c=await i;return{accounts:a.withCapabilities?c.accounts.map(l=>({address:l,capabilities:{}})):c.accounts,chainId:c.chainId}}i||(i=new Promise(c=>{c(u(a))}));const d=await i;return i=void 0,{accounts:a.withCapabilities?d.accounts.map(c=>({address:c,capabilities:{}})):d.accounts,chainId:d.chainId}},async disconnect(){await(await this.getProvider()).disconnect()},getAccounts(){return e!=null&&e.length?(o.emitter.emit("change",{accounts:e}),Promise.resolve(e)):Promise.resolve([])},async getProvider(){var a;return this.provider||(this.provider=$e.getInstance({projectId:n.options.projectId,chainId:(a=Y())==null?void 0:a.caipNetworkId,enableLogger:n.options.enableAuthLogger,abortController:x.EmbeddedWalletAbortController,onTimeout:d=>{d==="iframe_load_failed"?D.open(x.ALERT_ERRORS.IFRAME_LOAD_FAILED,"error"):d==="iframe_request_timeout"?D.open(x.ALERT_ERRORS.IFRAME_REQUEST_TIMEOUT,"error"):d==="unverified_domain"&&D.open(x.ALERT_ERRORS.UNVERIFIED_DOMAIN,"error")},getActiveCaipNetwork:d=>Y(d),getCaipNetworks:d=>P.getCaipNetworks(d)})),Promise.resolve(this.provider)},async getChainId(){const a=await this.getProvider(),{chainId:d}=await a.getChainId();return s(d)},async isAuthorized(){const d=P.state.activeChain===S.CHAIN.EVM;if(S.AUTH_CONNECTOR_SUPPORTED_CHAINS.some(h=>ct.getConnectorId(h)===S.CONNECTOR_ID.AUTH)&&!d)return!1;const l=await this.getProvider();return Promise.resolve(l.getLoginEmailUsed())},async switchChain({chainId:a}){var d;try{const c=o.chains.find(p=>p.id===a);if(!c)throw new H(new Error("chain not found on connector."));const l=await this.getProvider(),h=_e("eip155"),f=await l.connect({chainId:a,preferredAccountType:h});return e=((d=f==null?void 0:f.accounts)==null?void 0:d.map(p=>p.address))||[f.address],o.emitter.emit("change",{chainId:Number(a),accounts:e}),c}catch(c){throw c instanceof Error?new H(c):c}},onAccountsChanged(a){a.length===0?this.onDisconnect():o.emitter.emit("change",{accounts:a.map(it)})},onChainChanged(a){const d=Number(a);o.emitter.emit("change",{chainId:d})},async onDisconnect(a){await(await this.getProvider()).disconnect()}})}Pe.type="walletConnect";function Pe(n){const e=n.isNewChainsStale??!0;let t,i,s,r,u,o,a;return d=>({id:"walletConnect",name:"WalletConnect",type:Pe.type,provider:n.universalProvider,async setup(){const c=await this.getProvider().catch(()=>null);c&&(r||(r=this.onConnect.bind(this),c.on("connect",r)),o||(o=this.onSessionDelete.bind(this),c.on("session_delete",o)))},async connect({...c}={}){var l,h,f;try{const p=P.getCaipNetworks(),m=await this.getProvider();if(!m)throw new W;u||(u=this.onDisplayUri,m.on("display_uri",u));const b=await this.isChainsStale();m.session&&b&&await m.disconnect();const I=F.state.universalProviderConfigOverride;if(!m.session||b){const E=ut.createNamespaces(p,I);await m.connect({optionalNamespaces:E,..."pairingTopic"in c?{pairingTopic:c.pairingTopic}:{}}),this.setRequestedChainsIds(p.map(v=>Number(v.id)))}const y=await this.getAccounts(),N=await this.getChainId(),A=(f=(h=(l=m.session)==null?void 0:l.namespaces)==null?void 0:h.eip155)==null?void 0:f.chains,g=A==null?void 0:A.some(E=>Number(E.split(":")[1])===N);let w=1;g?w=N:A!=null&&A[0]&&(w=Number(A[0].split(":")[1])),u&&(m.removeListener("display_uri",u),u=void 0),r&&(m.removeListener("connect",r),r=void 0),i||(i=this.onAccountsChanged.bind(this),m.on("accountsChanged",i)),s||(s=this.onChainChanged.bind(this),m.on("chainChanged",s)),a||(a=this.onDisconnect.bind(this),m.on("disconnect",a)),o||(o=this.onSessionDelete.bind(this),m.on("session_delete",o));const C=I==null?void 0:I.defaultChain;return m.setDefaultChain(C??`eip155:${w}`),{accounts:y,chainId:w}}catch(p){throw/(user rejected|connection request reset)/i.test(p==null?void 0:p.message)?new q(p):p}},async disconnect(){const c=await this.getProvider();try{await(c==null?void 0:c.disconnect())}catch(l){if(!/No matching key/i.test(l.message))throw l}finally{s&&(c==null||c.removeListener("chainChanged",s),s=void 0),a&&(c==null||c.removeListener("disconnect",a),a=void 0),r||(r=this.onConnect.bind(this),c==null||c.on("connect",r)),i&&(c==null||c.removeListener("accountsChanged",i),i=void 0),o&&(c==null||c.removeListener("session_delete",o),o=void 0),this.setRequestedChainsIds([])}},async getAccounts(){var m,b,I;const c=await this.getProvider();if(!((m=c==null?void 0:c.session)!=null&&m.namespaces))return[];const l=(I=(b=c==null?void 0:c.session)==null?void 0:b.namespaces[S.CHAIN.EVM])==null?void 0:I.accounts,h=(l==null?void 0:l.map(y=>y.split(":")[2]))??[],f=new Set;return h.filter(y=>{const N=y==null?void 0:y.toLowerCase();return f.has(N)?!1:(f.add(N),!0)})},async getProvider({chainId:c}={}){var f,p;t||(t=n.universalProvider,t==null||t.events.setMaxListeners(Number.POSITIVE_INFINITY));const l=B.getActiveNamespace(),h=(f=P.getActiveCaipNetwork())==null?void 0:f.id;if(c&&h!==c&&l){const m=B.getStoredActiveCaipNetworkId(),b=l?P.getCaipNetworks(l):[],I=b==null?void 0:b.find(y=>y.id===m);I&&I.chainNamespace===S.CHAIN.EVM&&await((p=this.switchChain)==null?void 0:p.call(this,{chainId:Number(I.id)}))}return t},async getChainId(){var p,m,b,I;const c=(p=P.getActiveCaipNetwork(S.CHAIN.EVM))==null?void 0:p.id;if(c)return c;const h=(I=(b=(m=(await this.getProvider()).session)==null?void 0:m.namespaces[S.CHAIN.EVM])==null?void 0:b.chains)==null?void 0:I[0],f=P.getCaipNetworks().find(y=>y.id===h);return f==null?void 0:f.id},async isAuthorized(){try{const[c,l]=await Promise.all([this.getAccounts(),this.getProvider()]);return c.length?await this.isChainsStale()&&l.session?(await l.disconnect().catch(()=>{}),!1):!0:!1}catch{return!1}},async switchChain({addEthereumChainParameter:c,chainId:l}){var p,m,b,I;const h=await this.getProvider();if(!h)throw new W;const f=P.getCaipNetworks().find(y=>y.id===l);if(!f)throw new H(new X);try{await h.request({method:"wallet_switchEthereumChain",params:[{chainId:Ae(l)}]}),f!=null&&f.caipNetworkId&&h.setDefaultChain(f==null?void 0:f.caipNetworkId),d.emitter.emit("change",{chainId:Number(l)});const y=await this.getRequestedChainsIds();return this.setRequestedChainsIds([...y,l]),{...f,id:f.id}}catch(y){const N=y;if(/(?:user rejected)/iu.test(N.message))throw new q(N);try{let A;c!=null&&c.blockExplorerUrls?A=c.blockExplorerUrls:A=(p=f.blockExplorers)!=null&&p.default.url?[(m=f.blockExplorers)==null?void 0:m.default.url]:[];const g=((I=(b=f.rpcUrls)==null?void 0:b.chainDefault)==null?void 0:I.http)||[],w={blockExplorerUrls:A,chainId:Ae(l),chainName:f.name,iconUrls:c==null?void 0:c.iconUrls,nativeCurrency:f.nativeCurrency,rpcUrls:g};await h.request({method:"wallet_addEthereumChain",params:[w]});const C=await this.getRequestedChainsIds();return this.setRequestedChainsIds([...C,l]),{...f,id:f.id}}catch(A){throw new q(A)}}},onAccountsChanged(c){c.length===0?this.onDisconnect():d.emitter.emit("change",{accounts:c.map(l=>it(l))})},onChainChanged(c){const l=Number(c);d.emitter.emit("change",{chainId:l})},onConnect(c){this.setRequestedChainsIds(P.getCaipNetworks().map(l=>Number(l.id)))},async onDisconnect(c){this.setRequestedChainsIds([]),d.emitter.emit("disconnect");const l=await this.getProvider();i&&(l.removeListener("accountsChanged",i),i=void 0),s&&(l.removeListener("chainChanged",s),s=void 0),a&&(l.removeListener("disconnect",a),a=void 0),o&&(l.removeListener("session_delete",o),o=void 0),r||(r=this.onConnect.bind(this),l.on("connect",r))},onDisplayUri(c){d.emitter.emit("message",{type:"display_uri",data:c})},onSessionDelete(){this.onDisconnect()},getNamespaceChainsIds(){var h,f,p;if(!((h=t==null?void 0:t.session)!=null&&h.namespaces))return[];const c=(p=(f=t==null?void 0:t.session)==null?void 0:f.namespaces[S.CHAIN.EVM])==null?void 0:p.accounts;return(c==null?void 0:c.map(m=>Number.parseInt(m.split(":")[1]??"")))??[]},async getRequestedChainsIds(){var l;const c=await((l=d.storage)==null?void 0:l.getItem(this.requestedChainsStorageKey))??[];return[...new Set(c)]},async isChainsStale(){if(!e)return!1;const c=d.chains.map(f=>f.id),l=this.getNamespaceChainsIds();if(l.length&&!l.some(f=>c.includes(f)))return!1;const h=await this.getRequestedChainsIds();return!c.every(f=>h.includes(Number(f)))},async setRequestedChainsIds(c){var l;await((l=d.storage)==null?void 0:l.setItem(this.requestedChainsStorageKey,c))},get requestedChainsStorageKey(){return`${this.id}.requestedChains`}})}const G=dt({pendingTransactions:0}),De={state:G,subscribeKey(n,e){return lt(G,n,e)},increase(n){G[n]+=1},decrease(n){G[n]-=1},reset(n){G[n]=0}};async function Ln(n){if(re.isSafeApp()){const{safe:e}=await Ve(async()=>{const{safe:t}=await import("./index-CAlJE1dj.js");return{safe:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));if(e&&!n.some(t=>t.type==="safe"))return e()}return null}async function zn(n){try{const{baseAccount:e}=await Ve(async()=>{const{baseAccount:t}=await import("./index-CAlJE1dj.js");return{baseAccount:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));if(e&&!n.some(t=>t.id==="baseAccount"))return e()}catch(e){console.error("Failed to import Coinbase Wallet SDK:",e)}return null}const Dn={enable:!1,pollingInterval:3e4};class Fn extends ht{constructor(e){const t=Z.extendCaipNetworks(e.networks,{projectId:e.projectId,customNetworkImageUrls:{},customRpcUrls:e.customRpcUrls});super(),this.balancePromises={},this.namespace=S.CHAIN.EVM,this.adapterType=S.ADAPTER_TYPES.WAGMI,this.projectId=e.projectId,this.pendingTransactionsFilter={...Dn,...e.pendingTransactionsFilter??{}},this.createConfig({...e,networks:t}),this.checkChainId()}construct(e){this.checkChainId(),this.setupWatchers()}async getAccounts(e){const t=this.getWagmiConnector(e.id);if(!t)return{accounts:[]};if(t.id===S.CONNECTOR_ID.AUTH){const u=await t.getProvider();if(!(u!=null&&u.user))return{accounts:[]};const{address:o,accounts:a,chainId:d}=u.user;return Promise.resolve({accounts:(a||[{address:o,type:"eoa"}]).map(c=>re.createAccount({caipAddress:`eip155:${d}:${c.address}`,type:c.type}))})}const{addresses:i,address:s,chainId:r}=J(this.wagmiConfig);return Promise.resolve({accounts:r?[...new Set(i||[s])].map(u=>re.createAccount({caipAddress:`eip155:${r}:${u||""}`,type:"eoa"})):[]})}checkChainId(){const{chainId:e}=J(this.wagmiConfig);e&&this.emit("switchNetwork",{chainId:e})}getWagmiConnector(e){return this.wagmiConfig.connectors.find(t=>t.id===e)}createConfig(e){this.wagmiChains=e.networks.filter(s=>s.chainNamespace===S.CHAIN.EVM);const t={},i=[...e.connectors??[]];this.wagmiChains.forEach(s=>{var o,a;const r=(o=e.transports)==null?void 0:o[s.id],u=Z.getCaipNetworkId(s);r?t[s.id]=Z.extendWagmiTransports(s,e.projectId,r):t[s.id]=Z.getViemTransport(s,e.projectId,(a=e.customRpcUrls)==null?void 0:a[u])}),this.wagmiConfig=bn({...e,chains:this.wagmiChains,connectors:i,transports:t})}setupWatchPendingTransactions(){if(!this.pendingTransactionsFilter.enable||this.unwatchPendingTransactions)return;this.unwatchPendingTransactions=nn(this.wagmiConfig,{pollingInterval:this.pendingTransactionsFilter.pollingInterval,onError:()=>{},onTransactions:()=>{this.emit("pendingTransactions"),De.increase("pendingTransactions")}});const e=De.subscribeKey("pendingTransactions",t=>{var i;t>=S.LIMITS.PENDING_TRANSACTIONS&&((i=this.unwatchPendingTransactions)==null||i.call(this),e())})}setupWatchers(){en(this.wagmiConfig,{onChange:e=>{this.clearConnections(),this.addConnection(...e.map(t=>{const i=this.getCaipNetworks().find(r=>r.id===t.chainId),s=t.connector.id===S.CONNECTOR_ID.AUTH;return{accounts:t.accounts.map(r=>({address:this.toChecksummedAddress(r)})),caipNetwork:i,connectorId:t.connector.id,auth:s?{name:B.getConnectedSocialProvider(),username:B.getConnectedSocialUsername()}:void 0}}))}}),Zt(this.wagmiConfig,{onChange:(e,t)=>{var i;if(e.status==="disconnected"&&t.address&&this.emit("disconnect"),e!=null&&e.chainId&&(e==null?void 0:e.chainId)!==(t==null?void 0:t.chainId)&&this.emit("switchNetwork",{chainId:e.chainId}),e.status==="connected"){const s=e.address!==(t==null?void 0:t.address),r=e.connector.id!==((i=t.connector)==null?void 0:i.id),u=t.status!=="connected";(s||r||u)&&(this.setupWatchPendingTransactions(),this.handleAccountChanged({address:e.address,chainId:e.chainId,connector:e.connector}))}}})}async addThirdPartyConnectors(){const e=[],{enableCoinbase:t}=F.state||{};if(t!==!1){const s=await zn(this.wagmiConfig.connectors);s&&e.push(s)}const i=await Ln(this.wagmiConfig.connectors);i&&e.push(i),await Promise.all(e.map(s=>{const r=this.configureInternalConnector(s);return this.addWagmiConnector(r)}))}addWagmiConnectors(){const e=[];F.state.enableInjected!==!1&&e.push(de({shimDisconnect:!0}));const{features:t,remoteFeatures:i,projectId:s,enableAuthLogger:r}=F.state,u=(i==null?void 0:i.email)??(t==null?void 0:t.email)??!0,o=(i==null?void 0:i.socials)??(t==null?void 0:t.socials),a=Array.isArray(o)&&(o==null?void 0:o.length)>0;(u||a)&&e.push(rt({chains:this.wagmiChains,options:{projectId:s,enableAuthLogger:r}})),e.forEach(d=>{this.configureInternalConnector(d)})}configureInternalConnector(e){const t=this.wagmiConfig._internal.connectors.setup(e);return this.wagmiConfig._internal.connectors.setState(i=>[...i,t]),t}async handleAccountChanged({address:e,chainId:t,connector:i}){if(!this.namespace)throw new Error("WagmiAdapter:handleAccountChanged - namespace is required");const s=await i.getProvider().catch(()=>{});this.emit("accountChanged",{address:this.toChecksummedAddress(e),chainId:t,connector:{id:i.id,name:O.ConnectorNamesMap[i.id]??i.name,imageId:O.ConnectorImageIds[i.id],type:O.ConnectorTypesMap[i.type]??"EXTERNAL",info:i.id===S.CONNECTOR_ID.INJECTED?void 0:{rdns:i.id},provider:s,chain:this.namespace,chains:[]}})}async writeSolanaTransaction(){return Promise.resolve({hash:""})}async signMessage(e){try{return{signature:await Xt(this.wagmiConfig,{message:e.message,account:e.address})}}catch{throw new Error("WagmiAdapter:signMessage - Sign message failed")}}async sendTransaction(e){var o;const{chainId:t,address:i}=J(this.wagmiConfig),s=(o=this.wagmiChains)==null?void 0:o.find(a=>a.id===t),r={account:i,to:e.to,value:Number.isNaN(Number(e.value))?BigInt(0):BigInt(e.value),gas:e.gas?BigInt(e.gas):void 0,gasPrice:e.gasPrice?BigInt(e.gasPrice):void 0,data:e.data,chain:s,type:"legacy",parameters:["nonce"]};await Kt(this.wagmiConfig,r);const u=await Jt(this.wagmiConfig,r);return await Yt(this.wagmiConfig,{hash:u,timeout:25e3}),{hash:u}}async writeContract(e){var o;const{caipNetwork:t,...i}=e,s=Number(be.caipNetworkIdToNumber(t.caipNetworkId)),r=(o=this.wagmiChains)==null?void 0:o.find(a=>a.id===s);return{hash:await sn(this.wagmiConfig,{chain:r,address:i.tokenAddress,account:i.fromAddress,abi:i.abi,functionName:i.method,args:i.args,__mode:"prepared"})}}async estimateGas(e){try{return{gas:await Ft(this.wagmiConfig,{account:e.address,to:e.to,data:e.data,type:"legacy"})}}catch{throw new Error("WagmiAdapter:estimateGas - error estimating gas")}}parseUnits(e){return qn(e.value,e.decimals)}formatUnits(e){return On(e.value,e.decimals)}async addWagmiConnector(e){if(!this.namespace)throw new Error("WagmiAdapter:addWagmiConnector - namespace is required");const{enableEIP6963:t}=F.state||{};if(e.type===S.CONNECTOR_ID.INJECTED&&t===!1||e.id===S.CONNECTOR_ID.AUTH||e.id===S.CONNECTOR_ID.WALLET_CONNECT)return;let i;e.id!==S.CONNECTOR_ID.BASE_ACCOUNT&&(i=await e.getProvider().catch(()=>{}));const s=ft.state.connectorImages;this.addConnector({id:e.id,explorerId:O.ConnectorExplorerIds[e.id]??O.ConnectorExplorerIds[e.name],imageUrl:(s==null?void 0:s[e.id])??e.icon,name:O.ConnectorNamesMap[e.id]??e.name,imageId:O.ConnectorImageIds[e.id],type:O.ConnectorTypesMap[e.type]??"EXTERNAL",info:e.id===S.CONNECTOR_ID.INJECTED?void 0:{rdns:e.id},provider:i,chain:this.namespace,chains:[]})}async syncConnectors(){tn(this.wagmiConfig,{onChange:e=>{e.forEach(t=>this.addWagmiConnector(t))}}),this.addWagmiConnectors(),await Promise.all(this.wagmiConfig.connectors.map(e=>this.addWagmiConnector(e))),await this.addThirdPartyConnectors()}async syncConnections(){const e=this.connectors.filter(t=>{const{hasDisconnected:i,hasConnected:s}=ee.getConnectorStorageInfo(t.id,this.namespace);return!i&&s}).map(t=>this.getWagmiConnector(t.id)).filter(Boolean);await me(this.wagmiConfig,{connectors:e})}async syncConnection(e){var d,c;const{id:t,chainId:i}=e,r=M(this.wagmiConfig).find(l=>l.connector.id===t),u=this.getWagmiConnector(t),o=await(u==null?void 0:u.getProvider());if(re.isSafeApp()&&t===S.CONNECTOR_ID.SAFE&&!(r!=null&&r.accounts.length)){const l=this.getWagmiConnector("safe");if(l){const h=await fe(this.wagmiConfig,{connector:l,chainId:Number(i)}),f=await l.getProvider();return{chainId:Number(i),address:this.toChecksummedAddress(h.accounts[0]),provider:f,type:(d=r==null?void 0:r.connector.type)==null?void 0:d.toUpperCase(),id:r==null?void 0:r.connector.id}}}return{chainId:Number(r==null?void 0:r.chainId),address:this.toChecksummedAddress(r==null?void 0:r.accounts[0]),provider:o,type:(c=r==null?void 0:r.connector.type)==null?void 0:c.toUpperCase(),id:r==null?void 0:r.connector.id}}async connectWalletConnect(e){try{const t=this.getWalletConnectConnector();await t.authenticate();const i=this.getWagmiConnector("walletConnect");if(!i)throw new Error("UniversalAdapter:connectWalletConnect - connector not found");const s=await fe(this.wagmiConfig,{connector:i,chainId:e?Number(e):void 0});return s.chainId!==Number(e)&&await Me(this.wagmiConfig,{chainId:s.chainId}),{clientId:await t.provider.client.core.crypto.getClientId()}}catch(t){throw t instanceof q?new te(t):Re.isUserRejectedRequestError(t)?new te(t):t}}async connect(e){var t,i,s,r,u;try{const{id:o,address:a,provider:d,type:c,info:l,chainId:h,socialUri:f}=e,p=this.getWagmiConnector(o);if(!p)throw new Error("connectionControllerClient:connectExternal - connector is undefined");d&&l&&p.id===S.CONNECTOR_ID.EIP6963&&((t=p.setEip6963Wallet)==null||t.call(p,{provider:d,info:l}));const m=(s=(i=this.wagmiConfig.state)==null?void 0:i.connections)==null?void 0:s.get(p.uid);if(m){await((r=this.wagmiConfig.storage)==null?void 0:r.setItem("recentConnectorId",p.id));const y=[...m.accounts].sort((N,A)=>ee.isLowerCaseMatch(N,a)?-1:ee.isLowerCaseMatch(A,a)?1:0);return(u=this.wagmiConfig)==null||u.setState(N=>({...N,connections:new Map(N.connections).set(p.uid,{accounts:y,chainId:m.chainId,connector:m.connector}),current:p.uid,status:"connected"})),{address:this.toChecksummedAddress(y[0]),chainId:m.chainId,provider:d,type:c,id:o}}const b=await fe(this.wagmiConfig,{connector:p,chainId:h?Number(h):void 0,socialUri:f}),I=d??await p.getProvider();return{address:this.toChecksummedAddress(b.accounts[0]),chainId:b.chainId,provider:I,type:c,id:o}}catch(o){throw o instanceof q?new te(o):Re.isUserRejectedRequestError(o)?new te(o):o}}get connections(){return Array.from(this.wagmiConfig.state.connections.values()).map(e=>({accounts:e.accounts.map(t=>({address:this.toChecksummedAddress(t)})),connectorId:e.connector.id}))}async reconnect(e){const{id:t}=e,i=this.getWagmiConnector(t);if(!i)throw new Error("connectionControllerClient:connectExternal - connector is undefined");await me(this.wagmiConfig,{connectors:[i]})}async getBalance(e){const t=e.address,i=this.getCaipNetworks().find(s=>s.id===e.chainId);if(!t)return Promise.resolve({balance:"0.00",symbol:"ETH"});if(i&&this.wagmiConfig){const s=`${i.caipNetworkId}:${e.address}`,r=this.balancePromises[s];if(r)return r;const u=B.getNativeBalanceCacheForCaipAddress(s);return u?{balance:u.balance,symbol:u.symbol}:(this.balancePromises[s]=new Promise(async o=>{var a,d;try{const c=Number(e.chainId),l=await Gt(this.wagmiConfig,{address:e.address,chainId:c,token:(d=(a=e.tokens)==null?void 0:a[i.caipNetworkId])==null?void 0:d.address});B.updateNativeBalanceCache({caipAddress:s,balance:l.formatted,symbol:l.symbol,timestamp:Date.now()}),o({balance:l.formatted,symbol:l.symbol})}catch(c){console.warn("Appkit:WagmiAdapter:getBalance - Error getting balance",c),o({balance:"0.00",symbol:"ETH"})}}).finally(()=>{delete this.balancePromises[s]}),this.balancePromises[s]||{balance:"0.00",symbol:"ETH"})}return{balance:"",symbol:""}}getWalletConnectProvider(){var e;return(e=this.getWagmiConnector("walletConnect"))==null?void 0:e.provider}async disconnect(e){if(e.id){const t=this.getWagmiConnector(e.id),s=M(this.wagmiConfig).find(r=>ee.isLowerCaseMatch(r.connector.id,e.id));return await Ue(this.wagmiConfig,{connector:t}),F.state.enableReconnect===!1&&this.deleteConnection(e.id),s?{connections:[{accounts:s.accounts.map(r=>({address:this.toChecksummedAddress(r)})),connectorId:s.connector.id}]}:{connections:[]}}return this.disconnectAll()}async disconnectAll(){const e=M(this.wagmiConfig),t=await Promise.allSettled(e.map(async i=>{const s=this.getWagmiConnector(i.connector.id);return s&&await Ue(this.wagmiConfig,{connector:s}),i}));return this.wagmiConfig.state.connections.clear(),{connections:t.filter(i=>i.status==="fulfilled").map(({value:i})=>({accounts:i.accounts.map(s=>({address:this.toChecksummedAddress(s)})),connectorId:i.connector.id}))}}async switchNetwork(e){var f,p,m,b,I;const{caipNetwork:t}=e,i=this.wagmiConfig.chains.find(y=>y.id.toString()===t.id.toString());if(!i)throw new Error("connectionControllerClient:switchNetwork - wagmiChain is undefined");const{name:s,nativeCurrency:r,rpcUrls:u,blockExplorers:o,id:a}=i,d=((m=(p=(f=t.rpcUrls)==null?void 0:f.chainDefault)==null?void 0:p.http)==null?void 0:m[0])??u.default.http[0]??"",c=(o==null?void 0:o.default.url)??((I=(b=t.blockExplorers)==null?void 0:b.default)==null?void 0:I.url)??"",l=r??t.nativeCurrency,h=s??t.name;await Me(this.wagmiConfig,{chainId:a,addEthereumChainParameter:{chainName:h,nativeCurrency:l,rpcUrls:[d],blockExplorerUrls:[c]}}),await super.switchNetwork(e)}async getCapabilities(e){if(!this.wagmiConfig)throw new Error("connectionControllerClient:getCapabilities - wagmiConfig is undefined");const i=M(this.wagmiConfig)[0],s=i?this.getWagmiConnector(i.connector.id):null;if(!s)throw new Error("connectionControllerClient:getCapabilities - connector is undefined");const r=await s.getProvider();if(!r)throw new Error("connectionControllerClient:getCapabilities - provider is undefined");return await r.request({method:"wallet_getCapabilities",params:[e]})}async grantPermissions(e){if(!this.wagmiConfig)throw new Error("connectionControllerClient:grantPermissions - wagmiConfig is undefined");const i=M(this.wagmiConfig)[0],s=i?this.getWagmiConnector(i.connector.id):null;if(!s)throw new Error("connectionControllerClient:grantPermissions - connector is undefined");const r=await s.getProvider();if(!r)throw new Error("connectionControllerClient:grantPermissions - provider is undefined");return r.request({method:"wallet_grantPermissions",params:e})}async revokePermissions(e){if(!this.wagmiConfig)throw new Error("connectionControllerClient:revokePermissions - wagmiConfig is undefined");const i=M(this.wagmiConfig)[0],s=i?this.getWagmiConnector(i.connector.id):null;if(!s)throw new Error("connectionControllerClient:revokePermissions - connector is undefined");const r=await s.getProvider();if(!r)throw new Error("connectionControllerClient:revokePermissions - provider is undefined");return r.request({method:"wallet_revokePermissions",params:e})}async walletGetAssets(e){if(!this.wagmiConfig)throw new Error("connectionControllerClient:walletGetAssets - wagmiConfig is undefined");const i=M(this.wagmiConfig)[0],s=i?this.getWagmiConnector(i.connector.id):null;if(!s)throw new Error("connectionControllerClient:walletGetAssets - connector is undefined");const r=await s.getProvider();if(!r)throw new Error("connectionControllerClient:walletGetAssets - provider is undefined");return r.request({method:"wallet_getAssets",params:[e]})}setAuthProvider(e){if(!this.namespace)throw new Error("WagmiAdapter:setAuthProvider - namespace is required");this.addConnector({id:S.CONNECTOR_ID.AUTH,type:"AUTH",name:S.CONNECTOR_NAMES.AUTH,provider:e,imageId:O.ConnectorImageIds[S.CONNECTOR_ID.AUTH],chain:this.namespace,chains:[]})}async setUniversalProvider(e){e.on("connect",()=>{const i=M(this.wagmiConfig),s=this.getWagmiConnector("walletConnect");if(s&&!i.find(r=>r.connector.id===s.id)){if(P.state.activeChain==="eip155")return;me(this.wagmiConfig,{connectors:[s]})}});const t=Pe({universalProvider:e});return this.configureInternalConnector(t),this.addConnector(new gt({provider:e,caipNetworks:this.getCaipNetworks(),namespace:"eip155"})),Promise.resolve()}toChecksummedAddress(e){return Se(e.toLowerCase())}}const ei=Object.freeze(Object.defineProperty({__proto__:null,WagmiAdapter:Fn,authConnector:rt},Symbol.toStringTag,{value:"Module"}));export{X as C,W as P,ei as a,Zn as c,de as i,Mt as w};
@@ -1 +1 @@
1
- import{B as M}from"./ui-BjvItYqm.js";import{B as Tt,m as Mt,K as ot,o as J,q as Bt,Y as F,P as $t,F as B,V as R,r as z,t as At,u as Lt}from"./wallets-DEM4N7hD.js";import"./index-BwkHDX6G.js";import{b as Jt,o as g,c as Et}from"./index-BuplIhvx.js";import{f as P}from"./index.es-D2xtIl02.js";import{N as zt}from"./index-BqHNs9qE.js";import"./vendor-CwdbX2q9.js";import"./thirdweb-DaGoGHaJ.js";import"./in-app-BLyWvKUh.js";import"./linkAccount-B5qtCVO2.js";import"./store-CraP4F4Y.js";import"./index-nibyPLVP.js";import"./index-Bhc069C3.js";import"./ethereum-AGK2C1RS.js";import"./types-DC0Zmj1B.js";import"./browser-ponyfill-CqE0UlVr.js";const ct="error",Gt="wss://relay.walletconnect.org",Vt="wc",Kt="universal_provider",x=`${Vt}@2:${Kt}:`,St="https://rpc.walletconnect.org/v1/",qt="generic",Wt=`${St}bundler`,_="call_status",Yt=86400,v={DEFAULT_CHAIN_CHANGED:"default_chain_changed"};function it(i){return i==null||typeof i!="object"&&typeof i!="function"}function Nt(i){return Object.getOwnPropertySymbols(i).filter(t=>Object.prototype.propertyIsEnumerable.call(i,t))}function Dt(i){return i==null?i===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(i)}const Qt="[object RegExp]",_t="[object String]",Ft="[object Number]",Rt="[object Boolean]",xt="[object Arguments]",Xt="[object Symbol]",Zt="[object Date]",te="[object Map]",ee="[object Set]",ie="[object Array]",se="[object ArrayBuffer]",re="[object Object]",ne="[object DataView]",ae="[object Uint8Array]",oe="[object Uint8ClampedArray]",ce="[object Uint16Array]",he="[object Uint32Array]",pe="[object Int8Array]",ue="[object Int16Array]",le="[object Int32Array]",de="[object Float32Array]",fe="[object Float64Array]";function st(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function me(i,t){return D(i,void 0,i,new Map,t)}function D(i,t,e,s=new Map,n=void 0){const a=n==null?void 0:n(i,t,e,s);if(a!=null)return a;if(it(i))return i;if(s.has(i))return s.get(i);if(Array.isArray(i)){const r=new Array(i.length);s.set(i,r);for(let o=0;o<i.length;o++)r[o]=D(i[o],o,e,s,n);return Object.hasOwn(i,"index")&&(r.index=i.index),Object.hasOwn(i,"input")&&(r.input=i.input),r}if(i instanceof Date)return new Date(i.getTime());if(i instanceof RegExp){const r=new RegExp(i.source,i.flags);return r.lastIndex=i.lastIndex,r}if(i instanceof Map){const r=new Map;s.set(i,r);for(const[o,c]of i)r.set(o,D(c,o,e,s,n));return r}if(i instanceof Set){const r=new Set;s.set(i,r);for(const o of i)r.add(D(o,void 0,e,s,n));return r}if(typeof M<"u"&&M.isBuffer(i))return i.subarray();if(st(i)){const r=new(Object.getPrototypeOf(i)).constructor(i.length);s.set(i,r);for(let o=0;o<i.length;o++)r[o]=D(i[o],o,e,s,n);return r}if(i instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&i instanceof SharedArrayBuffer)return i.slice(0);if(i instanceof DataView){const r=new DataView(i.buffer.slice(0),i.byteOffset,i.byteLength);return s.set(i,r),y(r,i,e,s,n),r}if(typeof File<"u"&&i instanceof File){const r=new File([i],i.name,{type:i.type});return s.set(i,r),y(r,i,e,s,n),r}if(i instanceof Blob){const r=new Blob([i],{type:i.type});return s.set(i,r),y(r,i,e,s,n),r}if(i instanceof Error){const r=new i.constructor;return s.set(i,r),r.message=i.message,r.name=i.name,r.stack=i.stack,r.cause=i.cause,y(r,i,e,s,n),r}if(typeof i=="object"&&ve(i)){const r=Object.create(Object.getPrototypeOf(i));return s.set(i,r),y(r,i,e,s,n),r}return i}function y(i,t,e=i,s,n){const a=[...Object.keys(t),...Nt(t)];for(let r=0;r<a.length;r++){const o=a[r],c=Object.getOwnPropertyDescriptor(i,o);(c==null||c.writable)&&(i[o]=D(t[o],o,e,s,n))}}function ve(i){switch(Dt(i)){case xt:case ie:case se:case ne:case Rt:case Zt:case de:case fe:case pe:case ue:case le:case te:case Ft:case re:case Qt:case ee:case _t:case Xt:case ae:case oe:case ce:case he:return!0;default:return!1}}function ge(i,t){return me(i,(e,s,n,a)=>{if(typeof i=="object")switch(Object.prototype.toString.call(i)){case Ft:case _t:case Rt:{const r=new i.constructor(i==null?void 0:i.valueOf());return y(r,i),r}case xt:{const r={};return y(r,i),r.length=i.length,r[Symbol.iterator]=i[Symbol.iterator],r}default:return}})}function ht(i){return ge(i)}function pt(i){return i!==null&&typeof i=="object"&&Dt(i)==="[object Arguments]"}function ut(i){return typeof i=="object"&&i!==null}function Pe(){}function we(i){return st(i)}function be(i){var e;if(typeof i!="object"||i==null)return!1;if(Object.getPrototypeOf(i)===null)return!0;if(Object.prototype.toString.call(i)!=="[object Object]"){const s=i[Symbol.toStringTag];return s==null||!((e=Object.getOwnPropertyDescriptor(i,Symbol.toStringTag))!=null&&e.writable)?!1:i.toString()===`[object ${s}]`}let t=i;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(i)===t}function ye(i){if(it(i))return i;if(Array.isArray(i)||st(i)||i instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&i instanceof SharedArrayBuffer)return i.slice(0);const t=Object.getPrototypeOf(i),e=t.constructor;if(i instanceof Date||i instanceof Map||i instanceof Set)return new e(i);if(i instanceof RegExp){const s=new e(i);return s.lastIndex=i.lastIndex,s}if(i instanceof DataView)return new e(i.buffer.slice(0));if(i instanceof Error){const s=new e(i.message);return s.stack=i.stack,s.name=i.name,s.cause=i.cause,s}if(typeof File<"u"&&i instanceof File)return new e([i],i.name,{type:i.type,lastModified:i.lastModified});if(typeof i=="object"){const s=Object.create(t);return Object.assign(s,i)}return i}function Ce(i,...t){const e=t.slice(0,-1),s=t[t.length-1];let n=i;for(let a=0;a<e.length;a++){const r=e[a];n=Z(n,r,s,new Map)}return n}function Z(i,t,e,s){if(it(i)&&(i=Object(i)),t==null||typeof t!="object")return i;if(s.has(t))return ye(s.get(t));if(s.set(t,i),Array.isArray(t)){t=t.slice();for(let a=0;a<t.length;a++)t[a]=t[a]??void 0}const n=[...Object.keys(t),...Nt(t)];for(let a=0;a<n.length;a++){const r=n[a];let o=t[r],c=i[r];if(pt(o)&&(o={...o}),pt(c)&&(c={...c}),typeof M<"u"&&M.isBuffer(o)&&(o=ht(o)),Array.isArray(o))if(typeof c=="object"&&c!=null){const l=[],h=Reflect.ownKeys(c);for(let w=0;w<h.length;w++){const d=h[w];l[d]=c[d]}c=l}else c=[];const u=e(c,o,r,i,t,s);u!=null?i[r]=u:Array.isArray(o)||ut(c)&&ut(o)?i[r]=Z(c,o,e,s):c==null&&be(o)?i[r]=Z({},o,e,s):c==null&&we(o)?i[r]=ht(o):(c===void 0||o!==void 0)&&(i[r]=o)}return i}function Ie(i,...t){return Ce(i,...t,Pe)}var Oe=Object.defineProperty,je=Object.defineProperties,He=Object.getOwnPropertyDescriptors,lt=Object.getOwnPropertySymbols,$e=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable,dt=(i,t,e)=>t in i?Oe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,U=(i,t)=>{for(var e in t||(t={}))$e.call(t,e)&&dt(i,e,t[e]);if(lt)for(var e of lt(t))Ae.call(t,e)&&dt(i,e,t[e]);return i},Ee=(i,t)=>je(i,He(t));function f(i,t,e){var s;const n=B(i);return((s=t.rpcMap)==null?void 0:s[n.reference])||`${St}?chainId=${n.namespace}:${n.reference}&projectId=${e}`}function C(i){return i.includes(":")?i.split(":")[1]:i}function Ut(i){return i.map(t=>`${t.split(":")[0]}:${t.split(":")[1]}`)}function Se(i,t){const e=Object.keys(t.namespaces).filter(n=>n.includes(i));if(!e.length)return[];const s=[];return e.forEach(n=>{const a=t.namespaces[n].accounts;s.push(...a)}),s}function ft(i){return Object.fromEntries(Object.entries(i).filter(([t,e])=>{var s,n;return((s=e==null?void 0:e.chains)==null?void 0:s.length)&&((n=e==null?void 0:e.chains)==null?void 0:n.length)>0}))}function k(i={},t={}){const e=ft(mt(i)),s=ft(mt(t));return Ie(e,s)}function mt(i){var t,e,s,n,a;const r={};if(!R(i))return r;for(const[o,c]of Object.entries(i)){const u=$t(o)?[o]:c.chains,l=c.methods||[],h=c.events||[],w=c.rpcMap||{},d=F(o);r[d]=Ee(U(U({},r[d]),c),{chains:z(u,(t=r[d])==null?void 0:t.chains),methods:z(l,(e=r[d])==null?void 0:e.methods),events:z(h,(s=r[d])==null?void 0:s.events)}),(R(w)||R(((n=r[d])==null?void 0:n.rpcMap)||{}))&&(r[d].rpcMap=U(U({},w),(a=r[d])==null?void 0:a.rpcMap))}return r}function vt(i){return i.includes(":")?i.split(":")[2]:i}function gt(i){const t={};for(const[e,s]of Object.entries(i)){const n=s.methods||[],a=s.events||[],r=s.accounts||[],o=$t(e)?[e]:s.chains?s.chains:Ut(s.accounts);t[e]={chains:o,methods:n,events:a,accounts:r}}return t}function G(i){return typeof i=="number"?i:i.includes("0x")?parseInt(i,16):(i=i.includes(":")?i.split(":")[1]:i,isNaN(Number(i))?i:Number(i))}function qe(i){try{const t=JSON.parse(i);return typeof t=="object"&&t!==null&&!Array.isArray(t)}catch{return!1}}const kt={},p=i=>kt[i],V=(i,t)=>{kt[i]=t};var Ne=Object.defineProperty,Pt=Object.getOwnPropertySymbols,De=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable,wt=(i,t,e)=>t in i?Ne(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,bt=(i,t)=>{for(var e in t||(t={}))De.call(t,e)&&wt(i,e,t[e]);if(Pt)for(var e of Pt(t))_e.call(t,e)&&wt(i,e,t[e]);return i};const yt="eip155",Fe=["atomic","flow-control","paymasterService","sessionKeys","auxiliaryFunds"],Re=i=>i&&i.startsWith("0x")?BigInt(i).toString(10):i,K=i=>i&&i.startsWith("0x")?i:`0x${BigInt(i).toString(16)}`,Ct=i=>Object.keys(i).filter(t=>Fe.includes(t)).reduce((t,e)=>(t[e]=xe(i[e]),t),{}),xe=i=>typeof i=="string"&&qe(i)?JSON.parse(i):i,Ue=(i,t,e)=>{const{sessionProperties:s={},scopedProperties:n={}}=i,a={};if(!R(n)&&!R(s))return;const r=Ct(s);for(const o of e){const c=Re(o);if(!c)continue;a[K(c)]=r;const u=n==null?void 0:n[`${yt}:${c}`];if(u){const l=u==null?void 0:u[`${yt}:${c}:${t}`];a[K(c)]=bt(bt({},a[K(c)]),Ct(l||u))}}for(const[o,c]of Object.entries(a))Object.keys(c).length===0&&delete a[o];return Object.keys(a).length>0?a:void 0};var ke=Object.defineProperty,Te=(i,t,e)=>t in i?ke(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Me=(i,t,e)=>Te(i,t+"",e);let W;class rt{constructor(t){Me(this,"storage"),this.storage=t}async getItem(t){return await this.storage.getItem(t)}async setItem(t,e){return await this.storage.setItem(t,e)}async removeItem(t){return await this.storage.removeItem(t)}static getStorage(t){return W||(W=new rt(t)),W}}var Be=Object.defineProperty,Le=Object.defineProperties,Je=Object.getOwnPropertyDescriptors,It=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable,Ot=(i,t,e)=>t in i?Be(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Ve=(i,t)=>{for(var e in t||(t={}))ze.call(t,e)&&Ot(i,e,t[e]);if(It)for(var e of It(t))Ge.call(t,e)&&Ot(i,e,t[e]);return i},Ke=(i,t)=>Le(i,Je(t));async function We(i,t){const e=B(i.result.capabilities.caip345.caip2),s=i.result.capabilities.caip345.transactionHashes,n=await Promise.allSettled(s.map(h=>Ye(e.reference,h,t))),a=n.filter(h=>h.status==="fulfilled").map(h=>h.value).filter(h=>h);n.filter(h=>h.status==="rejected").forEach(h=>console.warn("Failed to fetch transaction receipt:",h.reason));const r=!a.length||a.some(h=>!h),o=a.every(h=>(h==null?void 0:h.status)==="0x1"),c=a.every(h=>(h==null?void 0:h.status)==="0x0"),u=a.some(h=>(h==null?void 0:h.status)==="0x0");let l;return r?l=100:o?l=200:c?l=500:u&&(l=600),{id:i.result.id,version:i.request.version,atomic:i.request.atomicRequired,chainId:i.request.chainId,capabilities:i.result.capabilities,receipts:a,status:l}}async function Ye(i,t,e){return await e(parseInt(i)).request(Et("eth_getTransactionReceipt",[t]))}async function Qe({sendCalls:i,storage:t}){const e=await t.getItem(_);await t.setItem(_,Ke(Ve({},e),{[i.result.id]:{request:i.request,result:i.result,expiry:Lt(Yt)}}))}async function Xe({resultId:i,storage:t}){const e=await t.getItem(_);if(e){delete e[i],await t.setItem(_,e);for(const s in e)At(e[s].expiry)&&delete e[s];await t.setItem(_,e)}}async function Ze({resultId:i,storage:t}){const e=await t.getItem(_),s=e==null?void 0:e[i];if(s&&!At(s.expiry))return s;await Xe({resultId:i,storage:t})}var ti=Object.defineProperty,ei=(i,t,e)=>t in i?ti(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,I=(i,t,e)=>ei(i,typeof t!="symbol"?t+"":t,e);class ii{constructor(t){I(this,"name","polkadot"),I(this,"client"),I(this,"httpProviders"),I(this,"events"),I(this,"namespace"),I(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${t}`)}getAccounts(){const t=this.namespace.accounts;return t?t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2])||[]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var si=Object.defineProperty,ri=Object.defineProperties,ni=Object.getOwnPropertyDescriptors,jt=Object.getOwnPropertySymbols,ai=Object.prototype.hasOwnProperty,oi=Object.prototype.propertyIsEnumerable,tt=(i,t,e)=>t in i?si(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Y=(i,t)=>{for(var e in t||(t={}))ai.call(t,e)&&tt(i,e,t[e]);if(jt)for(var e of jt(t))oi.call(t,e)&&tt(i,e,t[e]);return i},Q=(i,t)=>ri(i,ni(t)),b=(i,t,e)=>tt(i,typeof t!="symbol"?t+"":t,e);class ci{constructor(t){b(this,"name","eip155"),b(this,"client"),b(this,"chainId"),b(this,"namespace"),b(this,"httpProviders"),b(this,"events"),b(this,"storage"),this.namespace=t.namespace,this.events=p("events"),this.client=p("client"),this.httpProviders=this.createHttpProviders(),this.chainId=parseInt(this.getDefaultChain()),this.storage=rt.getStorage(this.client.core.storage)}async request(t){switch(t.request.method){case"eth_requestAccounts":return this.getAccounts();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);case"wallet_sendCalls":return await this.sendCalls(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(v.DEFAULT_CHAIN_CHANGED,`${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||f(`${this.name}:${t}`,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("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 n=parseInt(C(e));t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?void 0:s[e])}),t}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}getHttpProvider(t){const e=t||this.chainId;return this.httpProviders[e]||(this.httpProviders=Q(Y({},this.httpProviders),{[e]:this.createHttpProvider(e)}),this.httpProviders[e])}async handleSwitchChain(t){var e,s;let n=t.request.params?(e=t.request.params[0])==null?void 0:e.chainId:"0x0";n=n.startsWith("0x")?n:`0x${n}`;const a=parseInt(n,16);if(this.isChainApproved(a))this.setDefaultChain(`${a}`);else if(this.namespace.methods.includes("wallet_switchEthereumChain"))await this.client.request({topic:t.topic,request:{method:t.request.method,params:[{chainId:n}]},chainId:(s=this.namespace.chains)==null?void 0:s[0]}),this.setDefaultChain(`${a}`);else throw new Error(`Failed to switch to chain 'eip155:${a}'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method.`);return null}isChainApproved(t){return this.namespace.chains.includes(`${this.name}:${t}`)}async getCapabilities(t){var e,s,n,a,r;const o=(s=(e=t.request)==null?void 0:e.params)==null?void 0:s[0],c=((a=(n=t.request)==null?void 0:n.params)==null?void 0:a[1])||[];if(!o)throw new Error("Missing address parameter in `wallet_getCapabilities` request");const u=this.client.session.get(t.topic),l=((r=u==null?void 0:u.sessionProperties)==null?void 0:r.capabilities)||{},h=`${o}${c.join(",")}`,w=l==null?void 0:l[h];if(w)return w;let d;try{d=Ue(u,o,c)}catch(L){console.warn("Failed to extract capabilities from session",L)}if(d)return d;const at=await this.client.request(t);try{await this.client.session.update(t.topic,{sessionProperties:Q(Y({},u.sessionProperties||{}),{capabilities:Q(Y({},l||{}),{[h]:at})})})}catch(L){console.warn("Failed to update session with capabilities",L)}return at}async getCallStatus(t){var e,s,n;const a=this.client.session.get(t.topic),r=(e=a.sessionProperties)==null?void 0:e.bundler_name;if(r){const u=this.getBundlerUrl(t.chainId,r);try{return await this.getUserOperationReceipt(u,t)}catch(l){console.warn("Failed to fetch call status from bundler",l,u)}}const o=(s=a.sessionProperties)==null?void 0:s.bundler_url;if(o)try{return await this.getUserOperationReceipt(o,t)}catch(u){console.warn("Failed to fetch call status from custom bundler",u,o)}const c=await Ze({resultId:(n=t.request.params)==null?void 0:n[0],storage:this.storage});if(c)try{return await We(c,this.getHttpProvider.bind(this))}catch(u){console.warn("Failed to fetch call status from stored send calls",u,c)}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 n=new URL(t),a=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Et("eth_getUserOperationReceipt",[(s=e.request.params)==null?void 0:s[0]]))});if(!a.ok)throw new Error(`Failed to fetch user operation receipt - ${a.status}`);return await a.json()}getBundlerUrl(t,e){return`${Wt}?projectId=${this.client.core.projectId}&chainId=${t}&bundler=${e}`}async sendCalls(t){var e,s,n;const a=await this.client.request(t),r=(e=t.request.params)==null?void 0:e[0],o=a==null?void 0:a.id,c=(a==null?void 0:a.capabilities)||{},u=(s=c==null?void 0:c.caip345)==null?void 0:s.caip2,l=(n=c==null?void 0:c.caip345)==null?void 0:n.transactionHashes;return!o||!u||!(l!=null&&l.length)||await Qe({sendCalls:{request:r,result:a},storage:this.storage}),a}}var hi=Object.defineProperty,pi=(i,t,e)=>t in i?hi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,O=(i,t,e)=>pi(i,typeof t!="symbol"?t+"":t,e);class ui{constructor(t){O(this,"name","solana"),O(this,"client"),O(this,"httpProviders"),O(this,"events"),O(this,"namespace"),O(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${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(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var li=Object.defineProperty,di=(i,t,e)=>t in i?li(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,j=(i,t,e)=>di(i,typeof t!="symbol"?t+"":t,e);class fi{constructor(t){j(this,"name","cosmos"),j(this,"client"),j(this,"httpProviders"),j(this,"events"),j(this,"namespace"),j(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var mi=Object.defineProperty,vi=(i,t,e)=>t in i?mi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,H=(i,t,e)=>vi(i,typeof t!="symbol"?t+"":t,e);class gi{constructor(t){H(this,"name","algorand"),H(this,"client"),H(this,"httpProviders"),H(this,"events"),H(this,"namespace"),H(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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||f(`${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(v.DEFAULT_CHAIN_CHANGED,`${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(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;t[e]=this.createHttpProvider(e,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);return typeof s>"u"?void 0:new g(new P(s,p("disableProviderPing")))}}var Pi=Object.defineProperty,wi=(i,t,e)=>t in i?Pi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,$=(i,t,e)=>wi(i,typeof t!="symbol"?t+"":t,e);class bi{constructor(t){$(this,"name","cip34"),$(this,"client"),$(this,"httpProviders"),$(this,"events"),$(this,"namespace"),$(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{const s=this.getCardanoRPCUrl(e),n=C(e);t[n]=this.createHttpProvider(n,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 g(new P(s,p("disableProviderPing")))}}var yi=Object.defineProperty,Ci=(i,t,e)=>t in i?yi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,A=(i,t,e)=>Ci(i,typeof t!="symbol"?t+"":t,e);class Ii{constructor(t){A(this,"name","elrond"),A(this,"client"),A(this,"httpProviders"),A(this,"events"),A(this,"namespace"),A(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${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(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var Oi=Object.defineProperty,ji=(i,t,e)=>t in i?Oi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,E=(i,t,e)=>ji(i,typeof t!="symbol"?t+"":t,e);class Hi{constructor(t){E(this,"name","multiversx"),E(this,"client"),E(this,"httpProviders"),E(this,"events"),E(this,"namespace"),E(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${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(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var $i=Object.defineProperty,Ai=(i,t,e)=>t in i?$i(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,S=(i,t,e)=>Ai(i,typeof t!="symbol"?t+"":t,e);class Ei{constructor(t){S(this,"name","near"),S(this,"client"),S(this,"httpProviders"),S(this,"events"),S(this,"namespace"),S(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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||f(`${this.name}:${t}`,this.namespace);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);this.setHttpProvider(t,s)}this.events.emit(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2])||[]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;t[e]=this.createHttpProvider(e,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace);return typeof s>"u"?void 0:new g(new P(s,p("disableProviderPing")))}}var Si=Object.defineProperty,qi=(i,t,e)=>t in i?Si(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,q=(i,t,e)=>qi(i,typeof t!="symbol"?t+"":t,e);class Ni{constructor(t){q(this,"name","tezos"),q(this,"client"),q(this,"httpProviders"),q(this,"events"),q(this,"namespace"),q(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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||f(`${this.name}:${t}`,this.namespace);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);this.setHttpProvider(t,s)}this.events.emit(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.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||f(t,this.namespace);return typeof s>"u"?void 0:new g(new P(s))}}var Di=Object.defineProperty,_i=(i,t,e)=>t in i?Di(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,N=(i,t,e)=>_i(i,typeof t!="symbol"?t+"":t,e);class Fi{constructor(t){N(this,"name",qt),N(this,"client"),N(this,"httpProviders"),N(this,"events"),N(this,"namespace"),N(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("client"),this.chainId=this.getDefaultChain(),this.name=this.getNamespaceName(),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(v.DEFAULT_CHAIN_CHANGED,`${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]}getNamespaceName(){const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return B(t).namespace}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){var t,e;const s={};return(e=(t=this.namespace)==null?void 0:t.accounts)==null||e.forEach(n=>{const a=B(n);s[a.reference]=this.createHttpProvider(n)}),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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var Ri=Object.defineProperty,xi=Object.defineProperties,Ui=Object.getOwnPropertyDescriptors,Ht=Object.getOwnPropertySymbols,ki=Object.prototype.hasOwnProperty,Ti=Object.prototype.propertyIsEnumerable,et=(i,t,e)=>t in i?Ri(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,T=(i,t)=>{for(var e in t||(t={}))ki.call(t,e)&&et(i,e,t[e]);if(Ht)for(var e of Ht(t))Ti.call(t,e)&&et(i,e,t[e]);return i},X=(i,t)=>xi(i,Ui(t)),m=(i,t,e)=>et(i,typeof t!="symbol"?t+"":t,e);class nt{constructor(t){m(this,"client"),m(this,"namespaces"),m(this,"optionalNamespaces"),m(this,"sessionProperties"),m(this,"scopedProperties"),m(this,"events",new zt),m(this,"rpcProviders",{}),m(this,"session"),m(this,"providerOpts"),m(this,"logger"),m(this,"uri"),m(this,"disableProviderPing",!1),this.providerOpts=t,this.logger=typeof(t==null?void 0:t.logger)<"u"&&typeof(t==null?void 0:t.logger)!="string"?t.logger:Tt(Mt({level:(t==null?void 0:t.logger)||ct})),this.disableProviderPing=(t==null?void 0:t.disableProviderPing)||!1}static async init(t){const e=new nt(t);return await e.initialize(),e}async request(t,e,s){const[n,a]=this.validateChain(e);if(!this.session)throw new Error("Please call connect() before request()");return await this.getProvider(n).request({request:T({},t),chainId:`${n}:${a}`,topic:this.session.topic,expiry:s})}sendAsync(t,e,s,n){const a=new Date().getTime();this.request(t,s,n).then(r=>e(null,Jt(a,r))).catch(r=>e(r,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,scopedProperties:this.scopedProperties}),await this.requestAccounts()}async disconnect(){var t;if(!this.session)throw new Error("Please call connect() before enable()");await this.client.disconnect({topic:(t=this.session)==null?void 0:t.topic,reason:ot("USER_DISCONNECTED")}),await this.cleanup()}async connect(t){if(!this.client)throw new Error("Sign Client not initialized");if(this.setNamespaces(t),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:n}=await this.client.authenticate(t,e);s&&(this.uri=s,this.events.emit("display_uri",s));const a=await n();if(this.session=a.session,this.session){const r=gt(this.session.namespaces);this.namespaces=k(this.namespaces,r),await this.persist("namespaces",this.namespaces),this.onConnect()}return a}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){const{uri:e,approval:s}=await this.client.connect({pairingTopic:t,requiredNamespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties,scopedProperties:this.scopedProperties});e&&(this.uri=e,this.events.emit("display_uri",e));const n=await s();this.session=n;const a=gt(n.namespaces);return this.namespaces=k(this.namespaces,a),await this.persist("namespaces",this.namespaces),await this.persist("optionalNamespaces",this.optionalNamespaces),this.onConnect(),this.session}setDefaultChain(t,e){try{if(!this.session)return;const[s,n]=this.validateChain(t);this.getProvider(s).setDefaultChain(n,e)}catch(s){if(!/Please call connect/.test(s.message))throw s}}async cleanupPendingPairings(t={}){try{this.logger.info("Cleaning up inactive pairings...");const e=this.client.pairing.getAll();if(!J(e))return;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}`)}catch(e){this.logger.warn("Failed to cleanup pending pairings",e)}}abortPairingAttempt(){this.logger.warn("abortPairingAttempt is deprecated. This is now a no-op.")}async checkStorage(){this.namespaces=await this.getFromStore("namespaces")||{},this.optionalNamespaces=await this.getFromStore("optionalNamespaces")||{},this.session&&this.createProviders()}async initialize(){this.logger.trace("Initialized"),await this.createClient(),await this.checkStorage(),this.registerEventListeners()}async createClient(){var t,e;if(this.client=this.providerOpts.client||await Bt.init({core:this.providerOpts.core,logger:this.providerOpts.logger||ct,relayUrl:this.providerOpts.relayUrl||Gt,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.providerOpts.session)try{this.session=this.client.session.get(this.providerOpts.session.topic)}catch(s){throw this.logger.error("Failed to get session",s),new Error(`The provided session: ${(e=(t=this.providerOpts)==null?void 0:t.session)==null?void 0:e.topic} doesn't exist in the Sign client`)}else{const s=this.client.session.getAll();this.session=s[0]}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(e=>F(e)))];V("client",this.client),V("events",this.events),V("disableProviderPing",this.disableProviderPing),t.forEach(e=>{if(!this.session)return;const s=Se(e,this.session);if((s==null?void 0:s.length)===0)return;const n=Ut(s),a=k(this.namespaces,this.optionalNamespaces),r=X(T({},a[e]),{accounts:s,chains:n});switch(e){case"eip155":this.rpcProviders[e]=new ci({namespace:r});break;case"algorand":this.rpcProviders[e]=new gi({namespace:r});break;case"solana":this.rpcProviders[e]=new ui({namespace:r});break;case"cosmos":this.rpcProviders[e]=new fi({namespace:r});break;case"polkadot":this.rpcProviders[e]=new ii({namespace:r});break;case"cip34":this.rpcProviders[e]=new bi({namespace:r});break;case"elrond":this.rpcProviders[e]=new Ii({namespace:r});break;case"multiversx":this.rpcProviders[e]=new Hi({namespace:r});break;case"near":this.rpcProviders[e]=new Ei({namespace:r});break;case"tezos":this.rpcProviders[e]=new Ni({namespace:r});break;default:this.rpcProviders[e]=new Fi({namespace:r})}})}registerEventListeners(){if(typeof this.client>"u")throw new Error("Sign Client is not initialized");this.client.on("session_ping",t=>{var e;const{topic:s}=t;s===((e=this.session)==null?void 0:e.topic)&&this.events.emit("session_ping",t)}),this.client.on("session_event",t=>{var e;const{params:s,topic:n}=t;if(n!==((e=this.session)==null?void 0:e.topic))return;const{event:a}=s;if(a.name==="accountsChanged"){const r=a.data;r&&J(r)&&this.events.emit("accountsChanged",r.map(vt))}else if(a.name==="chainChanged"){const r=s.chainId,o=s.event.data,c=F(r),u=G(r)!==G(o)?`${c}:${G(o)}`:r;this.onChainChanged(u)}else this.events.emit(a.name,a.data);this.events.emit("session_event",t)}),this.client.on("session_update",({topic:t,params:e})=>{var s,n;if(t!==((s=this.session)==null?void 0:s.topic))return;const{namespaces:a}=e,r=(n=this.client)==null?void 0:n.session.get(t);this.session=X(T({},r),{namespaces:a}),this.onSessionUpdate(),this.events.emit("session_update",{topic:t,params:e})}),this.client.on("session_delete",async t=>{var e;t.topic===((e=this.session)==null?void 0:e.topic)&&(await this.cleanup(),this.events.emit("session_delete",t),this.events.emit("disconnect",X(T({},ot("USER_DISCONNECTED")),{data:t.topic})))}),this.on(v.DEFAULT_CHAIN_CHANGED,t=>{this.onChainChanged(t,!0)})}getProvider(t){return this.rpcProviders[t]||this.rpcProviders[qt]}onSessionUpdate(){Object.keys(this.rpcProviders).forEach(t=>{var e;this.getProvider(t).updateNamespace((e=this.session)==null?void 0:e.namespaces[t])})}setNamespaces(t){const{namespaces:e={},optionalNamespaces:s={},sessionProperties:n,scopedProperties:a}=t;this.optionalNamespaces=k(e,s),this.sessionProperties=n,this.scopedProperties=a}validateChain(t){const[e,s]=(t==null?void 0:t.split(":"))||["",""];if(!this.namespaces||!Object.keys(this.namespaces).length)return[e,s];if(e&&!Object.keys(this.namespaces||{}).map(r=>F(r)).includes(e))throw new Error(`Namespace '${e}' is not configured. Please call connect() first with namespace config.`);if(e&&s)return[e,s];const n=F(Object.keys(this.namespaces)[0]),a=this.rpcProviders[n].getDefaultChain();return[n,a]}async requestAccounts(){const[t]=this.validateChain();return await this.getProvider(t).requestAccounts()}async onChainChanged(t,e=!1){if(!this.namespaces)return;const[s,n]=this.validateChain(t);if(!n)return;this.updateNamespaceChain(s,n);const a=this.getProvider(s).getDefaultChain();e?(this.events.emit("chainChanged",n),this.emitAccountsChangedOnChainChange({namespace:s,previousChainId:a,newChainId:t})):this.getProvider(s).setDefaultChain(n),await this.persist("namespaces",this.namespaces)}emitAccountsChangedOnChainChange({namespace:t,previousChainId:e,newChainId:s}){var n,a;try{if(e===s)return;const r=(a=(n=this.session)==null?void 0:n.namespaces[t])==null?void 0:a.accounts;if(!r)return;const o=r.filter(c=>c.includes(`${s}:`)).map(vt);if(!J(o))return;this.events.emit("accountsChanged",o)}catch(r){this.logger.warn("Failed to emit accountsChanged on chain change",r)}}updateNamespaceChain(t,e){if(!this.namespaces)return;const s=this.namespaces[t]?t:`${t}:${e}`,n={chains:[],methods:[],events:[],defaultChain:e};this.namespaces[s]?this.namespaces[s]&&(this.namespaces[s].defaultChain=e):this.namespaces[s]=n}onConnect(){this.createProviders(),this.events.emit("connect",{session:this.session})}async cleanup(){this.namespaces=void 0,this.optionalNamespaces=void 0,this.sessionProperties=void 0,await this.deleteFromStore("namespaces"),await this.deleteFromStore("optionalNamespaces"),await this.deleteFromStore("sessionProperties"),this.session=void 0,this.cleanupPendingPairings({deletePairings:!0}),await this.cleanupStorage()}async persist(t,e){var s;const n=((s=this.session)==null?void 0:s.topic)||"";await this.client.core.storage.setItem(`${x}/${t}${n}`,e)}async getFromStore(t){var e;const s=((e=this.session)==null?void 0:e.topic)||"";return await this.client.core.storage.getItem(`${x}/${t}${s}`)}async deleteFromStore(t){var e;const s=((e=this.session)==null?void 0:e.topic)||"";await this.client.core.storage.removeItem(`${x}/${t}${s}`)}async cleanupStorage(){var t;try{if(((t=this.client)==null?void 0:t.session.length)>0)return;const e=await this.client.core.storage.getKeys();for(const s of e)s.startsWith(x)&&await this.client.core.storage.removeItem(s)}catch(e){this.logger.warn("Failed to cleanup storage",e)}}}const ss=nt;export{ss as UniversalProvider,nt as default};
1
+ import{B as M}from"./ui-D3rNG5Q7.js";import{B as Tt,m as Mt,K as ot,o as J,q as Bt,Y as F,P as $t,F as B,V as R,r as z,t as At,u as Lt}from"./wallets-BhWOoOxj.js";import"./index-oiDSpXvo.js";import{b as Jt,o as g,c as Et}from"./index-Ckxei1Mz.js";import{f as P}from"./index.es-sCbnotK4.js";import{N as zt}from"./index-DNXa2sg0.js";import"./vendor-BwjdGo6X.js";import"./thirdweb-DCTNjMNu.js";import"./in-app-BDRqXNf4.js";import"./linkAccount-B8uktXqT.js";import"./store-CraP4F4Y.js";import"./index-nibyPLVP.js";import"./index-BLmcG3T6.js";import"./ethereum-8HMgNHU3.js";import"./types-DC0Zmj1B.js";import"./browser-ponyfill-CvvEnW1h.js";const ct="error",Gt="wss://relay.walletconnect.org",Vt="wc",Kt="universal_provider",x=`${Vt}@2:${Kt}:`,St="https://rpc.walletconnect.org/v1/",qt="generic",Wt=`${St}bundler`,_="call_status",Yt=86400,v={DEFAULT_CHAIN_CHANGED:"default_chain_changed"};function it(i){return i==null||typeof i!="object"&&typeof i!="function"}function Nt(i){return Object.getOwnPropertySymbols(i).filter(t=>Object.prototype.propertyIsEnumerable.call(i,t))}function Dt(i){return i==null?i===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(i)}const Qt="[object RegExp]",_t="[object String]",Ft="[object Number]",Rt="[object Boolean]",xt="[object Arguments]",Xt="[object Symbol]",Zt="[object Date]",te="[object Map]",ee="[object Set]",ie="[object Array]",se="[object ArrayBuffer]",re="[object Object]",ne="[object DataView]",ae="[object Uint8Array]",oe="[object Uint8ClampedArray]",ce="[object Uint16Array]",he="[object Uint32Array]",pe="[object Int8Array]",ue="[object Int16Array]",le="[object Int32Array]",de="[object Float32Array]",fe="[object Float64Array]";function st(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function me(i,t){return D(i,void 0,i,new Map,t)}function D(i,t,e,s=new Map,n=void 0){const a=n==null?void 0:n(i,t,e,s);if(a!=null)return a;if(it(i))return i;if(s.has(i))return s.get(i);if(Array.isArray(i)){const r=new Array(i.length);s.set(i,r);for(let o=0;o<i.length;o++)r[o]=D(i[o],o,e,s,n);return Object.hasOwn(i,"index")&&(r.index=i.index),Object.hasOwn(i,"input")&&(r.input=i.input),r}if(i instanceof Date)return new Date(i.getTime());if(i instanceof RegExp){const r=new RegExp(i.source,i.flags);return r.lastIndex=i.lastIndex,r}if(i instanceof Map){const r=new Map;s.set(i,r);for(const[o,c]of i)r.set(o,D(c,o,e,s,n));return r}if(i instanceof Set){const r=new Set;s.set(i,r);for(const o of i)r.add(D(o,void 0,e,s,n));return r}if(typeof M<"u"&&M.isBuffer(i))return i.subarray();if(st(i)){const r=new(Object.getPrototypeOf(i)).constructor(i.length);s.set(i,r);for(let o=0;o<i.length;o++)r[o]=D(i[o],o,e,s,n);return r}if(i instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&i instanceof SharedArrayBuffer)return i.slice(0);if(i instanceof DataView){const r=new DataView(i.buffer.slice(0),i.byteOffset,i.byteLength);return s.set(i,r),y(r,i,e,s,n),r}if(typeof File<"u"&&i instanceof File){const r=new File([i],i.name,{type:i.type});return s.set(i,r),y(r,i,e,s,n),r}if(i instanceof Blob){const r=new Blob([i],{type:i.type});return s.set(i,r),y(r,i,e,s,n),r}if(i instanceof Error){const r=new i.constructor;return s.set(i,r),r.message=i.message,r.name=i.name,r.stack=i.stack,r.cause=i.cause,y(r,i,e,s,n),r}if(typeof i=="object"&&ve(i)){const r=Object.create(Object.getPrototypeOf(i));return s.set(i,r),y(r,i,e,s,n),r}return i}function y(i,t,e=i,s,n){const a=[...Object.keys(t),...Nt(t)];for(let r=0;r<a.length;r++){const o=a[r],c=Object.getOwnPropertyDescriptor(i,o);(c==null||c.writable)&&(i[o]=D(t[o],o,e,s,n))}}function ve(i){switch(Dt(i)){case xt:case ie:case se:case ne:case Rt:case Zt:case de:case fe:case pe:case ue:case le:case te:case Ft:case re:case Qt:case ee:case _t:case Xt:case ae:case oe:case ce:case he:return!0;default:return!1}}function ge(i,t){return me(i,(e,s,n,a)=>{if(typeof i=="object")switch(Object.prototype.toString.call(i)){case Ft:case _t:case Rt:{const r=new i.constructor(i==null?void 0:i.valueOf());return y(r,i),r}case xt:{const r={};return y(r,i),r.length=i.length,r[Symbol.iterator]=i[Symbol.iterator],r}default:return}})}function ht(i){return ge(i)}function pt(i){return i!==null&&typeof i=="object"&&Dt(i)==="[object Arguments]"}function ut(i){return typeof i=="object"&&i!==null}function Pe(){}function we(i){return st(i)}function be(i){var e;if(typeof i!="object"||i==null)return!1;if(Object.getPrototypeOf(i)===null)return!0;if(Object.prototype.toString.call(i)!=="[object Object]"){const s=i[Symbol.toStringTag];return s==null||!((e=Object.getOwnPropertyDescriptor(i,Symbol.toStringTag))!=null&&e.writable)?!1:i.toString()===`[object ${s}]`}let t=i;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(i)===t}function ye(i){if(it(i))return i;if(Array.isArray(i)||st(i)||i instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&i instanceof SharedArrayBuffer)return i.slice(0);const t=Object.getPrototypeOf(i),e=t.constructor;if(i instanceof Date||i instanceof Map||i instanceof Set)return new e(i);if(i instanceof RegExp){const s=new e(i);return s.lastIndex=i.lastIndex,s}if(i instanceof DataView)return new e(i.buffer.slice(0));if(i instanceof Error){const s=new e(i.message);return s.stack=i.stack,s.name=i.name,s.cause=i.cause,s}if(typeof File<"u"&&i instanceof File)return new e([i],i.name,{type:i.type,lastModified:i.lastModified});if(typeof i=="object"){const s=Object.create(t);return Object.assign(s,i)}return i}function Ce(i,...t){const e=t.slice(0,-1),s=t[t.length-1];let n=i;for(let a=0;a<e.length;a++){const r=e[a];n=Z(n,r,s,new Map)}return n}function Z(i,t,e,s){if(it(i)&&(i=Object(i)),t==null||typeof t!="object")return i;if(s.has(t))return ye(s.get(t));if(s.set(t,i),Array.isArray(t)){t=t.slice();for(let a=0;a<t.length;a++)t[a]=t[a]??void 0}const n=[...Object.keys(t),...Nt(t)];for(let a=0;a<n.length;a++){const r=n[a];let o=t[r],c=i[r];if(pt(o)&&(o={...o}),pt(c)&&(c={...c}),typeof M<"u"&&M.isBuffer(o)&&(o=ht(o)),Array.isArray(o))if(typeof c=="object"&&c!=null){const l=[],h=Reflect.ownKeys(c);for(let w=0;w<h.length;w++){const d=h[w];l[d]=c[d]}c=l}else c=[];const u=e(c,o,r,i,t,s);u!=null?i[r]=u:Array.isArray(o)||ut(c)&&ut(o)?i[r]=Z(c,o,e,s):c==null&&be(o)?i[r]=Z({},o,e,s):c==null&&we(o)?i[r]=ht(o):(c===void 0||o!==void 0)&&(i[r]=o)}return i}function Ie(i,...t){return Ce(i,...t,Pe)}var Oe=Object.defineProperty,je=Object.defineProperties,He=Object.getOwnPropertyDescriptors,lt=Object.getOwnPropertySymbols,$e=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable,dt=(i,t,e)=>t in i?Oe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,U=(i,t)=>{for(var e in t||(t={}))$e.call(t,e)&&dt(i,e,t[e]);if(lt)for(var e of lt(t))Ae.call(t,e)&&dt(i,e,t[e]);return i},Ee=(i,t)=>je(i,He(t));function f(i,t,e){var s;const n=B(i);return((s=t.rpcMap)==null?void 0:s[n.reference])||`${St}?chainId=${n.namespace}:${n.reference}&projectId=${e}`}function C(i){return i.includes(":")?i.split(":")[1]:i}function Ut(i){return i.map(t=>`${t.split(":")[0]}:${t.split(":")[1]}`)}function Se(i,t){const e=Object.keys(t.namespaces).filter(n=>n.includes(i));if(!e.length)return[];const s=[];return e.forEach(n=>{const a=t.namespaces[n].accounts;s.push(...a)}),s}function ft(i){return Object.fromEntries(Object.entries(i).filter(([t,e])=>{var s,n;return((s=e==null?void 0:e.chains)==null?void 0:s.length)&&((n=e==null?void 0:e.chains)==null?void 0:n.length)>0}))}function k(i={},t={}){const e=ft(mt(i)),s=ft(mt(t));return Ie(e,s)}function mt(i){var t,e,s,n,a;const r={};if(!R(i))return r;for(const[o,c]of Object.entries(i)){const u=$t(o)?[o]:c.chains,l=c.methods||[],h=c.events||[],w=c.rpcMap||{},d=F(o);r[d]=Ee(U(U({},r[d]),c),{chains:z(u,(t=r[d])==null?void 0:t.chains),methods:z(l,(e=r[d])==null?void 0:e.methods),events:z(h,(s=r[d])==null?void 0:s.events)}),(R(w)||R(((n=r[d])==null?void 0:n.rpcMap)||{}))&&(r[d].rpcMap=U(U({},w),(a=r[d])==null?void 0:a.rpcMap))}return r}function vt(i){return i.includes(":")?i.split(":")[2]:i}function gt(i){const t={};for(const[e,s]of Object.entries(i)){const n=s.methods||[],a=s.events||[],r=s.accounts||[],o=$t(e)?[e]:s.chains?s.chains:Ut(s.accounts);t[e]={chains:o,methods:n,events:a,accounts:r}}return t}function G(i){return typeof i=="number"?i:i.includes("0x")?parseInt(i,16):(i=i.includes(":")?i.split(":")[1]:i,isNaN(Number(i))?i:Number(i))}function qe(i){try{const t=JSON.parse(i);return typeof t=="object"&&t!==null&&!Array.isArray(t)}catch{return!1}}const kt={},p=i=>kt[i],V=(i,t)=>{kt[i]=t};var Ne=Object.defineProperty,Pt=Object.getOwnPropertySymbols,De=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable,wt=(i,t,e)=>t in i?Ne(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,bt=(i,t)=>{for(var e in t||(t={}))De.call(t,e)&&wt(i,e,t[e]);if(Pt)for(var e of Pt(t))_e.call(t,e)&&wt(i,e,t[e]);return i};const yt="eip155",Fe=["atomic","flow-control","paymasterService","sessionKeys","auxiliaryFunds"],Re=i=>i&&i.startsWith("0x")?BigInt(i).toString(10):i,K=i=>i&&i.startsWith("0x")?i:`0x${BigInt(i).toString(16)}`,Ct=i=>Object.keys(i).filter(t=>Fe.includes(t)).reduce((t,e)=>(t[e]=xe(i[e]),t),{}),xe=i=>typeof i=="string"&&qe(i)?JSON.parse(i):i,Ue=(i,t,e)=>{const{sessionProperties:s={},scopedProperties:n={}}=i,a={};if(!R(n)&&!R(s))return;const r=Ct(s);for(const o of e){const c=Re(o);if(!c)continue;a[K(c)]=r;const u=n==null?void 0:n[`${yt}:${c}`];if(u){const l=u==null?void 0:u[`${yt}:${c}:${t}`];a[K(c)]=bt(bt({},a[K(c)]),Ct(l||u))}}for(const[o,c]of Object.entries(a))Object.keys(c).length===0&&delete a[o];return Object.keys(a).length>0?a:void 0};var ke=Object.defineProperty,Te=(i,t,e)=>t in i?ke(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Me=(i,t,e)=>Te(i,t+"",e);let W;class rt{constructor(t){Me(this,"storage"),this.storage=t}async getItem(t){return await this.storage.getItem(t)}async setItem(t,e){return await this.storage.setItem(t,e)}async removeItem(t){return await this.storage.removeItem(t)}static getStorage(t){return W||(W=new rt(t)),W}}var Be=Object.defineProperty,Le=Object.defineProperties,Je=Object.getOwnPropertyDescriptors,It=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable,Ot=(i,t,e)=>t in i?Be(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Ve=(i,t)=>{for(var e in t||(t={}))ze.call(t,e)&&Ot(i,e,t[e]);if(It)for(var e of It(t))Ge.call(t,e)&&Ot(i,e,t[e]);return i},Ke=(i,t)=>Le(i,Je(t));async function We(i,t){const e=B(i.result.capabilities.caip345.caip2),s=i.result.capabilities.caip345.transactionHashes,n=await Promise.allSettled(s.map(h=>Ye(e.reference,h,t))),a=n.filter(h=>h.status==="fulfilled").map(h=>h.value).filter(h=>h);n.filter(h=>h.status==="rejected").forEach(h=>console.warn("Failed to fetch transaction receipt:",h.reason));const r=!a.length||a.some(h=>!h),o=a.every(h=>(h==null?void 0:h.status)==="0x1"),c=a.every(h=>(h==null?void 0:h.status)==="0x0"),u=a.some(h=>(h==null?void 0:h.status)==="0x0");let l;return r?l=100:o?l=200:c?l=500:u&&(l=600),{id:i.result.id,version:i.request.version,atomic:i.request.atomicRequired,chainId:i.request.chainId,capabilities:i.result.capabilities,receipts:a,status:l}}async function Ye(i,t,e){return await e(parseInt(i)).request(Et("eth_getTransactionReceipt",[t]))}async function Qe({sendCalls:i,storage:t}){const e=await t.getItem(_);await t.setItem(_,Ke(Ve({},e),{[i.result.id]:{request:i.request,result:i.result,expiry:Lt(Yt)}}))}async function Xe({resultId:i,storage:t}){const e=await t.getItem(_);if(e){delete e[i],await t.setItem(_,e);for(const s in e)At(e[s].expiry)&&delete e[s];await t.setItem(_,e)}}async function Ze({resultId:i,storage:t}){const e=await t.getItem(_),s=e==null?void 0:e[i];if(s&&!At(s.expiry))return s;await Xe({resultId:i,storage:t})}var ti=Object.defineProperty,ei=(i,t,e)=>t in i?ti(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,I=(i,t,e)=>ei(i,typeof t!="symbol"?t+"":t,e);class ii{constructor(t){I(this,"name","polkadot"),I(this,"client"),I(this,"httpProviders"),I(this,"events"),I(this,"namespace"),I(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${t}`)}getAccounts(){const t=this.namespace.accounts;return t?t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2])||[]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var si=Object.defineProperty,ri=Object.defineProperties,ni=Object.getOwnPropertyDescriptors,jt=Object.getOwnPropertySymbols,ai=Object.prototype.hasOwnProperty,oi=Object.prototype.propertyIsEnumerable,tt=(i,t,e)=>t in i?si(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Y=(i,t)=>{for(var e in t||(t={}))ai.call(t,e)&&tt(i,e,t[e]);if(jt)for(var e of jt(t))oi.call(t,e)&&tt(i,e,t[e]);return i},Q=(i,t)=>ri(i,ni(t)),b=(i,t,e)=>tt(i,typeof t!="symbol"?t+"":t,e);class ci{constructor(t){b(this,"name","eip155"),b(this,"client"),b(this,"chainId"),b(this,"namespace"),b(this,"httpProviders"),b(this,"events"),b(this,"storage"),this.namespace=t.namespace,this.events=p("events"),this.client=p("client"),this.httpProviders=this.createHttpProviders(),this.chainId=parseInt(this.getDefaultChain()),this.storage=rt.getStorage(this.client.core.storage)}async request(t){switch(t.request.method){case"eth_requestAccounts":return this.getAccounts();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);case"wallet_sendCalls":return await this.sendCalls(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(v.DEFAULT_CHAIN_CHANGED,`${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||f(`${this.name}:${t}`,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("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 n=parseInt(C(e));t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?void 0:s[e])}),t}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}getHttpProvider(t){const e=t||this.chainId;return this.httpProviders[e]||(this.httpProviders=Q(Y({},this.httpProviders),{[e]:this.createHttpProvider(e)}),this.httpProviders[e])}async handleSwitchChain(t){var e,s;let n=t.request.params?(e=t.request.params[0])==null?void 0:e.chainId:"0x0";n=n.startsWith("0x")?n:`0x${n}`;const a=parseInt(n,16);if(this.isChainApproved(a))this.setDefaultChain(`${a}`);else if(this.namespace.methods.includes("wallet_switchEthereumChain"))await this.client.request({topic:t.topic,request:{method:t.request.method,params:[{chainId:n}]},chainId:(s=this.namespace.chains)==null?void 0:s[0]}),this.setDefaultChain(`${a}`);else throw new Error(`Failed to switch to chain 'eip155:${a}'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method.`);return null}isChainApproved(t){return this.namespace.chains.includes(`${this.name}:${t}`)}async getCapabilities(t){var e,s,n,a,r;const o=(s=(e=t.request)==null?void 0:e.params)==null?void 0:s[0],c=((a=(n=t.request)==null?void 0:n.params)==null?void 0:a[1])||[];if(!o)throw new Error("Missing address parameter in `wallet_getCapabilities` request");const u=this.client.session.get(t.topic),l=((r=u==null?void 0:u.sessionProperties)==null?void 0:r.capabilities)||{},h=`${o}${c.join(",")}`,w=l==null?void 0:l[h];if(w)return w;let d;try{d=Ue(u,o,c)}catch(L){console.warn("Failed to extract capabilities from session",L)}if(d)return d;const at=await this.client.request(t);try{await this.client.session.update(t.topic,{sessionProperties:Q(Y({},u.sessionProperties||{}),{capabilities:Q(Y({},l||{}),{[h]:at})})})}catch(L){console.warn("Failed to update session with capabilities",L)}return at}async getCallStatus(t){var e,s,n;const a=this.client.session.get(t.topic),r=(e=a.sessionProperties)==null?void 0:e.bundler_name;if(r){const u=this.getBundlerUrl(t.chainId,r);try{return await this.getUserOperationReceipt(u,t)}catch(l){console.warn("Failed to fetch call status from bundler",l,u)}}const o=(s=a.sessionProperties)==null?void 0:s.bundler_url;if(o)try{return await this.getUserOperationReceipt(o,t)}catch(u){console.warn("Failed to fetch call status from custom bundler",u,o)}const c=await Ze({resultId:(n=t.request.params)==null?void 0:n[0],storage:this.storage});if(c)try{return await We(c,this.getHttpProvider.bind(this))}catch(u){console.warn("Failed to fetch call status from stored send calls",u,c)}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 n=new URL(t),a=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Et("eth_getUserOperationReceipt",[(s=e.request.params)==null?void 0:s[0]]))});if(!a.ok)throw new Error(`Failed to fetch user operation receipt - ${a.status}`);return await a.json()}getBundlerUrl(t,e){return`${Wt}?projectId=${this.client.core.projectId}&chainId=${t}&bundler=${e}`}async sendCalls(t){var e,s,n;const a=await this.client.request(t),r=(e=t.request.params)==null?void 0:e[0],o=a==null?void 0:a.id,c=(a==null?void 0:a.capabilities)||{},u=(s=c==null?void 0:c.caip345)==null?void 0:s.caip2,l=(n=c==null?void 0:c.caip345)==null?void 0:n.transactionHashes;return!o||!u||!(l!=null&&l.length)||await Qe({sendCalls:{request:r,result:a},storage:this.storage}),a}}var hi=Object.defineProperty,pi=(i,t,e)=>t in i?hi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,O=(i,t,e)=>pi(i,typeof t!="symbol"?t+"":t,e);class ui{constructor(t){O(this,"name","solana"),O(this,"client"),O(this,"httpProviders"),O(this,"events"),O(this,"namespace"),O(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${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(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var li=Object.defineProperty,di=(i,t,e)=>t in i?li(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,j=(i,t,e)=>di(i,typeof t!="symbol"?t+"":t,e);class fi{constructor(t){j(this,"name","cosmos"),j(this,"client"),j(this,"httpProviders"),j(this,"events"),j(this,"namespace"),j(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var mi=Object.defineProperty,vi=(i,t,e)=>t in i?mi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,H=(i,t,e)=>vi(i,typeof t!="symbol"?t+"":t,e);class gi{constructor(t){H(this,"name","algorand"),H(this,"client"),H(this,"httpProviders"),H(this,"events"),H(this,"namespace"),H(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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||f(`${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(v.DEFAULT_CHAIN_CHANGED,`${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(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;t[e]=this.createHttpProvider(e,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);return typeof s>"u"?void 0:new g(new P(s,p("disableProviderPing")))}}var Pi=Object.defineProperty,wi=(i,t,e)=>t in i?Pi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,$=(i,t,e)=>wi(i,typeof t!="symbol"?t+"":t,e);class bi{constructor(t){$(this,"name","cip34"),$(this,"client"),$(this,"httpProviders"),$(this,"events"),$(this,"namespace"),$(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{const s=this.getCardanoRPCUrl(e),n=C(e);t[n]=this.createHttpProvider(n,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 g(new P(s,p("disableProviderPing")))}}var yi=Object.defineProperty,Ci=(i,t,e)=>t in i?yi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,A=(i,t,e)=>Ci(i,typeof t!="symbol"?t+"":t,e);class Ii{constructor(t){A(this,"name","elrond"),A(this,"client"),A(this,"httpProviders"),A(this,"events"),A(this,"namespace"),A(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${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(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var Oi=Object.defineProperty,ji=(i,t,e)=>t in i?Oi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,E=(i,t,e)=>ji(i,typeof t!="symbol"?t+"":t,e);class Hi{constructor(t){E(this,"name","multiversx"),E(this,"client"),E(this,"httpProviders"),E(this,"events"),E(this,"namespace"),E(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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(v.DEFAULT_CHAIN_CHANGED,`${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(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;const n=C(e);t[n]=this.createHttpProvider(n,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var $i=Object.defineProperty,Ai=(i,t,e)=>t in i?$i(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,S=(i,t,e)=>Ai(i,typeof t!="symbol"?t+"":t,e);class Ei{constructor(t){S(this,"name","near"),S(this,"client"),S(this,"httpProviders"),S(this,"events"),S(this,"namespace"),S(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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||f(`${this.name}:${t}`,this.namespace);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);this.setHttpProvider(t,s)}this.events.emit(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2])||[]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(e=>{var s;t[e]=this.createHttpProvider(e,(s=this.namespace.rpcMap)==null?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||f(t,this.namespace);return typeof s>"u"?void 0:new g(new P(s,p("disableProviderPing")))}}var Si=Object.defineProperty,qi=(i,t,e)=>t in i?Si(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,q=(i,t,e)=>qi(i,typeof t!="symbol"?t+"":t,e);class Ni{constructor(t){q(this,"name","tezos"),q(this,"client"),q(this,"httpProviders"),q(this,"events"),q(this,"namespace"),q(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("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||f(`${this.name}:${t}`,this.namespace);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);this.setHttpProvider(t,s)}this.events.emit(v.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.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||f(t,this.namespace);return typeof s>"u"?void 0:new g(new P(s))}}var Di=Object.defineProperty,_i=(i,t,e)=>t in i?Di(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,N=(i,t,e)=>_i(i,typeof t!="symbol"?t+"":t,e);class Fi{constructor(t){N(this,"name",qt),N(this,"client"),N(this,"httpProviders"),N(this,"events"),N(this,"namespace"),N(this,"chainId"),this.namespace=t.namespace,this.events=p("events"),this.client=p("client"),this.chainId=this.getDefaultChain(),this.name=this.getNamespaceName(),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(v.DEFAULT_CHAIN_CHANGED,`${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]}getNamespaceName(){const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return B(t).namespace}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(e=>e.split(":")[1]===this.chainId.toString()).map(e=>e.split(":")[2]))]:[]}createHttpProviders(){var t,e;const s={};return(e=(t=this.namespace)==null?void 0:t.accounts)==null||e.forEach(n=>{const a=B(n);s[a.reference]=this.createHttpProvider(n)}),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||f(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new g(new P(s,p("disableProviderPing")))}}var Ri=Object.defineProperty,xi=Object.defineProperties,Ui=Object.getOwnPropertyDescriptors,Ht=Object.getOwnPropertySymbols,ki=Object.prototype.hasOwnProperty,Ti=Object.prototype.propertyIsEnumerable,et=(i,t,e)=>t in i?Ri(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,T=(i,t)=>{for(var e in t||(t={}))ki.call(t,e)&&et(i,e,t[e]);if(Ht)for(var e of Ht(t))Ti.call(t,e)&&et(i,e,t[e]);return i},X=(i,t)=>xi(i,Ui(t)),m=(i,t,e)=>et(i,typeof t!="symbol"?t+"":t,e);class nt{constructor(t){m(this,"client"),m(this,"namespaces"),m(this,"optionalNamespaces"),m(this,"sessionProperties"),m(this,"scopedProperties"),m(this,"events",new zt),m(this,"rpcProviders",{}),m(this,"session"),m(this,"providerOpts"),m(this,"logger"),m(this,"uri"),m(this,"disableProviderPing",!1),this.providerOpts=t,this.logger=typeof(t==null?void 0:t.logger)<"u"&&typeof(t==null?void 0:t.logger)!="string"?t.logger:Tt(Mt({level:(t==null?void 0:t.logger)||ct})),this.disableProviderPing=(t==null?void 0:t.disableProviderPing)||!1}static async init(t){const e=new nt(t);return await e.initialize(),e}async request(t,e,s){const[n,a]=this.validateChain(e);if(!this.session)throw new Error("Please call connect() before request()");return await this.getProvider(n).request({request:T({},t),chainId:`${n}:${a}`,topic:this.session.topic,expiry:s})}sendAsync(t,e,s,n){const a=new Date().getTime();this.request(t,s,n).then(r=>e(null,Jt(a,r))).catch(r=>e(r,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,scopedProperties:this.scopedProperties}),await this.requestAccounts()}async disconnect(){var t;if(!this.session)throw new Error("Please call connect() before enable()");await this.client.disconnect({topic:(t=this.session)==null?void 0:t.topic,reason:ot("USER_DISCONNECTED")}),await this.cleanup()}async connect(t){if(!this.client)throw new Error("Sign Client not initialized");if(this.setNamespaces(t),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:n}=await this.client.authenticate(t,e);s&&(this.uri=s,this.events.emit("display_uri",s));const a=await n();if(this.session=a.session,this.session){const r=gt(this.session.namespaces);this.namespaces=k(this.namespaces,r),await this.persist("namespaces",this.namespaces),this.onConnect()}return a}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){const{uri:e,approval:s}=await this.client.connect({pairingTopic:t,requiredNamespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties,scopedProperties:this.scopedProperties});e&&(this.uri=e,this.events.emit("display_uri",e));const n=await s();this.session=n;const a=gt(n.namespaces);return this.namespaces=k(this.namespaces,a),await this.persist("namespaces",this.namespaces),await this.persist("optionalNamespaces",this.optionalNamespaces),this.onConnect(),this.session}setDefaultChain(t,e){try{if(!this.session)return;const[s,n]=this.validateChain(t);this.getProvider(s).setDefaultChain(n,e)}catch(s){if(!/Please call connect/.test(s.message))throw s}}async cleanupPendingPairings(t={}){try{this.logger.info("Cleaning up inactive pairings...");const e=this.client.pairing.getAll();if(!J(e))return;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}`)}catch(e){this.logger.warn("Failed to cleanup pending pairings",e)}}abortPairingAttempt(){this.logger.warn("abortPairingAttempt is deprecated. This is now a no-op.")}async checkStorage(){this.namespaces=await this.getFromStore("namespaces")||{},this.optionalNamespaces=await this.getFromStore("optionalNamespaces")||{},this.session&&this.createProviders()}async initialize(){this.logger.trace("Initialized"),await this.createClient(),await this.checkStorage(),this.registerEventListeners()}async createClient(){var t,e;if(this.client=this.providerOpts.client||await Bt.init({core:this.providerOpts.core,logger:this.providerOpts.logger||ct,relayUrl:this.providerOpts.relayUrl||Gt,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.providerOpts.session)try{this.session=this.client.session.get(this.providerOpts.session.topic)}catch(s){throw this.logger.error("Failed to get session",s),new Error(`The provided session: ${(e=(t=this.providerOpts)==null?void 0:t.session)==null?void 0:e.topic} doesn't exist in the Sign client`)}else{const s=this.client.session.getAll();this.session=s[0]}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(e=>F(e)))];V("client",this.client),V("events",this.events),V("disableProviderPing",this.disableProviderPing),t.forEach(e=>{if(!this.session)return;const s=Se(e,this.session);if((s==null?void 0:s.length)===0)return;const n=Ut(s),a=k(this.namespaces,this.optionalNamespaces),r=X(T({},a[e]),{accounts:s,chains:n});switch(e){case"eip155":this.rpcProviders[e]=new ci({namespace:r});break;case"algorand":this.rpcProviders[e]=new gi({namespace:r});break;case"solana":this.rpcProviders[e]=new ui({namespace:r});break;case"cosmos":this.rpcProviders[e]=new fi({namespace:r});break;case"polkadot":this.rpcProviders[e]=new ii({namespace:r});break;case"cip34":this.rpcProviders[e]=new bi({namespace:r});break;case"elrond":this.rpcProviders[e]=new Ii({namespace:r});break;case"multiversx":this.rpcProviders[e]=new Hi({namespace:r});break;case"near":this.rpcProviders[e]=new Ei({namespace:r});break;case"tezos":this.rpcProviders[e]=new Ni({namespace:r});break;default:this.rpcProviders[e]=new Fi({namespace:r})}})}registerEventListeners(){if(typeof this.client>"u")throw new Error("Sign Client is not initialized");this.client.on("session_ping",t=>{var e;const{topic:s}=t;s===((e=this.session)==null?void 0:e.topic)&&this.events.emit("session_ping",t)}),this.client.on("session_event",t=>{var e;const{params:s,topic:n}=t;if(n!==((e=this.session)==null?void 0:e.topic))return;const{event:a}=s;if(a.name==="accountsChanged"){const r=a.data;r&&J(r)&&this.events.emit("accountsChanged",r.map(vt))}else if(a.name==="chainChanged"){const r=s.chainId,o=s.event.data,c=F(r),u=G(r)!==G(o)?`${c}:${G(o)}`:r;this.onChainChanged(u)}else this.events.emit(a.name,a.data);this.events.emit("session_event",t)}),this.client.on("session_update",({topic:t,params:e})=>{var s,n;if(t!==((s=this.session)==null?void 0:s.topic))return;const{namespaces:a}=e,r=(n=this.client)==null?void 0:n.session.get(t);this.session=X(T({},r),{namespaces:a}),this.onSessionUpdate(),this.events.emit("session_update",{topic:t,params:e})}),this.client.on("session_delete",async t=>{var e;t.topic===((e=this.session)==null?void 0:e.topic)&&(await this.cleanup(),this.events.emit("session_delete",t),this.events.emit("disconnect",X(T({},ot("USER_DISCONNECTED")),{data:t.topic})))}),this.on(v.DEFAULT_CHAIN_CHANGED,t=>{this.onChainChanged(t,!0)})}getProvider(t){return this.rpcProviders[t]||this.rpcProviders[qt]}onSessionUpdate(){Object.keys(this.rpcProviders).forEach(t=>{var e;this.getProvider(t).updateNamespace((e=this.session)==null?void 0:e.namespaces[t])})}setNamespaces(t){const{namespaces:e={},optionalNamespaces:s={},sessionProperties:n,scopedProperties:a}=t;this.optionalNamespaces=k(e,s),this.sessionProperties=n,this.scopedProperties=a}validateChain(t){const[e,s]=(t==null?void 0:t.split(":"))||["",""];if(!this.namespaces||!Object.keys(this.namespaces).length)return[e,s];if(e&&!Object.keys(this.namespaces||{}).map(r=>F(r)).includes(e))throw new Error(`Namespace '${e}' is not configured. Please call connect() first with namespace config.`);if(e&&s)return[e,s];const n=F(Object.keys(this.namespaces)[0]),a=this.rpcProviders[n].getDefaultChain();return[n,a]}async requestAccounts(){const[t]=this.validateChain();return await this.getProvider(t).requestAccounts()}async onChainChanged(t,e=!1){if(!this.namespaces)return;const[s,n]=this.validateChain(t);if(!n)return;this.updateNamespaceChain(s,n);const a=this.getProvider(s).getDefaultChain();e?(this.events.emit("chainChanged",n),this.emitAccountsChangedOnChainChange({namespace:s,previousChainId:a,newChainId:t})):this.getProvider(s).setDefaultChain(n),await this.persist("namespaces",this.namespaces)}emitAccountsChangedOnChainChange({namespace:t,previousChainId:e,newChainId:s}){var n,a;try{if(e===s)return;const r=(a=(n=this.session)==null?void 0:n.namespaces[t])==null?void 0:a.accounts;if(!r)return;const o=r.filter(c=>c.includes(`${s}:`)).map(vt);if(!J(o))return;this.events.emit("accountsChanged",o)}catch(r){this.logger.warn("Failed to emit accountsChanged on chain change",r)}}updateNamespaceChain(t,e){if(!this.namespaces)return;const s=this.namespaces[t]?t:`${t}:${e}`,n={chains:[],methods:[],events:[],defaultChain:e};this.namespaces[s]?this.namespaces[s]&&(this.namespaces[s].defaultChain=e):this.namespaces[s]=n}onConnect(){this.createProviders(),this.events.emit("connect",{session:this.session})}async cleanup(){this.namespaces=void 0,this.optionalNamespaces=void 0,this.sessionProperties=void 0,await this.deleteFromStore("namespaces"),await this.deleteFromStore("optionalNamespaces"),await this.deleteFromStore("sessionProperties"),this.session=void 0,this.cleanupPendingPairings({deletePairings:!0}),await this.cleanupStorage()}async persist(t,e){var s;const n=((s=this.session)==null?void 0:s.topic)||"";await this.client.core.storage.setItem(`${x}/${t}${n}`,e)}async getFromStore(t){var e;const s=((e=this.session)==null?void 0:e.topic)||"";return await this.client.core.storage.getItem(`${x}/${t}${s}`)}async deleteFromStore(t){var e;const s=((e=this.session)==null?void 0:e.topic)||"";await this.client.core.storage.removeItem(`${x}/${t}${s}`)}async cleanupStorage(){var t;try{if(((t=this.client)==null?void 0:t.session.length)>0)return;const e=await this.client.core.storage.getKeys();for(const s of e)s.startsWith(x)&&await this.client.core.storage.removeItem(s)}catch(e){this.logger.warn("Failed to cleanup storage",e)}}}const ss=nt;export{ss as UniversalProvider,nt as default};
@@ -1 +1 @@
1
- import{e as d}from"./index-BqHNs9qE.js";import{o}from"./browser-ponyfill-CqE0UlVr.js";import{i as a,s as h,a as u,f as m,p as y}from"./index-BuplIhvx.js";import"./index-BwkHDX6G.js";var b=Object.defineProperty,P=Object.defineProperties,w=Object.getOwnPropertyDescriptors,l=Object.getOwnPropertySymbols,E=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,c=(s,e,t)=>e in s?b(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,p=(s,e)=>{for(var t in e||(e={}))E.call(e,t)&&c(s,t,e[t]);if(l)for(var t of l(e))O.call(e,t)&&c(s,t,e[t]);return s},v=(s,e)=>P(s,w(e));const L={Accept:"application/json","Content-Type":"application/json"},j="POST",f={headers:L,method:j},g=10;class M{constructor(e,t=!1){if(this.url=e,this.disableProviderPing=t,this.events=new d.EventEmitter,this.isAvailable=!1,this.registering=!1,!a(e))throw new Error(`Provided URL is not compatible with HTTP connection: ${e}`);this.url=e,this.disableProviderPing=t}get connected(){return this.isAvailable}get connecting(){return this.registering}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async open(e=this.url){await this.register(e)}async close(){if(!this.isAvailable)throw new Error("Connection already closed");this.onClose()}async send(e){this.isAvailable||await this.register();try{const t=h(e),r=await(await o(this.url,v(p({},f),{body:t}))).json();this.onPayload({data:r})}catch(t){this.onError(e.id,t)}}async register(e=this.url){if(!a(e))throw new Error(`Provided URL is not compatible with HTTP connection: ${e}`);if(this.registering){const t=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=t||this.events.listenerCount("open")>=t)&&this.events.setMaxListeners(t+1),new Promise((r,i)=>{this.events.once("register_error",n=>{this.resetMaxListeners(),i(n)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.isAvailable>"u")return i(new Error("HTTP connection is missing or invalid"));r()})})}this.url=e,this.registering=!0;try{if(!this.disableProviderPing){const t=h({id:1,jsonrpc:"2.0",method:"test",params:[]});await o(e,v(p({},f),{body:t}))}this.onOpen()}catch(t){const r=this.parseError(t);throw this.events.emit("register_error",r),this.onClose(),r}}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 t=typeof e.data=="string"?u(e.data):e.data;this.events.emit("payload",t)}onError(e,t){const r=this.parseError(t),i=r.message||r.toString(),n=m(e,i);this.events.emit("payload",n)}parseError(e,t=this.url){return y(e,t,"HTTP")}resetMaxListeners(){this.events.getMaxListeners()>g&&this.events.setMaxListeners(g)}}export{M as f};
1
+ import{e as d}from"./index-DNXa2sg0.js";import{o}from"./browser-ponyfill-CvvEnW1h.js";import{i as a,s as h,a as u,f as m,p as y}from"./index-Ckxei1Mz.js";import"./index-oiDSpXvo.js";var b=Object.defineProperty,P=Object.defineProperties,w=Object.getOwnPropertyDescriptors,l=Object.getOwnPropertySymbols,E=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,c=(s,e,t)=>e in s?b(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,p=(s,e)=>{for(var t in e||(e={}))E.call(e,t)&&c(s,t,e[t]);if(l)for(var t of l(e))O.call(e,t)&&c(s,t,e[t]);return s},v=(s,e)=>P(s,w(e));const L={Accept:"application/json","Content-Type":"application/json"},j="POST",f={headers:L,method:j},g=10;class M{constructor(e,t=!1){if(this.url=e,this.disableProviderPing=t,this.events=new d.EventEmitter,this.isAvailable=!1,this.registering=!1,!a(e))throw new Error(`Provided URL is not compatible with HTTP connection: ${e}`);this.url=e,this.disableProviderPing=t}get connected(){return this.isAvailable}get connecting(){return this.registering}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async open(e=this.url){await this.register(e)}async close(){if(!this.isAvailable)throw new Error("Connection already closed");this.onClose()}async send(e){this.isAvailable||await this.register();try{const t=h(e),r=await(await o(this.url,v(p({},f),{body:t}))).json();this.onPayload({data:r})}catch(t){this.onError(e.id,t)}}async register(e=this.url){if(!a(e))throw new Error(`Provided URL is not compatible with HTTP connection: ${e}`);if(this.registering){const t=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=t||this.events.listenerCount("open")>=t)&&this.events.setMaxListeners(t+1),new Promise((r,i)=>{this.events.once("register_error",n=>{this.resetMaxListeners(),i(n)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.isAvailable>"u")return i(new Error("HTTP connection is missing or invalid"));r()})})}this.url=e,this.registering=!0;try{if(!this.disableProviderPing){const t=h({id:1,jsonrpc:"2.0",method:"test",params:[]});await o(e,v(p({},f),{body:t}))}this.onOpen()}catch(t){const r=this.parseError(t);throw this.events.emit("register_error",r),this.onClose(),r}}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 t=typeof e.data=="string"?u(e.data):e.data;this.events.emit("payload",t)}onError(e,t){const r=this.parseError(t),i=r.message||r.toString(),n=m(e,i);this.events.emit("payload",n)}parseError(e,t=this.url){return y(e,t,"HTTP")}resetMaxListeners(){this.events.getMaxListeners()>g&&this.events.setMaxListeners(g)}}export{M as f};
@@ -1 +1 @@
1
- import{X as S,Y as f,$ as g,a0 as A,s as _}from"./thirdweb-DaGoGHaJ.js";function v(t){const e=t.domain;return(e==null?void 0:e.chainId)!==void 0&&S(e.chainId)&&(t.domain={...t.domain,chainId:f(t.domain.chainId)}),t}const O={async getItem(t){try{if(typeof window<"u"&&window.localStorage)return localStorage.getItem(t)}catch{}return null},async removeItem(t){typeof window<"u"&&window.localStorage&&localStorage.removeItem(t)},async setItem(t,e){try{typeof window<"u"&&window.localStorage&&localStorage.setItem(t,e)}catch{}}},b="/sdk/2022-08-12/embedded-wallet",h=t=>`thirdwebEwsWalletUserId-${t}`,p="walletToken",d=t=>`${p}-${t}`,I=t=>`passkey-credential-id-${t}`,T="a",w=(t,e)=>`${T}-${t}-${e}`,y=t=>`walletConnectSessions-${t}`,m=t=>`thirdweb_guest_session_id_${t}`,k=new Map;class P{constructor({storage:e,clientId:n,ecosystem:s}){Object.defineProperty(this,"key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ecosystem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.storage=e,this.key=C(n,s==null?void 0:s.id),this.ecosystem=s}async getItem(e){return this.storage?this.storage.getItem(e):k.get(e)??null}async setItem(e,n){if(this.storage)return this.storage.setItem(e,n);k.set(e,n)}async removeItem(e){const n=await this.getItem(e);return this.storage&&n?(this.storage.removeItem(e),!0):!1}async getWalletConnectSessions(){return this.getItem(y(this.key))}async saveWalletConnectSessions(e){await this.setItem(y(this.key),e)}async savePasskeyCredentialId(e){await this.setItem(I(this.key),e)}async getPasskeyCredentialId(){return this.getItem(I(this.key))}async saveAuthCookie(e){await this.setItem(d(this.key),e)}async getAuthCookie(){return this.getItem(d(this.key))}async removeAuthCookie(){return this.removeItem(d(this.key))}async saveDeviceShare(e,n){await this.saveWalletUserId(n),await this.setItem(w(this.key,n),e)}async getDeviceShare(){const e=await this.getWalletUserId();return e?this.getItem(w(this.key,e)):null}async removeDeviceShare(){const e=await this.getWalletUserId();return e?this.removeItem(w(this.key,e)):!1}async getWalletUserId(){return this.getItem(h(this.key))}async saveWalletUserId(e){await this.setItem(h(this.key),e)}async removeWalletUserId(){return this.removeItem(h(this.key))}async getGuestSessionId(){return this.getItem(m(this.key))}async saveGuestSessionId(e){await this.setItem(m(this.key),e)}}const C=(t,e)=>`${t}${e?`-${e}`:""}`;async function R({client:t,ecosystem:e,tokenToLink:n,storage:s}){const l=A(t,e),r=g("inAppWallet"),c=await s.getAuthCookie();if(!c)throw new Error("Failed to link account, no user logged in");const a={Authorization:`Bearer iaw-auth-token:${c}`,"Content-Type":"application/json"},o=await l(`${r}/api/2024-05-05/account/connect`,{body:_({accountAuthTokenToConnect:n}),headers:a,method:"POST"});if(!o.ok){const u=await o.json();throw new Error(u.message||"Failed to link account.")}const{linkedAccounts:i}=await o.json();return i??[]}async function $({client:t,ecosystem:e,profileToUnlink:n,allowAccountDeletion:s=!1,storage:l}){const r=A(t,e),c=g("inAppWallet"),a=await l.getAuthCookie();if(!a)throw new Error("Failed to unlink account, no user logged in");const o={Authorization:`Bearer iaw-auth-token:${a}`,"Content-Type":"application/json"},i=await r(`${c}/api/2024-05-05/account/disconnect`,{body:_({allowAccountDeletion:s,details:n.details,type:n.type}),headers:o,method:"POST"});if(!i.ok){const E=await i.json();throw new Error(E.message||"Failed to unlink account.")}const{linkedAccounts:u}=await i.json();return u??[]}async function N({client:t,ecosystem:e,storage:n}){const s=A(t,e),l=g("inAppWallet"),r=await n.getAuthCookie();if(!r)throw new Error("Failed to get linked accounts, no user logged in");const c={Authorization:`Bearer iaw-auth-token:${r}`,"Content-Type":"application/json"},a=await s(`${l}/api/2024-05-05/accounts`,{headers:c,method:"GET"});if(!a.ok){const i=await a.json();throw new Error(i.message||"Failed to get linked accounts.")}const{linkedAccounts:o}=await a.json();return o??[]}export{P as C,b as I,N as g,R as l,v as p,$ as u,O as w};
1
+ import{X as S,Y as f,$ as g,a0 as A,s as _}from"./thirdweb-DCTNjMNu.js";function v(t){const e=t.domain;return(e==null?void 0:e.chainId)!==void 0&&S(e.chainId)&&(t.domain={...t.domain,chainId:f(t.domain.chainId)}),t}const O={async getItem(t){try{if(typeof window<"u"&&window.localStorage)return localStorage.getItem(t)}catch{}return null},async removeItem(t){typeof window<"u"&&window.localStorage&&localStorage.removeItem(t)},async setItem(t,e){try{typeof window<"u"&&window.localStorage&&localStorage.setItem(t,e)}catch{}}},b="/sdk/2022-08-12/embedded-wallet",h=t=>`thirdwebEwsWalletUserId-${t}`,p="walletToken",d=t=>`${p}-${t}`,I=t=>`passkey-credential-id-${t}`,T="a",w=(t,e)=>`${T}-${t}-${e}`,y=t=>`walletConnectSessions-${t}`,m=t=>`thirdweb_guest_session_id_${t}`,k=new Map;class P{constructor({storage:e,clientId:n,ecosystem:s}){Object.defineProperty(this,"key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ecosystem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.storage=e,this.key=C(n,s==null?void 0:s.id),this.ecosystem=s}async getItem(e){return this.storage?this.storage.getItem(e):k.get(e)??null}async setItem(e,n){if(this.storage)return this.storage.setItem(e,n);k.set(e,n)}async removeItem(e){const n=await this.getItem(e);return this.storage&&n?(this.storage.removeItem(e),!0):!1}async getWalletConnectSessions(){return this.getItem(y(this.key))}async saveWalletConnectSessions(e){await this.setItem(y(this.key),e)}async savePasskeyCredentialId(e){await this.setItem(I(this.key),e)}async getPasskeyCredentialId(){return this.getItem(I(this.key))}async saveAuthCookie(e){await this.setItem(d(this.key),e)}async getAuthCookie(){return this.getItem(d(this.key))}async removeAuthCookie(){return this.removeItem(d(this.key))}async saveDeviceShare(e,n){await this.saveWalletUserId(n),await this.setItem(w(this.key,n),e)}async getDeviceShare(){const e=await this.getWalletUserId();return e?this.getItem(w(this.key,e)):null}async removeDeviceShare(){const e=await this.getWalletUserId();return e?this.removeItem(w(this.key,e)):!1}async getWalletUserId(){return this.getItem(h(this.key))}async saveWalletUserId(e){await this.setItem(h(this.key),e)}async removeWalletUserId(){return this.removeItem(h(this.key))}async getGuestSessionId(){return this.getItem(m(this.key))}async saveGuestSessionId(e){await this.setItem(m(this.key),e)}}const C=(t,e)=>`${t}${e?`-${e}`:""}`;async function R({client:t,ecosystem:e,tokenToLink:n,storage:s}){const l=A(t,e),r=g("inAppWallet"),c=await s.getAuthCookie();if(!c)throw new Error("Failed to link account, no user logged in");const a={Authorization:`Bearer iaw-auth-token:${c}`,"Content-Type":"application/json"},o=await l(`${r}/api/2024-05-05/account/connect`,{body:_({accountAuthTokenToConnect:n}),headers:a,method:"POST"});if(!o.ok){const u=await o.json();throw new Error(u.message||"Failed to link account.")}const{linkedAccounts:i}=await o.json();return i??[]}async function $({client:t,ecosystem:e,profileToUnlink:n,allowAccountDeletion:s=!1,storage:l}){const r=A(t,e),c=g("inAppWallet"),a=await l.getAuthCookie();if(!a)throw new Error("Failed to unlink account, no user logged in");const o={Authorization:`Bearer iaw-auth-token:${a}`,"Content-Type":"application/json"},i=await r(`${c}/api/2024-05-05/account/disconnect`,{body:_({allowAccountDeletion:s,details:n.details,type:n.type}),headers:o,method:"POST"});if(!i.ok){const E=await i.json();throw new Error(E.message||"Failed to unlink account.")}const{linkedAccounts:u}=await i.json();return u??[]}async function N({client:t,ecosystem:e,storage:n}){const s=A(t,e),l=g("inAppWallet"),r=await n.getAuthCookie();if(!r)throw new Error("Failed to get linked accounts, no user logged in");const c={Authorization:`Bearer iaw-auth-token:${r}`,"Content-Type":"application/json"},a=await s(`${l}/api/2024-05-05/accounts`,{headers:c,method:"GET"});if(!a.ok){const i=await a.json();throw new Error(i.message||"Failed to get linked accounts.")}const{linkedAccounts:o}=await a.json();return o??[]}export{P as C,b as I,N as g,R as l,v as p,$ as u,O as w};
@@ -1 +1 @@
1
- import{g as e}from"./ui-BjvItYqm.js";function t(){if(typeof WebSocket<"u")return WebSocket;if(typeof e.WebSocket<"u")return e.WebSocket;if(typeof window.WebSocket<"u")return window.WebSocket;if(typeof self.WebSocket<"u")return self.WebSocket;throw new Error("`WebSocket` is not supported in this environment")}const o=t(),r=Object.freeze(Object.defineProperty({__proto__:null,WebSocket:o},Symbol.toStringTag,{value:"Module"}));export{r as n};
1
+ import{g as e}from"./ui-D3rNG5Q7.js";function t(){if(typeof WebSocket<"u")return WebSocket;if(typeof e.WebSocket<"u")return e.WebSocket;if(typeof window.WebSocket<"u")return window.WebSocket;if(typeof self.WebSocket<"u")return self.WebSocket;throw new Error("`WebSocket` is not supported in this environment")}const o=t(),r=Object.freeze(Object.defineProperty({__proto__:null,WebSocket:o},Symbol.toStringTag,{value:"Module"}));export{r as n};