"use client";
import { e as Se, E as ze } from "./events-ByesS-9C.js";
import { i as oe, s as ce, a as Je, f as Be, p as Ge, $ as Qe, k as Ve, b as Ke, d as Y, c as U, E as We, e as T, T as qe, Y as Ne, o as g, g as Ye, q as Xe, Q as B, K as he } from "./index.es-DbRFw0QB.js";
import { k as z } from "./index.package-D_xeHHvS.js";
import { f as pe } from "./browser-ponyfill-tfa6GFx1.js";
var Ze = Object.defineProperty, et = Object.defineProperties, tt = Object.getOwnPropertyDescriptors, le = Object.getOwnPropertySymbols, st = Object.prototype.hasOwnProperty, it = Object.prototype.propertyIsEnumerable, de = (s, e, t) => e in s ? Ze(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, ue = (s, e) => {
  for (var t in e || (e = {})) st.call(e, t) && de(s, t, e[t]);
  if (le) for (var t of le(e)) it.call(e, t) && de(s, t, e[t]);
  return s;
}, me = (s, e) => et(s, tt(e));
const nt = { Accept: "application/json", "Content-Type": "application/json" }, rt = "POST", fe = { headers: nt, method: rt }, ve = 10;
class w {
  constructor(e, t = !1) {
    if (this.url = e, this.disableProviderPing = t, this.events = new Se.EventEmitter(), this.isAvailable = !1, this.registering = !1, !oe(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 = ce(e), i = await (await pe(this.url, me(ue({}, fe), { body: t }))).json();
      this.onPayload({ data: i });
    } catch (t) {
      this.onError(e.id, t);
    }
  }
  async register(e = this.url) {
    if (!oe(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((i, n) => {
        this.events.once("register_error", (a) => {
          this.resetMaxListeners(), n(a);
        }), this.events.once("open", () => {
          if (this.resetMaxListeners(), typeof this.isAvailable > "u") return n(new Error("HTTP connection is missing or invalid"));
          i();
        });
      });
    }
    this.url = e, this.registering = !0;
    try {
      if (!this.disableProviderPing) {
        const t = ce({ id: 1, jsonrpc: "2.0", method: "test", params: [] });
        await pe(e, me(ue({}, fe), { body: t }));
      }
      this.onOpen();
    } catch (t) {
      const i = this.parseError(t);
      throw this.events.emit("register_error", i), this.onClose(), i;
    }
  }
  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" ? Je(e.data) : e.data;
    this.events.emit("payload", t);
  }
  onError(e, t) {
    const i = this.parseError(t), n = i.message || i.toString(), a = Be(e, n);
    this.events.emit("payload", a);
  }
  parseError(e, t = this.url) {
    return Ge(e, t, "HTTP");
  }
  resetMaxListeners() {
    this.events.getMaxListeners() > ve && this.events.setMaxListeners(ve);
  }
}
const ge = "error", at = "wss://relay.walletconnect.org", ot = "wc", ct = "universal_provider", L = `${ot}@2:${ct}:`, De = "https://rpc.walletconnect.org/v1/", _ = "generic", ht = `${De}bundler`, v = { DEFAULT_CHAIN_CHANGED: "default_chain_changed" };
function pt() {
}
function ne(s) {
  return s == null || typeof s != "object" && typeof s != "function";
}
function re(s) {
  return ArrayBuffer.isView(s) && !(s instanceof DataView);
}
function lt(s) {
  if (ne(s)) return s;
  if (Array.isArray(s) || re(s) || s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer) return s.slice(0);
  const e = Object.getPrototypeOf(s), t = e.constructor;
  if (s instanceof Date || s instanceof Map || s instanceof Set) return new t(s);
  if (s instanceof RegExp) {
    const i = new t(s);
    return i.lastIndex = s.lastIndex, i;
  }
  if (s instanceof DataView) return new t(s.buffer.slice(0));
  if (s instanceof Error) {
    const i = new t(s.message);
    return i.stack = s.stack, i.name = s.name, i.cause = s.cause, i;
  }
  if (typeof File < "u" && s instanceof File) return new t([s], s.name, { type: s.type, lastModified: s.lastModified });
  if (typeof s == "object") {
    const i = Object.create(e);
    return Object.assign(i, s);
  }
  return s;
}
function we(s) {
  return typeof s == "object" && s !== null;
}
function _e(s) {
  return Object.getOwnPropertySymbols(s).filter((e) => Object.prototype.propertyIsEnumerable.call(s, e));
}
function Re(s) {
  return s == null ? s === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(s);
}
const dt = "[object RegExp]", Me = "[object String]", Te = "[object Number]", Ue = "[object Boolean]", Le = "[object Arguments]", ut = "[object Symbol]", mt = "[object Date]", ft = "[object Map]", vt = "[object Set]", gt = "[object Array]", wt = "[object ArrayBuffer]", Pt = "[object Object]", bt = "[object DataView]", yt = "[object Uint8Array]", Ct = "[object Uint8ClampedArray]", It = "[object Uint16Array]", Et = "[object Uint32Array]", $t = "[object Int8Array]", Ot = "[object Int16Array]", jt = "[object Int32Array]", At = "[object Float32Array]", Ht = "[object Float64Array]";
function St(s, e) {
  return M(s, void 0, s, /* @__PURE__ */ new Map(), e);
}
function M(s, e, t, i = /* @__PURE__ */ new Map(), n = void 0) {
  const a = n == null ? void 0 : n(s, e, t, i);
  if (a != null) return a;
  if (ne(s)) return s;
  if (i.has(s)) return i.get(s);
  if (Array.isArray(s)) {
    const r = new Array(s.length);
    i.set(s, r);
    for (let o = 0; o < s.length; o++) r[o] = M(s[o], o, t, i, n);
    return Object.hasOwn(s, "index") && (r.index = s.index), Object.hasOwn(s, "input") && (r.input = s.input), r;
  }
  if (s instanceof Date) return new Date(s.getTime());
  if (s instanceof RegExp) {
    const r = new RegExp(s.source, s.flags);
    return r.lastIndex = s.lastIndex, r;
  }
  if (s instanceof Map) {
    const r = /* @__PURE__ */ new Map();
    i.set(s, r);
    for (const [o, c] of s) r.set(o, M(c, o, t, i, n));
    return r;
  }
  if (s instanceof Set) {
    const r = /* @__PURE__ */ new Set();
    i.set(s, r);
    for (const o of s) r.add(M(o, void 0, t, i, n));
    return r;
  }
  if (typeof z < "u" && z.isBuffer(s)) return s.subarray();
  if (re(s)) {
    const r = new (Object.getPrototypeOf(s)).constructor(s.length);
    i.set(s, r);
    for (let o = 0; o < s.length; o++) r[o] = M(s[o], o, t, i, n);
    return r;
  }
  if (s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer) return s.slice(0);
  if (s instanceof DataView) {
    const r = new DataView(s.buffer.slice(0), s.byteOffset, s.byteLength);
    return i.set(s, r), y(r, s, t, i, n), r;
  }
  if (typeof File < "u" && s instanceof File) {
    const r = new File([s], s.name, { type: s.type });
    return i.set(s, r), y(r, s, t, i, n), r;
  }
  if (s instanceof Blob) {
    const r = new Blob([s], { type: s.type });
    return i.set(s, r), y(r, s, t, i, n), r;
  }
  if (s instanceof Error) {
    const r = new s.constructor();
    return i.set(s, r), r.message = s.message, r.name = s.name, r.stack = s.stack, r.cause = s.cause, y(r, s, t, i, n), r;
  }
  if (typeof s == "object" && qt(s)) {
    const r = Object.create(Object.getPrototypeOf(s));
    return i.set(s, r), y(r, s, t, i, n), r;
  }
  return s;
}
function y(s, e, t = s, i, n) {
  const a = [...Object.keys(e), ..._e(e)];
  for (let r = 0; r < a.length; r++) {
    const o = a[r], c = Object.getOwnPropertyDescriptor(s, o);
    (c == null || c.writable) && (s[o] = M(e[o], o, t, i, n));
  }
}
function qt(s) {
  switch (Re(s)) {
    case Le:
    case gt:
    case wt:
    case bt:
    case Ue:
    case mt:
    case At:
    case Ht:
    case $t:
    case Ot:
    case jt:
    case ft:
    case Te:
    case Pt:
    case dt:
    case vt:
    case Me:
    case ut:
    case yt:
    case Ct:
    case It:
    case Et:
      return !0;
    default:
      return !1;
  }
}
function Nt(s, e) {
  return St(s, (t, i, n, a) => {
    if (typeof s == "object") switch (Object.prototype.toString.call(s)) {
      case Te:
      case Me:
      case Ue: {
        const r = new s.constructor(s == null ? void 0 : s.valueOf());
        return y(r, s), r;
      }
      case Le: {
        const r = {};
        return y(r, s), r.length = s.length, r[Symbol.iterator] = s[Symbol.iterator], r;
      }
      default:
        return;
    }
  });
}
function Pe(s) {
  return Nt(s);
}
function be(s) {
  return s !== null && typeof s == "object" && Re(s) === "[object Arguments]";
}
function Dt(s) {
  return re(s);
}
function _t(s) {
  var t;
  if (typeof s != "object" || s == null) return !1;
  if (Object.getPrototypeOf(s) === null) return !0;
  if (Object.prototype.toString.call(s) !== "[object Object]") {
    const i = s[Symbol.toStringTag];
    return i == null || !((t = Object.getOwnPropertyDescriptor(s, Symbol.toStringTag)) != null && t.writable) ? !1 : s.toString() === `[object ${i}]`;
  }
  let e = s;
  for (; Object.getPrototypeOf(e) !== null; ) e = Object.getPrototypeOf(e);
  return Object.getPrototypeOf(s) === e;
}
function Rt(s, ...e) {
  const t = e.slice(0, -1), i = e[e.length - 1];
  let n = s;
  for (let a = 0; a < t.length; a++) {
    const r = t[a];
    n = X(n, r, i, /* @__PURE__ */ new Map());
  }
  return n;
}
function X(s, e, t, i) {
  if (ne(s) && (s = Object(s)), e == null || typeof e != "object") return s;
  if (i.has(e)) return lt(i.get(e));
  if (i.set(e, s), Array.isArray(e)) {
    e = e.slice();
    for (let a = 0; a < e.length; a++) e[a] = e[a] ?? void 0;
  }
  const n = [...Object.keys(e), ..._e(e)];
  for (let a = 0; a < n.length; a++) {
    const r = n[a];
    let o = e[r], c = s[r];
    if (be(o) && (o = { ...o }), be(c) && (c = { ...c }), typeof z < "u" && z.isBuffer(o) && (o = Pe(o)), Array.isArray(o)) if (typeof c == "object" && c != null) {
      const l = [], b = Reflect.ownKeys(c);
      for (let d = 0; d < b.length; d++) {
        const P = b[d];
        l[P] = c[P];
      }
      c = l;
    } else c = [];
    const p = t(c, o, r, s, e, i);
    p != null ? s[r] = p : Array.isArray(o) || we(c) && we(o) ? s[r] = X(c, o, t, i) : c == null && _t(o) ? s[r] = X({}, o, t, i) : c == null && Dt(o) ? s[r] = Pe(o) : (c === void 0 || o !== void 0) && (s[r] = o);
  }
  return s;
}
function Mt(s, ...e) {
  return Rt(s, ...e, pt);
}
var Tt = Object.defineProperty, Ut = Object.defineProperties, Lt = Object.getOwnPropertyDescriptors, ye = Object.getOwnPropertySymbols, xt = Object.prototype.hasOwnProperty, Ft = Object.prototype.propertyIsEnumerable, Ce = (s, e, t) => e in s ? Tt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, x = (s, e) => {
  for (var t in e || (e = {})) xt.call(e, t) && Ce(s, t, e[t]);
  if (ye) for (var t of ye(e)) Ft.call(e, t) && Ce(s, t, e[t]);
  return s;
}, kt = (s, e) => Ut(s, Lt(e));
function m(s, e, t) {
  var i;
  const n = Ne(s);
  return ((i = e.rpcMap) == null ? void 0 : i[n.reference]) || `${De}?chainId=${n.namespace}:${n.reference}&projectId=${t}`;
}
function C(s) {
  return s.includes(":") ? s.split(":")[1] : s;
}
function xe(s) {
  return s.map((e) => `${e.split(":")[0]}:${e.split(":")[1]}`);
}
function zt(s, e) {
  const t = Object.keys(e.namespaces).filter((n) => n.includes(s));
  if (!t.length) return [];
  const i = [];
  return t.forEach((n) => {
    const a = e.namespaces[n].accounts;
    i.push(...a);
  }), i;
}
function G(s = {}, e = {}) {
  const t = Ie(s), i = Ie(e);
  return Mt(t, i);
}
function Ie(s) {
  var e, t, i, n;
  const a = {};
  if (!Xe(s)) return a;
  for (const [r, o] of Object.entries(s)) {
    const c = qe(r) ? [r] : o.chains, p = o.methods || [], l = o.events || [], b = o.rpcMap || {}, d = T(r);
    a[d] = kt(x(x({}, a[d]), o), { chains: B(c, (e = a[d]) == null ? void 0 : e.chains), methods: B(p, (t = a[d]) == null ? void 0 : t.methods), events: B(l, (i = a[d]) == null ? void 0 : i.events), rpcMap: x(x({}, b), (n = a[d]) == null ? void 0 : n.rpcMap) });
  }
  return a;
}
function Jt(s) {
  return s.includes(":") ? s.split(":")[2] : s;
}
function Ee(s) {
  const e = {};
  for (const [t, i] of Object.entries(s)) {
    const n = i.methods || [], a = i.events || [], r = i.accounts || [], o = qe(t) ? [t] : i.chains ? i.chains : xe(i.accounts);
    e[t] = { chains: o, methods: n, events: a, accounts: r };
  }
  return e;
}
function Q(s) {
  return typeof s == "number" ? s : s.includes("0x") ? parseInt(s, 16) : (s = s.includes(":") ? s.split(":")[1] : s, isNaN(Number(s)) ? s : Number(s));
}
const Fe = {}, h = (s) => Fe[s], V = (s, e) => {
  Fe[s] = e;
};
var Bt = Object.defineProperty, Gt = (s, e, t) => e in s ? Bt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, I = (s, e, t) => Gt(s, typeof e != "symbol" ? e + "" : e, t);
class Qt {
  constructor(e) {
    I(this, "name", "polkadot"), I(this, "client"), I(this, "httpProviders"), I(this, "events"), I(this, "namespace"), I(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId;
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  setDefaultChain(e, t) {
    this.httpProviders[e] || this.setHttpProvider(e, t), this.chainId = e, this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${e}`);
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]) || [] : [];
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      var i;
      const n = C(t);
      e[n] = this.createHttpProvider(n, (i = this.namespace.rpcMap) == null ? void 0 : i[t]);
    }), e;
  }
  getHttpProvider() {
    const e = `${this.name}:${this.chainId}`, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || m(e, this.namespace, this.client.core.projectId);
    if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
    return new g(new w(i, h("disableProviderPing")));
  }
}
var Vt = Object.defineProperty, Kt = Object.defineProperties, Wt = Object.getOwnPropertyDescriptors, $e = Object.getOwnPropertySymbols, Yt = Object.prototype.hasOwnProperty, Xt = Object.prototype.propertyIsEnumerable, Z = (s, e, t) => e in s ? Vt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Oe = (s, e) => {
  for (var t in e || (e = {})) Yt.call(e, t) && Z(s, t, e[t]);
  if ($e) for (var t of $e(e)) Xt.call(e, t) && Z(s, t, e[t]);
  return s;
}, je = (s, e) => Kt(s, Wt(e)), E = (s, e, t) => Z(s, typeof e != "symbol" ? e + "" : e, t);
class Zt {
  constructor(e) {
    E(this, "name", "eip155"), E(this, "client"), E(this, "chainId"), E(this, "namespace"), E(this, "httpProviders"), E(this, "events"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.httpProviders = this.createHttpProviders(), this.chainId = parseInt(this.getDefaultChain());
  }
  async request(e) {
    switch (e.request.method) {
      case "eth_requestAccounts":
        return this.getAccounts();
      case "eth_accounts":
        return this.getAccounts();
      case "wallet_switchEthereumChain":
        return await this.handleSwitchChain(e);
      case "eth_chainId":
        return parseInt(this.getDefaultChain());
      case "wallet_getCapabilities":
        return await this.getCapabilities(e);
      case "wallet_getCallsStatus":
        return await this.getCallStatus(e);
    }
    return this.namespace.methods.includes(e.request.method) ? await this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  setDefaultChain(e, t) {
    this.httpProviders[e] || this.setHttpProvider(parseInt(e), t), this.chainId = parseInt(e), this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${e}`);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId.toString();
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  createHttpProvider(e, t) {
    const i = t || m(`${this.name}:${e}`, this.namespace, this.client.core.projectId);
    if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
    return new g(new w(i, h("disableProviderPing")));
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      var i;
      const n = parseInt(C(t));
      e[n] = this.createHttpProvider(n, (i = this.namespace.rpcMap) == null ? void 0 : i[t]);
    }), e;
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? [...new Set(e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]))] : [];
  }
  getHttpProvider() {
    const e = this.chainId, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  async handleSwitchChain(e) {
    var t, i;
    let n = e.request.params ? (t = e.request.params[0]) == null ? void 0 : t.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: e.topic, request: { method: e.request.method, params: [{ chainId: n }] }, chainId: (i = this.namespace.chains) == null ? void 0 : i[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(e) {
    return this.namespace.chains.includes(`${this.name}:${e}`);
  }
  async getCapabilities(e) {
    var t, i, n;
    const a = (i = (t = e.request) == null ? void 0 : t.params) == null ? void 0 : i[0];
    if (!a) throw new Error("Missing address parameter in `wallet_getCapabilities` request");
    const r = this.client.session.get(e.topic), o = ((n = r == null ? void 0 : r.sessionProperties) == null ? void 0 : n.capabilities) || {};
    if (o != null && o[a]) return o == null ? void 0 : o[a];
    const c = await this.client.request(e);
    try {
      await this.client.session.update(e.topic, { sessionProperties: je(Oe({}, r.sessionProperties || {}), { capabilities: je(Oe({}, o || {}), { [a]: c }) }) });
    } catch (p) {
      console.warn("Failed to update session with capabilities", p);
    }
    return c;
  }
  async getCallStatus(e) {
    var t, i;
    const n = this.client.session.get(e.topic), a = (t = n.sessionProperties) == null ? void 0 : t.bundler_name;
    if (a) {
      const o = this.getBundlerUrl(e.chainId, a);
      try {
        return await this.getUserOperationReceipt(o, e);
      } catch (c) {
        console.warn("Failed to fetch call status from bundler", c, o);
      }
    }
    const r = (i = n.sessionProperties) == null ? void 0 : i.bundler_url;
    if (r) try {
      return await this.getUserOperationReceipt(r, e);
    } catch (o) {
      console.warn("Failed to fetch call status from custom bundler", o, r);
    }
    if (this.namespace.methods.includes(e.request.method)) return await this.client.request(e);
    throw new Error("Fetching call status not approved by the wallet.");
  }
  async getUserOperationReceipt(e, t) {
    var i;
    const n = new URL(e), a = await fetch(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(Ye("eth_getUserOperationReceipt", [(i = t.request.params) == null ? void 0 : i[0]])) });
    if (!a.ok) throw new Error(`Failed to fetch user operation receipt - ${a.status}`);
    return await a.json();
  }
  getBundlerUrl(e, t) {
    return `${ht}?projectId=${this.client.core.projectId}&chainId=${e}&bundler=${t}`;
  }
}
var es = Object.defineProperty, ts = (s, e, t) => e in s ? es(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, $ = (s, e, t) => ts(s, typeof e != "symbol" ? e + "" : e, t);
class ss {
  constructor(e) {
    $(this, "name", "solana"), $(this, "client"), $(this, "httpProviders"), $(this, "events"), $(this, "namespace"), $(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  setDefaultChain(e, t) {
    this.httpProviders[e] || this.setHttpProvider(e, t), this.chainId = e, this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${e}`);
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId;
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? [...new Set(e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]))] : [];
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      var i;
      const n = C(t);
      e[n] = this.createHttpProvider(n, (i = this.namespace.rpcMap) == null ? void 0 : i[t]);
    }), e;
  }
  getHttpProvider() {
    const e = `${this.name}:${this.chainId}`, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || m(e, this.namespace, this.client.core.projectId);
    if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
    return new g(new w(i, h("disableProviderPing")));
  }
}
var is = Object.defineProperty, ns = (s, e, t) => e in s ? is(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, O = (s, e, t) => ns(s, typeof e != "symbol" ? e + "" : e, t);
class rs {
  constructor(e) {
    O(this, "name", "cosmos"), O(this, "client"), O(this, "httpProviders"), O(this, "events"), O(this, "namespace"), O(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId;
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  setDefaultChain(e, t) {
    this.httpProviders[e] || this.setHttpProvider(e, t), this.chainId = e, this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${this.chainId}`);
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? [...new Set(e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]))] : [];
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      var i;
      const n = C(t);
      e[n] = this.createHttpProvider(n, (i = this.namespace.rpcMap) == null ? void 0 : i[t]);
    }), e;
  }
  getHttpProvider() {
    const e = `${this.name}:${this.chainId}`, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || m(e, this.namespace, this.client.core.projectId);
    if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
    return new g(new w(i, h("disableProviderPing")));
  }
}
var as = Object.defineProperty, os = (s, e, t) => e in s ? as(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, j = (s, e, t) => os(s, typeof e != "symbol" ? e + "" : e, t);
class cs {
  constructor(e) {
    j(this, "name", "algorand"), j(this, "client"), j(this, "httpProviders"), j(this, "events"), j(this, "namespace"), j(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  setDefaultChain(e, t) {
    if (!this.httpProviders[e]) {
      const i = t || m(`${this.name}:${e}`, this.namespace, this.client.core.projectId);
      if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
      this.setHttpProvider(e, i);
    }
    this.chainId = e, 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 e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? [...new Set(e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]))] : [];
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      var i;
      e[t] = this.createHttpProvider(t, (i = this.namespace.rpcMap) == null ? void 0 : i[t]);
    }), e;
  }
  getHttpProvider() {
    const e = `${this.name}:${this.chainId}`, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || m(e, this.namespace, this.client.core.projectId);
    return typeof i > "u" ? void 0 : new g(new w(i, h("disableProviderPing")));
  }
}
var hs = Object.defineProperty, ps = (s, e, t) => e in s ? hs(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, A = (s, e, t) => ps(s, typeof e != "symbol" ? e + "" : e, t);
class ls {
  constructor(e) {
    A(this, "name", "cip34"), A(this, "client"), A(this, "httpProviders"), A(this, "events"), A(this, "namespace"), A(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId;
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  setDefaultChain(e, t) {
    this.httpProviders[e] || this.setHttpProvider(e, t), this.chainId = e, this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${this.chainId}`);
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? [...new Set(e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]))] : [];
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      const i = this.getCardanoRPCUrl(t), n = C(t);
      e[n] = this.createHttpProvider(n, i);
    }), e;
  }
  getHttpProvider() {
    const e = `${this.name}:${this.chainId}`, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  getCardanoRPCUrl(e) {
    const t = this.namespace.rpcMap;
    if (t) return t[e];
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || this.getCardanoRPCUrl(e);
    if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
    return new g(new w(i, h("disableProviderPing")));
  }
}
var ds = Object.defineProperty, us = (s, e, t) => e in s ? ds(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, H = (s, e, t) => us(s, typeof e != "symbol" ? e + "" : e, t);
class ms {
  constructor(e) {
    H(this, "name", "elrond"), H(this, "client"), H(this, "httpProviders"), H(this, "events"), H(this, "namespace"), H(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  setDefaultChain(e, t) {
    this.httpProviders[e] || this.setHttpProvider(e, t), this.chainId = e, this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${e}`);
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId;
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? [...new Set(e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]))] : [];
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      var i;
      const n = C(t);
      e[n] = this.createHttpProvider(n, (i = this.namespace.rpcMap) == null ? void 0 : i[t]);
    }), e;
  }
  getHttpProvider() {
    const e = `${this.name}:${this.chainId}`, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || m(e, this.namespace, this.client.core.projectId);
    if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
    return new g(new w(i, h("disableProviderPing")));
  }
}
var fs = Object.defineProperty, vs = (s, e, t) => e in s ? fs(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, S = (s, e, t) => vs(s, typeof e != "symbol" ? e + "" : e, t);
class gs {
  constructor(e) {
    S(this, "name", "multiversx"), S(this, "client"), S(this, "httpProviders"), S(this, "events"), S(this, "namespace"), S(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  setDefaultChain(e, t) {
    this.httpProviders[e] || this.setHttpProvider(e, t), this.chainId = e, this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${e}`);
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId;
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? [...new Set(e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]))] : [];
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      var i;
      const n = C(t);
      e[n] = this.createHttpProvider(n, (i = this.namespace.rpcMap) == null ? void 0 : i[t]);
    }), e;
  }
  getHttpProvider() {
    const e = `${this.name}:${this.chainId}`, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || m(e, this.namespace, this.client.core.projectId);
    if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
    return new g(new w(i, h("disableProviderPing")));
  }
}
var ws = Object.defineProperty, Ps = (s, e, t) => e in s ? ws(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, q = (s, e, t) => Ps(s, typeof e != "symbol" ? e + "" : e, t);
class bs {
  constructor(e) {
    q(this, "name", "near"), q(this, "client"), q(this, "httpProviders"), q(this, "events"), q(this, "namespace"), q(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId;
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  setDefaultChain(e, t) {
    if (this.chainId = e, !this.httpProviders[e]) {
      const i = t || m(`${this.name}:${e}`, this.namespace);
      if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
      this.setHttpProvider(e, i);
    }
    this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${this.chainId}`);
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]) || [] : [];
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      var i;
      e[t] = this.createHttpProvider(t, (i = this.namespace.rpcMap) == null ? void 0 : i[t]);
    }), e;
  }
  getHttpProvider() {
    const e = `${this.name}:${this.chainId}`, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || m(e, this.namespace);
    return typeof i > "u" ? void 0 : new g(new w(i, h("disableProviderPing")));
  }
}
var ys = Object.defineProperty, Cs = (s, e, t) => e in s ? ys(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, N = (s, e, t) => Cs(s, typeof e != "symbol" ? e + "" : e, t);
class Is {
  constructor(e) {
    N(this, "name", "tezos"), N(this, "client"), N(this, "httpProviders"), N(this, "events"), N(this, "namespace"), N(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace = Object.assign(this.namespace, e);
  }
  requestAccounts() {
    return this.getAccounts();
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId;
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider().request(e.request);
  }
  setDefaultChain(e, t) {
    if (this.chainId = e, !this.httpProviders[e]) {
      const i = t || m(`${this.name}:${e}`, this.namespace);
      if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
      this.setHttpProvider(e, i);
    }
    this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${this.chainId}`);
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]) || [] : [];
  }
  createHttpProviders() {
    const e = {};
    return this.namespace.chains.forEach((t) => {
      e[t] = this.createHttpProvider(t);
    }), e;
  }
  getHttpProvider() {
    const e = `${this.name}:${this.chainId}`, t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || m(e, this.namespace);
    return typeof i > "u" ? void 0 : new g(new w(i));
  }
}
var Es = Object.defineProperty, $s = (s, e, t) => e in s ? Es(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, D = (s, e, t) => $s(s, typeof e != "symbol" ? e + "" : e, t);
class Os {
  constructor(e) {
    D(this, "name", _), D(this, "client"), D(this, "httpProviders"), D(this, "events"), D(this, "namespace"), D(this, "chainId"), this.namespace = e.namespace, this.events = h("events"), this.client = h("client"), this.chainId = this.getDefaultChain(), this.httpProviders = this.createHttpProviders();
  }
  updateNamespace(e) {
    this.namespace.chains = [...new Set((this.namespace.chains || []).concat(e.chains || []))], this.namespace.accounts = [...new Set((this.namespace.accounts || []).concat(e.accounts || []))], this.namespace.methods = [...new Set((this.namespace.methods || []).concat(e.methods || []))], this.namespace.events = [...new Set((this.namespace.events || []).concat(e.events || []))], this.httpProviders = this.createHttpProviders();
  }
  requestAccounts() {
    return this.getAccounts();
  }
  request(e) {
    return this.namespace.methods.includes(e.request.method) ? this.client.request(e) : this.getHttpProvider(e.chainId).request(e.request);
  }
  setDefaultChain(e, t) {
    this.httpProviders[e] || this.setHttpProvider(e, t), this.chainId = e, this.events.emit(v.DEFAULT_CHAIN_CHANGED, `${this.name}:${e}`);
  }
  getDefaultChain() {
    if (this.chainId) return this.chainId;
    if (this.namespace.defaultChain) return this.namespace.defaultChain;
    const e = this.namespace.chains[0];
    if (!e) throw new Error("ChainId not found");
    return e.split(":")[1];
  }
  getAccounts() {
    const e = this.namespace.accounts;
    return e ? [...new Set(e.filter((t) => t.split(":")[1] === this.chainId.toString()).map((t) => t.split(":")[2]))] : [];
  }
  createHttpProviders() {
    var e, t;
    const i = {};
    return (t = (e = this.namespace) == null ? void 0 : e.accounts) == null || t.forEach((n) => {
      const a = Ne(n);
      i[`${a.namespace}:${a.reference}`] = this.createHttpProvider(n);
    }), i;
  }
  getHttpProvider(e) {
    const t = this.httpProviders[e];
    if (typeof t > "u") throw new Error(`JSON-RPC provider for ${e} not found`);
    return t;
  }
  setHttpProvider(e, t) {
    const i = this.createHttpProvider(e, t);
    i && (this.httpProviders[e] = i);
  }
  createHttpProvider(e, t) {
    const i = t || m(e, this.namespace, this.client.core.projectId);
    if (!i) throw new Error(`No RPC url provided for chainId: ${e}`);
    return new g(new w(i, h("disableProviderPing")));
  }
}
var js = Object.defineProperty, As = Object.defineProperties, Hs = Object.getOwnPropertyDescriptors, Ae = Object.getOwnPropertySymbols, Ss = Object.prototype.hasOwnProperty, qs = Object.prototype.propertyIsEnumerable, ee = (s, e, t) => e in s ? js(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, F = (s, e) => {
  for (var t in e || (e = {})) Ss.call(e, t) && ee(s, t, e[t]);
  if (Ae) for (var t of Ae(e)) qs.call(e, t) && ee(s, t, e[t]);
  return s;
}, K = (s, e) => As(s, Hs(e)), f = (s, e, t) => ee(s, typeof e != "symbol" ? e + "" : e, t);
let Ns = class ke {
  constructor(e) {
    f(this, "client"), f(this, "namespaces"), f(this, "optionalNamespaces"), f(this, "sessionProperties"), f(this, "scopedProperties"), f(this, "events", new ze()), f(this, "rpcProviders", {}), f(this, "session"), f(this, "providerOpts"), f(this, "logger"), f(this, "uri"), f(this, "disableProviderPing", !1), this.providerOpts = e, this.logger = typeof (e == null ? void 0 : e.logger) < "u" && typeof (e == null ? void 0 : e.logger) != "string" ? e.logger : Qe(Ve({ level: (e == null ? void 0 : e.logger) || ge })), this.disableProviderPing = (e == null ? void 0 : e.disableProviderPing) || !1;
  }
  static async init(e) {
    const t = new ke(e);
    return await t.initialize(), t;
  }
  async request(e, t, i) {
    const [n, a] = this.validateChain(t);
    if (!this.session) throw new Error("Please call connect() before request()");
    return await this.getProvider(n).request({ request: F({}, e), chainId: `${n}:${a}`, topic: this.session.topic, expiry: i });
  }
  sendAsync(e, t, i, n) {
    const a = (/* @__PURE__ */ new Date()).getTime();
    this.request(e, i, n).then((r) => t(null, Ke(a, r))).catch((r) => t(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 e;
    if (!this.session) throw new Error("Please call connect() before enable()");
    await this.client.disconnect({ topic: (e = this.session) == null ? void 0 : e.topic, reason: Y("USER_DISCONNECTED") }), await this.cleanup();
  }
  async connect(e) {
    if (!this.client) throw new Error("Sign Client not initialized");
    if (this.setNamespaces(e), await this.cleanupPendingPairings(), !e.skipPairing) return await this.pair(e.pairingTopic);
  }
  async authenticate(e, t) {
    if (!this.client) throw new Error("Sign Client not initialized");
    this.setNamespaces(e), await this.cleanupPendingPairings();
    const { uri: i, response: n } = await this.client.authenticate(e, t);
    i && (this.uri = i, this.events.emit("display_uri", i));
    const a = await n();
    if (this.session = a.session, this.session) {
      const r = Ee(this.session.namespaces);
      this.namespaces = G(this.namespaces, r), await this.persist("namespaces", this.namespaces), this.onConnect();
    }
    return a;
  }
  on(e, t) {
    this.events.on(e, t);
  }
  once(e, t) {
    this.events.once(e, t);
  }
  removeListener(e, t) {
    this.events.removeListener(e, t);
  }
  off(e, t) {
    this.events.off(e, t);
  }
  get isWalletConnect() {
    return !0;
  }
  async pair(e) {
    const { uri: t, approval: i } = await this.client.connect({ pairingTopic: e, requiredNamespaces: this.namespaces, optionalNamespaces: this.optionalNamespaces, sessionProperties: this.sessionProperties, scopedProperties: this.scopedProperties });
    t && (this.uri = t, this.events.emit("display_uri", t));
    const n = await i();
    this.session = n;
    const a = Ee(n.namespaces);
    return this.namespaces = G(this.namespaces, a), await this.persist("namespaces", this.namespaces), await this.persist("optionalNamespaces", this.optionalNamespaces), this.onConnect(), this.session;
  }
  setDefaultChain(e, t) {
    try {
      if (!this.session) return;
      const [i, n] = this.validateChain(e), a = this.getProvider(i);
      a.name === _ ? a.setDefaultChain(`${i}:${n}`, t) : a.setDefaultChain(n, t);
    } catch (i) {
      if (!/Please call connect/.test(i.message)) throw i;
    }
  }
  async cleanupPendingPairings(e = {}) {
    this.logger.info("Cleaning up inactive pairings...");
    const t = this.client.pairing.getAll();
    if (U(t)) {
      for (const i of t) e.deletePairings ? this.client.core.expirer.set(i.topic, 0) : await this.client.core.relayer.subscriber.unsubscribe(i.topic);
      this.logger.info(`Inactive pairings cleared: ${t.length}`);
    }
  }
  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 e, t;
    if (this.client = this.providerOpts.client || await We.init({ core: this.providerOpts.core, logger: this.providerOpts.logger || ge, relayUrl: this.providerOpts.relayUrl || at, 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 (i) {
      throw this.logger.error("Failed to get session", i), new Error(`The provided session: ${(t = (e = this.providerOpts) == null ? void 0 : e.session) == null ? void 0 : t.topic} doesn't exist in the Sign client`);
    }
    else {
      const i = this.client.session.getAll();
      this.session = i[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 e = [...new Set(Object.keys(this.session.namespaces).map((t) => T(t)))];
    V("client", this.client), V("events", this.events), V("disableProviderPing", this.disableProviderPing), e.forEach((t) => {
      if (!this.session) return;
      const i = zt(t, this.session), n = xe(i), a = G(this.namespaces, this.optionalNamespaces), r = K(F({}, a[t]), { accounts: i, chains: n });
      switch (t) {
        case "eip155":
          this.rpcProviders[t] = new Zt({ namespace: r });
          break;
        case "algorand":
          this.rpcProviders[t] = new cs({ namespace: r });
          break;
        case "solana":
          this.rpcProviders[t] = new ss({ namespace: r });
          break;
        case "cosmos":
          this.rpcProviders[t] = new rs({ namespace: r });
          break;
        case "polkadot":
          this.rpcProviders[t] = new Qt({ namespace: r });
          break;
        case "cip34":
          this.rpcProviders[t] = new ls({ namespace: r });
          break;
        case "elrond":
          this.rpcProviders[t] = new ms({ namespace: r });
          break;
        case "multiversx":
          this.rpcProviders[t] = new gs({ namespace: r });
          break;
        case "near":
          this.rpcProviders[t] = new bs({ namespace: r });
          break;
        case "tezos":
          this.rpcProviders[t] = new Is({ namespace: r });
          break;
        default:
          this.rpcProviders[_] ? this.rpcProviders[_].updateNamespace(r) : this.rpcProviders[_] = new Os({ namespace: r });
      }
    });
  }
  registerEventListeners() {
    if (typeof this.client > "u") throw new Error("Sign Client is not initialized");
    this.client.on("session_ping", (e) => {
      var t;
      const { topic: i } = e;
      i === ((t = this.session) == null ? void 0 : t.topic) && this.events.emit("session_ping", e);
    }), this.client.on("session_event", (e) => {
      var t;
      const { params: i, topic: n } = e;
      if (n !== ((t = this.session) == null ? void 0 : t.topic)) return;
      const { event: a } = i;
      if (a.name === "accountsChanged") {
        const r = a.data;
        r && U(r) && this.events.emit("accountsChanged", r.map(Jt));
      } else if (a.name === "chainChanged") {
        const r = i.chainId, o = i.event.data, c = T(r), p = Q(r) !== Q(o) ? `${c}:${Q(o)}` : r;
        this.onChainChanged(p);
      } else this.events.emit(a.name, a.data);
      this.events.emit("session_event", e);
    }), this.client.on("session_update", ({ topic: e, params: t }) => {
      var i, n;
      if (e !== ((i = this.session) == null ? void 0 : i.topic)) return;
      const { namespaces: a } = t, r = (n = this.client) == null ? void 0 : n.session.get(e);
      this.session = K(F({}, r), { namespaces: a }), this.onSessionUpdate(), this.events.emit("session_update", { topic: e, params: t });
    }), this.client.on("session_delete", async (e) => {
      var t;
      e.topic === ((t = this.session) == null ? void 0 : t.topic) && (await this.cleanup(), this.events.emit("session_delete", e), this.events.emit("disconnect", K(F({}, Y("USER_DISCONNECTED")), { data: e.topic })));
    }), this.on(v.DEFAULT_CHAIN_CHANGED, (e) => {
      this.onChainChanged(e, !0);
    });
  }
  getProvider(e) {
    return this.rpcProviders[e] || this.rpcProviders[_];
  }
  onSessionUpdate() {
    Object.keys(this.rpcProviders).forEach((e) => {
      var t;
      this.getProvider(e).updateNamespace((t = this.session) == null ? void 0 : t.namespaces[e]);
    });
  }
  setNamespaces(e) {
    const { namespaces: t, optionalNamespaces: i, sessionProperties: n, scopedProperties: a } = e;
    t && Object.keys(t).length && (this.namespaces = t), i && Object.keys(i).length && (this.optionalNamespaces = i), this.sessionProperties = n, this.scopedProperties = a;
  }
  validateChain(e) {
    const [t, i] = (e == null ? void 0 : e.split(":")) || ["", ""];
    if (!this.namespaces || !Object.keys(this.namespaces).length) return [t, i];
    if (t && !Object.keys(this.namespaces || {}).map((r) => T(r)).includes(t)) throw new Error(`Namespace '${t}' is not configured. Please call connect() first with namespace config.`);
    if (t && i) return [t, i];
    const n = T(Object.keys(this.namespaces)[0]), a = this.rpcProviders[n].getDefaultChain();
    return [n, a];
  }
  async requestAccounts() {
    const [e] = this.validateChain();
    return await this.getProvider(e).requestAccounts();
  }
  async onChainChanged(e, t = !1) {
    if (!this.namespaces) return;
    const [i, n] = this.validateChain(e);
    n && (t || this.getProvider(i).setDefaultChain(n), this.namespaces[i] ? this.namespaces[i].defaultChain = n : this.namespaces[`${i}:${n}`] ? this.namespaces[`${i}:${n}`].defaultChain = n : this.namespaces[`${i}:${n}`] = { defaultChain: n }, this.events.emit("chainChanged", n), await this.persist("namespaces", this.namespaces));
  }
  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, await this.cleanupPendingPairings({ deletePairings: !0 }), await this.cleanupStorage();
  }
  async persist(e, t) {
    var i;
    const n = ((i = this.session) == null ? void 0 : i.topic) || "";
    await this.client.core.storage.setItem(`${L}/${e}${n}`, t);
  }
  async getFromStore(e) {
    var t;
    const i = ((t = this.session) == null ? void 0 : t.topic) || "";
    return await this.client.core.storage.getItem(`${L}/${e}${i}`);
  }
  async deleteFromStore(e) {
    var t;
    const i = ((t = this.session) == null ? void 0 : t.topic) || "";
    await this.client.core.storage.removeItem(`${L}/${e}${i}`);
  }
  async cleanupStorage() {
    var e;
    try {
      if (((e = this.client) == null ? void 0 : e.session.length) > 0) return;
      const t = await this.client.core.storage.getKeys();
      for (const i of t) i.startsWith(L) && await this.client.core.storage.removeItem(i);
    } catch (t) {
      this.logger.warn("Failed to cleanup storage", t);
    }
  }
};
const Ds = Ns, _s = "wc", Rs = "ethereum_provider", Ms = `${_s}@2:${Rs}:`, Ts = "https://rpc.walletconnect.org/v1/", te = ["eth_sendTransaction", "personal_sign"], Us = ["eth_accounts", "eth_requestAccounts", "eth_sendRawTransaction", "eth_sign", "eth_signTransaction", "eth_signTypedData", "eth_signTypedData_v3", "eth_signTypedData_v4", "eth_sendTransaction", "personal_sign", "wallet_switchEthereumChain", "wallet_addEthereumChain", "wallet_getPermissions", "wallet_requestPermissions", "wallet_registerOnboarding", "wallet_watchAsset", "wallet_scanQRCode", "wallet_sendCalls", "wallet_getCapabilities", "wallet_getCallsStatus", "wallet_showCallsStatus"], se = ["chainChanged", "accountsChanged"], Ls = ["chainChanged", "accountsChanged", "message", "disconnect", "connect"];
var xs = Object.defineProperty, Fs = Object.defineProperties, ks = Object.getOwnPropertyDescriptors, He = Object.getOwnPropertySymbols, zs = Object.prototype.hasOwnProperty, Js = Object.prototype.propertyIsEnumerable, ie = (s, e, t) => e in s ? xs(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, R = (s, e) => {
  for (var t in e || (e = {})) zs.call(e, t) && ie(s, t, e[t]);
  if (He) for (var t of He(e)) Js.call(e, t) && ie(s, t, e[t]);
  return s;
}, W = (s, e) => Fs(s, ks(e)), u = (s, e, t) => ie(s, typeof e != "symbol" ? e + "" : e, t);
function J(s) {
  return Number(s[0].split(":")[1]);
}
function k(s) {
  return `0x${s.toString(16)}`;
}
function Bs(s) {
  const { chains: e, optionalChains: t, methods: i, optionalMethods: n, events: a, optionalEvents: r, rpcMap: o } = s;
  if (!U(e)) throw new Error("Invalid chains");
  const c = { chains: e, methods: i || te, events: a || se, rpcMap: R({}, e.length ? { [J(e)]: o[J(e)] } : {}) }, p = a == null ? void 0 : a.filter((P) => !se.includes(P)), l = i == null ? void 0 : i.filter((P) => !te.includes(P));
  if (!t && !r && !n && !(p != null && p.length) && !(l != null && l.length)) return { required: e.length ? c : void 0 };
  const b = (p == null ? void 0 : p.length) && (l == null ? void 0 : l.length) || !t, d = { chains: [...new Set(b ? c.chains.concat(t || []) : t)], methods: [...new Set(c.methods.concat(n != null && n.length ? n : Us))], events: [...new Set(c.events.concat(r != null && r.length ? r : Ls))], rpcMap: o };
  return { required: e.length ? c : void 0, optional: t.length ? d : void 0 };
}
class ae {
  constructor() {
    u(this, "events", new Se.EventEmitter()), u(this, "namespace", "eip155"), u(this, "accounts", []), u(this, "signer"), u(this, "chainId", 1), u(this, "modal"), u(this, "rpc"), u(this, "STORAGE_KEY", Ms), u(this, "on", (e, t) => (this.events.on(e, t), this)), u(this, "once", (e, t) => (this.events.once(e, t), this)), u(this, "removeListener", (e, t) => (this.events.removeListener(e, t), this)), u(this, "off", (e, t) => (this.events.off(e, t), this)), u(this, "parseAccount", (e) => this.isCompatibleChainId(e) ? this.parseAccountId(e).address : e), this.signer = {}, this.rpc = {};
  }
  static async init(e) {
    const t = new ae();
    return await t.initialize(e), t;
  }
  async request(e, t) {
    return await this.signer.request(e, this.formatChainId(this.chainId), t);
  }
  sendAsync(e, t, i) {
    this.signer.sendAsync(e, t, this.formatChainId(this.chainId), i);
  }
  get connected() {
    return this.signer.client ? this.signer.client.core.relayer.connected : !1;
  }
  get connecting() {
    return this.signer.client ? this.signer.client.core.relayer.connecting : !1;
  }
  async enable() {
    return this.session || await this.connect(), await this.request({ method: "eth_requestAccounts" });
  }
  async connect(e) {
    if (!this.signer.client) throw new Error("Provider not initialized. Call init() first");
    this.loadConnectOpts(e);
    const { required: t, optional: i } = Bs(this.rpc);
    try {
      const n = await new Promise(async (r, o) => {
        var c;
        this.rpc.showQrModal && ((c = this.modal) == null || c.subscribeModal((l) => {
          !l.open && !this.signer.session && (this.signer.abortPairingAttempt(), o(new Error("Connection request reset. Please try again.")));
        }));
        const p = e != null && e.scopedProperties ? { [this.namespace]: e.scopedProperties } : void 0;
        await this.signer.connect(W(R({ namespaces: R({}, t && { [this.namespace]: t }) }, i && { optionalNamespaces: { [this.namespace]: i } }), { pairingTopic: e == null ? void 0 : e.pairingTopic, scopedProperties: p })).then((l) => {
          r(l);
        }).catch((l) => {
          o(new Error(l.message));
        });
      });
      if (!n) return;
      const a = he(n.namespaces, [this.namespace]);
      this.setChainIds(this.rpc.chains.length ? this.rpc.chains : a), this.setAccounts(a), this.events.emit("connect", { chainId: k(this.chainId) });
    } catch (n) {
      throw this.signer.logger.error(n), n;
    } finally {
      this.modal && this.modal.closeModal();
    }
  }
  async authenticate(e, t) {
    if (!this.signer.client) throw new Error("Provider not initialized. Call init() first");
    this.loadConnectOpts({ chains: e == null ? void 0 : e.chains });
    try {
      const i = await new Promise(async (a, r) => {
        var o;
        this.rpc.showQrModal && ((o = this.modal) == null || o.subscribeModal((c) => {
          !c.open && !this.signer.session && (this.signer.abortPairingAttempt(), r(new Error("Connection request reset. Please try again.")));
        })), await this.signer.authenticate(W(R({}, e), { chains: this.rpc.chains }), t).then((c) => {
          a(c);
        }).catch((c) => {
          r(new Error(c.message));
        });
      }), n = i.session;
      if (n) {
        const a = he(n.namespaces, [this.namespace]);
        this.setChainIds(this.rpc.chains.length ? this.rpc.chains : a), this.setAccounts(a), this.events.emit("connect", { chainId: k(this.chainId) });
      }
      return i;
    } catch (i) {
      throw this.signer.logger.error(i), i;
    } finally {
      this.modal && this.modal.closeModal();
    }
  }
  async disconnect() {
    this.session && await this.signer.disconnect(), this.reset();
  }
  get isWalletConnect() {
    return !0;
  }
  get session() {
    return this.signer.session;
  }
  registerEventListeners() {
    this.signer.on("session_event", (e) => {
      const { params: t } = e, { event: i } = t;
      i.name === "accountsChanged" ? (this.accounts = this.parseAccounts(i.data), this.events.emit("accountsChanged", this.accounts)) : i.name === "chainChanged" ? this.setChainId(this.formatChainId(i.data)) : this.events.emit(i.name, i.data), this.events.emit("session_event", e);
    }), this.signer.on("chainChanged", (e) => {
      const t = parseInt(e);
      this.chainId = t, this.events.emit("chainChanged", k(this.chainId)), this.persist();
    }), this.signer.on("session_update", (e) => {
      this.events.emit("session_update", e);
    }), this.signer.on("session_delete", (e) => {
      this.reset(), this.events.emit("session_delete", e), this.events.emit("disconnect", W(R({}, Y("USER_DISCONNECTED")), { data: e.topic, name: "USER_DISCONNECTED" }));
    }), this.signer.on("display_uri", (e) => {
      var t, i;
      this.rpc.showQrModal && ((t = this.modal) == null || t.closeModal(), (i = this.modal) == null || i.openModal({ uri: e })), this.events.emit("display_uri", e);
    });
  }
  switchEthereumChain(e) {
    this.request({ method: "wallet_switchEthereumChain", params: [{ chainId: e.toString(16) }] });
  }
  isCompatibleChainId(e) {
    return typeof e == "string" ? e.startsWith(`${this.namespace}:`) : !1;
  }
  formatChainId(e) {
    return `${this.namespace}:${e}`;
  }
  parseChainId(e) {
    return Number(e.split(":")[1]);
  }
  setChainIds(e) {
    const t = e.filter((i) => this.isCompatibleChainId(i)).map((i) => this.parseChainId(i));
    t.length && (this.chainId = t[0], this.events.emit("chainChanged", k(this.chainId)), this.persist());
  }
  setChainId(e) {
    if (this.isCompatibleChainId(e)) {
      const t = this.parseChainId(e);
      this.chainId = t, this.switchEthereumChain(t);
    }
  }
  parseAccountId(e) {
    const [t, i, n] = e.split(":");
    return { chainId: `${t}:${i}`, address: n };
  }
  setAccounts(e) {
    this.accounts = e.filter((t) => this.parseChainId(this.parseAccountId(t).chainId) === this.chainId).map((t) => this.parseAccountId(t).address), this.events.emit("accountsChanged", this.accounts);
  }
  getRpcConfig(e) {
    var t, i;
    const n = (t = e == null ? void 0 : e.chains) != null ? t : [], a = (i = e == null ? void 0 : e.optionalChains) != null ? i : [], r = n.concat(a);
    if (!r.length) throw new Error("No chains specified in either `chains` or `optionalChains`");
    const o = n.length ? (e == null ? void 0 : e.methods) || te : [], c = n.length ? (e == null ? void 0 : e.events) || se : [], p = (e == null ? void 0 : e.optionalMethods) || [], l = (e == null ? void 0 : e.optionalEvents) || [], b = (e == null ? void 0 : e.rpcMap) || this.buildRpcMap(r, e.projectId), d = (e == null ? void 0 : e.qrModalOptions) || void 0;
    return { chains: n == null ? void 0 : n.map((P) => this.formatChainId(P)), optionalChains: a.map((P) => this.formatChainId(P)), methods: o, events: c, optionalMethods: p, optionalEvents: l, rpcMap: b, showQrModal: !!(e != null && e.showQrModal), qrModalOptions: d, projectId: e.projectId, metadata: e.metadata };
  }
  buildRpcMap(e, t) {
    const i = {};
    return e.forEach((n) => {
      i[n] = this.getRpcUrl(n, t);
    }), i;
  }
  async initialize(e) {
    if (this.rpc = this.getRpcConfig(e), this.chainId = this.rpc.chains.length ? J(this.rpc.chains) : J(this.rpc.optionalChains), this.signer = await Ds.init({ projectId: this.rpc.projectId, metadata: this.rpc.metadata, disableProviderPing: e.disableProviderPing, relayUrl: e.relayUrl, storage: e.storage, storageOptions: e.storageOptions, customStoragePrefix: e.customStoragePrefix, telemetryEnabled: e.telemetryEnabled, logger: e.logger }), this.registerEventListeners(), await this.loadPersistedSession(), this.rpc.showQrModal) {
      let t;
      try {
        const { WalletConnectModal: i } = await import("./index-B9Z8GpEF.js").then((n) => n.i);
        t = i;
      } catch {
        throw new Error("To use QR modal, please install @walletconnect/modal package");
      }
      if (t) try {
        this.modal = new t(R({ projectId: this.rpc.projectId }, this.rpc.qrModalOptions));
      } catch (i) {
        throw this.signer.logger.error(i), new Error("Could not generate WalletConnectModal Instance");
      }
    }
  }
  loadConnectOpts(e) {
    if (!e) return;
    const { chains: t, optionalChains: i, rpcMap: n } = e;
    t && U(t) && (this.rpc.chains = t.map((a) => this.formatChainId(a)), t.forEach((a) => {
      this.rpc.rpcMap[a] = (n == null ? void 0 : n[a]) || this.getRpcUrl(a);
    })), i && U(i) && (this.rpc.optionalChains = [], this.rpc.optionalChains = i == null ? void 0 : i.map((a) => this.formatChainId(a)), i.forEach((a) => {
      this.rpc.rpcMap[a] = (n == null ? void 0 : n[a]) || this.getRpcUrl(a);
    }));
  }
  getRpcUrl(e, t) {
    var i;
    return ((i = this.rpc.rpcMap) == null ? void 0 : i[e]) || `${Ts}?chainId=eip155:${e}&projectId=${t || this.rpc.projectId}`;
  }
  async loadPersistedSession() {
    if (this.session) try {
      const e = await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`), t = this.session.namespaces[`${this.namespace}:${e}`] ? this.session.namespaces[`${this.namespace}:${e}`] : this.session.namespaces[this.namespace];
      this.setChainIds(e ? [this.formatChainId(e)] : t == null ? void 0 : t.accounts), this.setAccounts(t == null ? void 0 : t.accounts);
    } catch (e) {
      this.signer.logger.error("Failed to load persisted session, clearing state..."), this.signer.logger.error(e), await this.disconnect().catch((t) => this.signer.logger.warn(t));
    }
  }
  reset() {
    this.chainId = 1, this.accounts = [];
  }
  persist() {
    this.session && this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`, this.chainId);
  }
  parseAccounts(e) {
    return typeof e == "string" || e instanceof String ? [this.parseAccount(e)] : e.map((t) => this.parseAccount(t));
  }
}
const Ws = ae;
export {
  Ws as EthereumProvider,
  Ls as OPTIONAL_EVENTS,
  Us as OPTIONAL_METHODS,
  se as REQUIRED_EVENTS,
  te as REQUIRED_METHODS,
  ae as default
};
//# sourceMappingURL=index.es-MT7yHhOL.js.map
