const p = "logger/5.7.0";
let T = !1, O = !1;
const I = { debug: 1, default: 2, info: 2, warning: 3, error: 4, off: 5 };
let S = I.default, w = null;
function C() {
  try {
    const t = [];
    if (["NFD", "NFC", "NFKD", "NFKC"].forEach((r) => {
      try {
        if ("test".normalize(r) !== "test")
          throw new Error("bad normalize");
      } catch {
        t.push(r);
      }
    }), t.length)
      throw new Error("missing " + t.join(", "));
    if ("é".normalize("NFD") !== "é")
      throw new Error("broken implementation");
  } catch (t) {
    return t.message;
  }
  return null;
}
const x = C();
var P;
(function(t) {
  t.DEBUG = "DEBUG", t.INFO = "INFO", t.WARNING = "WARNING", t.ERROR = "ERROR", t.OFF = "OFF";
})(P || (P = {}));
var c;
(function(t) {
  t.UNKNOWN_ERROR = "UNKNOWN_ERROR", t.NOT_IMPLEMENTED = "NOT_IMPLEMENTED", t.UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION", t.NETWORK_ERROR = "NETWORK_ERROR", t.SERVER_ERROR = "SERVER_ERROR", t.TIMEOUT = "TIMEOUT", t.BUFFER_OVERRUN = "BUFFER_OVERRUN", t.NUMERIC_FAULT = "NUMERIC_FAULT", t.MISSING_NEW = "MISSING_NEW", t.INVALID_ARGUMENT = "INVALID_ARGUMENT", t.MISSING_ARGUMENT = "MISSING_ARGUMENT", t.UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT", t.CALL_EXCEPTION = "CALL_EXCEPTION", t.INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS", t.NONCE_EXPIRED = "NONCE_EXPIRED", t.REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED", t.UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT", t.TRANSACTION_REPLACED = "TRANSACTION_REPLACED", t.ACTION_REJECTED = "ACTION_REJECTED";
})(c || (c = {}));
const b = "0123456789abcdef";
class s {
  constructor(r) {
    Object.defineProperty(this, "version", {
      enumerable: !0,
      value: r,
      writable: !1
    });
  }
  _log(r, e) {
    const n = r.toLowerCase();
    I[n] == null && this.throwArgumentError("invalid log level name", "logLevel", r), !(S > I[n]) && console.log.apply(console, e);
  }
  debug(...r) {
    this._log(s.levels.DEBUG, r);
  }
  info(...r) {
    this._log(s.levels.INFO, r);
  }
  warn(...r) {
    this._log(s.levels.WARNING, r);
  }
  makeError(r, e, n) {
    if (O)
      return this.makeError("censored error", e, {});
    e || (e = s.errors.UNKNOWN_ERROR), n || (n = {});
    const i = [];
    Object.keys(n).forEach((f) => {
      const N = n[f];
      try {
        if (N instanceof Uint8Array) {
          let A = "";
          for (let m = 0; m < N.length; m++)
            A += b[N[m] >> 4], A += b[N[m] & 15];
          i.push(f + "=Uint8Array(0x" + A + ")");
        } else
          i.push(f + "=" + JSON.stringify(N));
      } catch {
        i.push(f + "=" + JSON.stringify(n[f].toString()));
      }
    }), i.push(`code=${e}`), i.push(`version=${this.version}`);
    const E = r;
    let a = "";
    switch (e) {
      case c.NUMERIC_FAULT: {
        a = "NUMERIC_FAULT";
        const f = r;
        switch (f) {
          case "overflow":
          case "underflow":
          case "division-by-zero":
            a += "-" + f;
            break;
          case "negative-power":
          case "negative-width":
            a += "-unsupported";
            break;
          case "unbound-bitwise-result":
            a += "-unbound-result";
            break;
        }
        break;
      }
      case c.CALL_EXCEPTION:
      case c.INSUFFICIENT_FUNDS:
      case c.MISSING_NEW:
      case c.NONCE_EXPIRED:
      case c.REPLACEMENT_UNDERPRICED:
      case c.TRANSACTION_REPLACED:
      case c.UNPREDICTABLE_GAS_LIMIT:
        a = e;
        break;
    }
    a && (r += " [ See: https://links.ethers.org/v5-errors-" + a + " ]"), i.length && (r += " (" + i.join(", ") + ")");
    const R = new Error(r);
    return R.reason = E, R.code = e, Object.keys(n).forEach(function(f) {
      R[f] = n[f];
    }), R;
  }
  throwError(r, e, n) {
    throw this.makeError(r, e, n);
  }
  throwArgumentError(r, e, n) {
    return this.throwError(r, s.errors.INVALID_ARGUMENT, {
      argument: e,
      value: n
    });
  }
  assert(r, e, n, i) {
    r || this.throwError(e, n, i);
  }
  assertArgument(r, e, n, i) {
    r || this.throwArgumentError(e, n, i);
  }
  checkNormalize(r) {
    x && this.throwError("platform missing String.prototype.normalize", s.errors.UNSUPPORTED_OPERATION, {
      operation: "String.prototype.normalize",
      form: x
    });
  }
  checkSafeUint53(r, e) {
    typeof r == "number" && (e == null && (e = "value not safe"), (r < 0 || r >= 9007199254740991) && this.throwError(e, s.errors.NUMERIC_FAULT, {
      operation: "checkSafeInteger",
      fault: "out-of-safe-range",
      value: r
    }), r % 1 && this.throwError(e, s.errors.NUMERIC_FAULT, {
      operation: "checkSafeInteger",
      fault: "non-integer",
      value: r
    }));
  }
  checkArgumentCount(r, e, n) {
    n ? n = ": " + n : n = "", r < e && this.throwError("missing argument" + n, s.errors.MISSING_ARGUMENT, {
      count: r,
      expectedCount: e
    }), r > e && this.throwError("too many arguments" + n, s.errors.UNEXPECTED_ARGUMENT, {
      count: r,
      expectedCount: e
    });
  }
  checkNew(r, e) {
    (r === Object || r == null) && this.throwError("missing new", s.errors.MISSING_NEW, { name: e.name });
  }
  checkAbstract(r, e) {
    r === e ? this.throwError("cannot instantiate abstract class " + JSON.stringify(e.name) + " directly; use a sub-class", s.errors.UNSUPPORTED_OPERATION, { name: r.name, operation: "new" }) : (r === Object || r == null) && this.throwError("missing new", s.errors.MISSING_NEW, { name: e.name });
  }
  static globalLogger() {
    return w || (w = new s(p)), w;
  }
  static setCensorship(r, e) {
    if (!r && e && this.globalLogger().throwError("cannot permanently disable censorship", s.errors.UNSUPPORTED_OPERATION, {
      operation: "setCensorship"
    }), T) {
      if (!r)
        return;
      this.globalLogger().throwError("error censorship permanent", s.errors.UNSUPPORTED_OPERATION, {
        operation: "setCensorship"
      });
    }
    O = !!r, T = !!e;
  }
  static setLogLevel(r) {
    const e = I[r.toLowerCase()];
    if (e == null) {
      s.globalLogger().warn("invalid log level - " + r);
      return;
    }
    S = e;
  }
  static from(r) {
    return new s(r);
  }
}
s.errors = c;
s.levels = P;
const M = "bytes/5.7.0", o = new s(M);
function D(t) {
  return !!t.toHexString;
}
function u(t) {
  return t.slice || (t.slice = function() {
    const r = Array.prototype.slice.call(arguments);
    return u(new Uint8Array(Array.prototype.slice.apply(t, r)));
  }), t;
}
function F(t) {
  return h(t) && !(t.length % 2) || y(t);
}
function v(t) {
  return typeof t == "number" && t == t && t % 1 === 0;
}
function y(t) {
  if (t == null)
    return !1;
  if (t.constructor === Uint8Array)
    return !0;
  if (typeof t == "string" || !v(t.length) || t.length < 0)
    return !1;
  for (let r = 0; r < t.length; r++) {
    const e = t[r];
    if (!v(e) || e < 0 || e >= 256)
      return !1;
  }
  return !0;
}
function g(t, r) {
  if (r || (r = {}), typeof t == "number") {
    o.checkSafeUint53(t, "invalid arrayify value");
    const e = [];
    for (; t; )
      e.unshift(t & 255), t = parseInt(String(t / 256));
    return e.length === 0 && e.push(0), u(new Uint8Array(e));
  }
  if (r.allowMissingPrefix && typeof t == "string" && t.substring(0, 2) !== "0x" && (t = "0x" + t), D(t) && (t = t.toHexString()), h(t)) {
    let e = t.substring(2);
    e.length % 2 && (r.hexPad === "left" ? e = "0" + e : r.hexPad === "right" ? e += "0" : o.throwArgumentError("hex data is odd-length", "value", t));
    const n = [];
    for (let i = 0; i < e.length; i += 2)
      n.push(parseInt(e.substring(i, i + 2), 16));
    return u(new Uint8Array(n));
  }
  return y(t) ? u(new Uint8Array(t)) : o.throwArgumentError("invalid arrayify value", "value", t);
}
function d(t) {
  const r = t.map((i) => g(i)), e = r.reduce((i, E) => i + E.length, 0), n = new Uint8Array(e);
  return r.reduce((i, E) => (n.set(E, i), i + E.length), 0), u(n);
}
function G(t, r) {
  t = g(t), t.length > r && o.throwArgumentError("value out of range", "value", arguments[0]);
  const e = new Uint8Array(r);
  return e.set(t, r - t.length), u(e);
}
function h(t, r) {
  return !(typeof t != "string" || !t.match(/^0x[0-9A-Fa-f]*$/) || r && t.length !== 2 + 2 * r);
}
const U = "0123456789abcdef";
function l(t, r) {
  if (r || (r = {}), typeof t == "number") {
    o.checkSafeUint53(t, "invalid hexlify value");
    let e = "";
    for (; t; )
      e = U[t & 15] + e, t = Math.floor(t / 16);
    return e.length ? (e.length % 2 && (e = "0" + e), "0x" + e) : "0x00";
  }
  if (typeof t == "bigint")
    return t = t.toString(16), t.length % 2 ? "0x0" + t : "0x" + t;
  if (r.allowMissingPrefix && typeof t == "string" && t.substring(0, 2) !== "0x" && (t = "0x" + t), D(t))
    return t.toHexString();
  if (h(t))
    return t.length % 2 && (r.hexPad === "left" ? t = "0x0" + t.substring(2) : r.hexPad === "right" ? t += "0" : o.throwArgumentError("hex data is odd-length", "value", t)), t.toLowerCase();
  if (y(t)) {
    let e = "0x";
    for (let n = 0; n < t.length; n++) {
      let i = t[n];
      e += U[(i & 240) >> 4] + U[i & 15];
    }
    return e;
  }
  return o.throwArgumentError("invalid hexlify value", "value", t);
}
function L(t, r, e) {
  return typeof t != "string" ? t = l(t) : (!h(t) || t.length % 2) && o.throwArgumentError("invalid hexData", "value", t), r = 2 + 2 * r, "0x" + t.substring(r, 2 + 2 * e);
}
function k(t) {
  let r = "0x";
  return t.forEach((e) => {
    r += l(e).substring(2);
  }), r;
}
function _(t, r) {
  for (typeof t != "string" ? t = l(t) : h(t) || o.throwArgumentError("invalid hex string", "value", t), t.length > 2 * r + 2 && o.throwArgumentError("value out of range", "value", arguments[1]); t.length < 2 * r + 2; )
    t = "0x0" + t.substring(2);
  return t;
}
function W(t) {
  const r = {
    r: "0x",
    s: "0x",
    _vs: "0x",
    recoveryParam: 0,
    v: 0,
    yParityAndS: "0x",
    compact: "0x"
  };
  if (F(t)) {
    let e = g(t);
    e.length === 64 ? (r.v = 27 + (e[32] >> 7), e[32] &= 127, r.r = l(e.slice(0, 32)), r.s = l(e.slice(32, 64))) : e.length === 65 ? (r.r = l(e.slice(0, 32)), r.s = l(e.slice(32, 64)), r.v = e[64]) : o.throwArgumentError("invalid signature string", "signature", t), r.v < 27 && (r.v === 0 || r.v === 1 ? r.v += 27 : o.throwArgumentError("signature invalid v byte", "signature", t)), r.recoveryParam = 1 - r.v % 2, r.recoveryParam && (e[32] |= 128), r._vs = l(e.slice(32, 64));
  } else {
    if (r.r = t.r, r.s = t.s, r.v = t.v, r.recoveryParam = t.recoveryParam, r._vs = t._vs, r._vs != null) {
      const i = G(g(r._vs), 32);
      r._vs = l(i);
      const E = i[0] >= 128 ? 1 : 0;
      r.recoveryParam == null ? r.recoveryParam = E : r.recoveryParam !== E && o.throwArgumentError("signature recoveryParam mismatch _vs", "signature", t), i[0] &= 127;
      const a = l(i);
      r.s == null ? r.s = a : r.s !== a && o.throwArgumentError("signature v mismatch _vs", "signature", t);
    }
    if (r.recoveryParam == null)
      r.v == null ? o.throwArgumentError("signature missing v and recoveryParam", "signature", t) : r.v === 0 || r.v === 1 ? r.recoveryParam = r.v : r.recoveryParam = 1 - r.v % 2;
    else if (r.v == null)
      r.v = 27 + r.recoveryParam;
    else {
      const i = r.v === 0 || r.v === 1 ? r.v : 1 - r.v % 2;
      r.recoveryParam !== i && o.throwArgumentError("signature recoveryParam mismatch v", "signature", t);
    }
    r.r == null || !h(r.r) ? o.throwArgumentError("signature missing or invalid r", "signature", t) : r.r = _(r.r, 32), r.s == null || !h(r.s) ? o.throwArgumentError("signature missing or invalid s", "signature", t) : r.s = _(r.s, 32);
    const e = g(r.s);
    e[0] >= 128 && o.throwArgumentError("signature s out of range", "signature", t), r.recoveryParam && (e[0] |= 128);
    const n = l(e);
    r._vs && (h(r._vs) || o.throwArgumentError("signature invalid _vs", "signature", t), r._vs = _(r._vs, 32)), r._vs == null ? r._vs = n : r._vs !== n && o.throwArgumentError("signature _vs mismatch v and s", "signature", t);
  }
  return r.yParityAndS = r._vs, r.compact = r.r + r.yParityAndS.substring(2), r;
}
export {
  s as L,
  g as a,
  h as b,
  d as c,
  k as d,
  _ as e,
  L as f,
  l as h,
  y as i,
  W as s
};
