var B = Object.defineProperty;
var S = (e) => {
  throw TypeError(e);
};
var O = (e, t, s) => t in e ? B(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
var l = (e, t, s) => O(e, typeof t != "symbol" ? t + "" : t, s), E = (e, t, s) => t.has(e) || S("Cannot " + s);
var h = (e, t, s) => (E(e, t, "read from private field"), s ? s.call(e) : t.get(e)), u = (e, t, s) => t.has(e) ? S("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), o = (e, t, s, i) => (E(e, t, "write to private field"), i ? i.call(e, s) : t.set(e, s), s);
var F = (e, t, s, i) => ({
  set _(r) {
    o(e, t, r, s);
  },
  get _() {
    return h(e, t, i);
  }
});
import { A as W, d as b, W as $, E as f, P as M, a as R, b as j, c as q, _ as z } from "./index-CSzw0A9y.mjs";
var a, c;
const w = class w extends W {
  /**
   *  Creates a new **NonceManager** to manage %%signer%%.
   */
  constructor(s) {
    super(s.provider);
    /**
     *  The Signer being managed.
     */
    l(this, "signer");
    u(this, a);
    u(this, c);
    b(this, { signer: s }), o(this, a, null), o(this, c, 0);
  }
  async getAddress() {
    return this.signer.getAddress();
  }
  connect(s) {
    return new w(this.signer.connect(s));
  }
  async getNonce(s) {
    if (s === "pending") {
      h(this, a) == null && o(this, a, super.getNonce("pending"));
      const i = h(this, c);
      return await h(this, a) + i;
    }
    return super.getNonce(s);
  }
  /**
   *  Manually increment the nonce. This may be useful when managng
   *  offline transactions.
   */
  increment() {
    F(this, c)._++;
  }
  /**
   *  Resets the nonce, causing the **NonceManager** to reload the current
   *  nonce from the blockchain on the next transaction.
   */
  reset() {
    o(this, c, 0), o(this, a, null);
  }
  async sendTransaction(s) {
    const i = this.getNonce("pending");
    return this.increment(), s = await this.signer.populateTransaction(s), s.nonce = await i, await this.signer.sendTransaction(s);
  }
  signTransaction(s) {
    return this.signer.signTransaction(s);
  }
  signMessage(s) {
    return this.signer.signMessage(s);
  }
  signTypedData(s, i, r) {
    return this.signer.signTypedData(s, i, r);
  }
};
a = new WeakMap(), c = new WeakMap();
let P = w;
async function H(e, t, s) {
  const i = typeof t == "string" ? new $(t, e) : t, r = (s == null ? void 0 : s.chain) ?? (await f.chainFromRpc(e))[1], n = new P(i);
  if (n.provider === null)
    try {
      n.connect(e);
    } catch (g) {
      console.error("Cannot connect to network for signer", g);
    }
  return new I(r, await i.getAddress(), n, s);
}
class I extends M {
  constructor(s, i, r, n) {
    super(s, i, r);
    l(this, "opts");
    this.opts = n;
  }
  chain() {
    return this._chain;
  }
  address() {
    return this._address;
  }
  async sign(s) {
    var v, y, C, x, T, A, G;
    const i = this.chain(), r = [];
    let n = 500000n, g = 100000000000n, m = 1500000000n, p = 100000000n;
    if (((v = this.opts) == null ? void 0 : v.overrides) === void 0 && i !== "Celo") {
      const d = await this._signer.provider.getFeeData();
      g = d.gasPrice ?? g, m = d.maxFeePerGas ?? m, p = d.maxPriorityFeePerGas ?? p;
    }
    ((y = this.opts) == null ? void 0 : y.gasLimit) !== void 0 && (n = this.opts.gasLimit), ((C = this.opts) == null ? void 0 : C.maxGasLimit) !== void 0 && (n = n > ((x = this.opts) == null ? void 0 : x.maxGasLimit) ? (T = this.opts) == null ? void 0 : T.maxGasLimit : n);
    const L = i === "Oasis" ? { gasLimit: n, gasPrice: g, type: 0 } : { gasLimit: n, maxFeePerGas: m, maxPriorityFeePerGas: p };
    for (const d of s) {
      const { transaction: N, description: _ } = d;
      (A = this.opts) != null && A.debug && console.log(`Signing: ${_} for ${this.address()}`);
      const D = {
        ...N,
        ...L,
        from: this.address(),
        nonce: await this._signer.getNonce(),
        // Override any existing values with those passed in the constructor
        ...(G = this.opts) == null ? void 0 : G.overrides
      };
      r.push(await this._signer.signTransaction(D));
    }
    return r;
  }
}
const Q = {
  Address: j,
  Platform: f,
  getSigner: H,
  protocols: {
    WormholeCore: () => import("./index-CSzw0A9y.mjs").then((e) => e.du),
    TokenBridge: () => import("./index-BDREYjeb.mjs"),
    PorticoBridge: () => import("./index-5SNveB_H.mjs"),
    CircleBridge: () => import("./index-_8tHp6ud.mjs")
  },
  getChain: (e, t, s) => new R(t, new f(e, q(e, z, {
    [t]: s
  })))
};
export {
  Q as default
};
