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