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