const A = {}, D = {}, N = (t, n) => {
  D[t] = n;
}, e = (t) => {
  class n extends Error {
    constructor(r, s, a) {
      if (super(r || t, a), Object.setPrototypeOf(this, n.prototype), this.name = t, s)
        for (const c in s)
          this[c] = s[c];
      if (a && R(a) && "cause" in a && !("cause" in this)) {
        const c = a.cause;
        this.cause = c, "stack" in c && (this.stack = this.stack + `
CAUSE: ` + c.stack);
      }
    }
  }
  return A[t] = n, n;
};
function R(t) {
  return typeof t == "object";
}
const T = (t) => {
  if (t && typeof t == "object") {
    try {
      if (typeof t.message == "string") {
        const o = JSON.parse(t.message);
        o.message && o.name && (t = o);
      }
    } catch {
    }
    let n;
    if (typeof t.name == "string") {
      const { name: o } = t, r = D[o];
      if (r)
        n = r(t);
      else {
        let s = o === "Error" ? Error : A[o];
        s || (console.warn("deserializing an unknown class '" + o + "'"), s = e(o)), n = Object.create(s.prototype);
        try {
          for (const a in t)
            t.hasOwnProperty(a) && (n[a] = t[a]);
        } catch {
        }
      }
    } else
      typeof t.message == "string" && (n = new Error(t.message));
    return n && !n.stack && Error.captureStackTrace && Error.captureStackTrace(n, T), n;
  }
  return new Error(String(t));
}, _ = (t) => t && (typeof t == "object" ? S(t, []) : typeof t == "function" ? `[Function: ${t.name || "anonymous"}]` : t);
function S(t, n) {
  const o = {};
  n.push(t);
  for (const r of Object.keys(t)) {
    const s = t[r];
    if (typeof s != "function") {
      if (!s || typeof s != "object") {
        o[r] = s;
        continue;
      }
      if (n.indexOf(t[r]) === -1) {
        o[r] = S(t[r], n.slice(0));
        continue;
      }
      o[r] = "[Circular]";
    }
  }
  return typeof t.name == "string" && (o.name = t.name), typeof t.message == "string" && (o.message = t.message), typeof t.stack == "string" && (o.stack = t.stack), o;
}
const U = e("AccountNameRequired"), P = e("AccountNotSupported"), v = e("AccountAwaitingSendPendingOperations"), F = e("AmountRequired"), L = e("BluetoothRequired"), f = e("BtcUnmatchedApp"), y = e("CantOpenDevice"), m = e("CashAddrNotSupported"), w = e("ClaimRewardsFeesWarning"), M = e("CurrencyNotSupported"), b = e("DeviceAppVerifyNotSupported"), B = e("DeviceGenuineSocketEarlyClose"), k = e("DeviceNotGenuine"), G = e("DeviceOnDashboardExpected"), H = e("DeviceOnDashboardUnexpected"), V = e("DeviceInOSUExpected"), W = e("DeviceHalted"), q = e("DeviceNameInvalid"), z = e("DeviceSocketFail"), K = e("DeviceSocketNoBulkStatus"), Y = e("DeviceSocketNoBulkStatus"), j = e("UnresponsiveDeviceError"), X = e("DisconnectedDevice"), $ = e("DisconnectedDeviceDuringOperation"), Q = e("DeviceExtractOnboardingStateError"), J = e("DeviceOnboardingStatePollingError"), Z = e("EnpointConfig"), ee = e("EthAppPleaseEnableContractData"), te = e("FeeEstimationFailed"), ne = e("FirmwareNotRecognized"), oe = e("HardResetFail"), re = e("InvalidXRPTag"), se = e("InvalidAddress"), ae = e("InvalidNonce"), ce = e("InvalidAddressBecauseDestinationIsAlsoSource"), ie = e("LatestMCUInstalledError"), de = e("UnknownMCU"), Ee = e("LedgerAPIError"), ue = e("LedgerAPIErrorWithMessage"), pe = e("LedgerAPINotAvailable"), le = e("ManagerAppAlreadyInstalled"), Ne = e("ManagerAppRelyOnBTC"), ge = e("ManagerAppDepInstallRequired"), Ae = e("ManagerAppDepUninstallRequired"), De = e("ManagerDeviceLocked"), Te = e("ManagerFirmwareNotEnoughSpace"), Se = e("ManagerNotEnoughSpace"), Ie = e("ManagerUninstallBTCDep"), Oe = e("NetworkDown"), he = e("NetworkError"), Ce = e("NoAddressesFound"), xe = e("NotEnoughBalance"), Re = e("NotEnoughBalanceSwap"), _e = e("NotEnoughBalanceToDelegate"), Ue = e("NotEnoughBalanceInParentAccount"), Pe = e("NotEnoughSpendableBalance"), ve = e("NotEnoughBalanceBecauseDestinationNotCreated"), Fe = e("NoAccessToCamera"), Le = e("NotEnoughGas"), fe = e("NotEnoughGasSwap"), ye = e("TronEmptyAccount"), me = e("MaybeKeepTronAccountAlive"), we = e("NotSupportedLegacyAddress"), Me = e("GasLessThanEstimate"), be = e("PriorityFeeTooLow"), Be = e("PriorityFeeTooHigh"), ke = e("PriorityFeeHigherThanMaxFee"), Ge = e("MaxFeeTooLow"), He = e("PasswordsDontMatch"), Ve = e("PasswordIncorrect"), We = e("RecommendSubAccountsToEmpty"), qe = e("RecommendUndelegation"), ze = e("TimeoutTagged"), Ke = e("UnexpectedBootloader"), Ye = e("MCUNotGenuineToDashboard"), je = e("RecipientRequired"), Xe = e("UnavailableTezosOriginatedAccountReceive"), $e = e("UnavailableTezosOriginatedAccountSend"), Qe = e("UpdateFetchFileFail"), Je = e("UpdateIncorrectHash"), Ze = e("UpdateIncorrectSig"), et = e("UpdateYourApp"), tt = e("UserRefusedDeviceNameChange"), nt = e("UserRefusedAddress"), ot = e("UserRefusedFirmwareUpdate"), rt = e("UserRefusedAllowManager"), st = e("UserRefusedOnDevice"), at = e("PinNotSet"), ct = e("ExpertModeRequired"), it = e("TransportOpenUserCancelled"), dt = e("TransportInterfaceNotAvailable"), Et = e("TransportRaceCondition"), ut = e("TransportWebUSBGestureRequired"), pt = e("TransactionHasBeenValidatedError"), lt = e("TransportExchangeTimeoutError"), Nt = e("DeviceShouldStayInApp"), gt = e("WebsocketConnectionError"), At = e("WebsocketConnectionFailed"), Dt = e("WrongDeviceForAccount"), Tt = e("WrongDeviceForAccountPayout"), St = e("WrongDeviceForAccountRefund"), It = e("WrongAppForCurrency"), Ot = e("ETHAddressNonEIP"), ht = e("CantScanQRCode"), Ct = e("FeeNotLoaded"), xt = e("FeeNotLoadedSwap"), Rt = e("FeeRequired"), _t = e("FeeTooHigh"), Ut = e("PendingOperation"), Pt = e("SyncError"), vt = e("PairingFailed"), Ft = e("PeerRemovedPairing"), Lt = e("GenuineCheckFailed"), ft = e("LedgerAPI4xx"), yt = e("LedgerAPI5xx"), mt = e("FirmwareOrAppUpdateRequired"), wt = e("ReplacementTransactionUnderpriced"), Mt = e("OpReturnSizeLimit"), bt = e("DustLimit"), Bt = e("LanguageNotFound"), kt = e("NoDBPathGiven"), Gt = e("DBWrongPassword"), Ht = e("DBNotReset"), Vt = e("SequenceNumberError"), Wt = e("DisabledTransactionBroadcastError");
var l;
(function(t) {
  t.Unknown = "Unknown", t.LocationServicesDisabled = "LocationServicesDisabled", t.LocationServicesUnauthorized = "LocationServicesUnauthorized", t.BluetoothScanStartFailed = "BluetoothScanStartFailed";
})(l || (l = {}));
class g extends Error {
  constructor(n, o) {
    super(o), this.name = "HwTransportError", this.type = n, Object.setPrototypeOf(this, g.prototype);
  }
}
class I extends Error {
  constructor(n, o) {
    const r = "TransportError";
    super(n || r), this.name = r, this.message = n, this.stack = new Error(n).stack, this.id = o;
  }
}
N("TransportError", (t) => new I(t.message, t.id));
const d = {
  ACCESS_CONDITION_NOT_FULFILLED: 38916,
  ALGORITHM_NOT_SUPPORTED: 38020,
  CLA_NOT_SUPPORTED: 28160,
  CODE_BLOCKED: 38976,
  CODE_NOT_INITIALIZED: 38914,
  COMMAND_INCOMPATIBLE_FILE_STRUCTURE: 27009,
  CONDITIONS_OF_USE_NOT_SATISFIED: 27013,
  CONTRADICTION_INVALIDATION: 38928,
  CONTRADICTION_SECRET_CODE_STATUS: 38920,
  DEVICE_IN_RECOVERY_MODE: 26159,
  CUSTOM_IMAGE_EMPTY: 26158,
  FILE_ALREADY_EXISTS: 27273,
  FILE_NOT_FOUND: 37892,
  GP_AUTH_FAILED: 25344,
  HALTED: 28586,
  INCONSISTENT_FILE: 37896,
  INCORRECT_DATA: 27264,
  INCORRECT_LENGTH: 26368,
  INCORRECT_P1_P2: 27392,
  INS_NOT_SUPPORTED: 27904,
  DEVICE_NOT_ONBOARDED: 27911,
  DEVICE_NOT_ONBOARDED_2: 26129,
  INVALID_KCV: 38021,
  INVALID_OFFSET: 37890,
  LICENSING: 28482,
  LOCKED_DEVICE: 21781,
  MAX_VALUE_REACHED: 38992,
  MEMORY_PROBLEM: 37440,
  MISSING_CRITICAL_PARAMETER: 26624,
  NO_EF_SELECTED: 37888,
  NOT_ENOUGH_MEMORY_SPACE: 27268,
  OK: 36864,
  PIN_REMAINING_ATTEMPTS: 25536,
  REFERENCED_DATA_NOT_FOUND: 27272,
  SECURITY_STATUS_NOT_SATISFIED: 27010,
  TECHNICAL_PROBLEM: 28416,
  UNKNOWN_APDU: 27906,
  USER_REFUSED_ON_DEVICE: 21761,
  NOT_ENOUGH_SPACE: 20738,
  APP_NOT_FOUND_OR_INVALID_CONTEXT: 20771,
  INVALID_APP_NAME_LENGTH: 26378,
  GEN_AES_KEY_FAILED: 21529,
  INTERNAL_CRYPTO_OPERATION_FAILED: 21530,
  INTERNAL_COMPUTE_AES_CMAC_FAILED: 21531,
  ENCRYPT_APP_STORAGE_FAILED: 21532,
  INVALID_BACKUP_STATE: 26178,
  PIN_NOT_SET: 21762,
  INVALID_BACKUP_LENGTH: 26419,
  INVALID_RESTORE_STATE: 26179,
  INVALID_CHUNK_LENGTH: 26420,
  INVALID_BACKUP_HEADER: 26698,
  // Not documented:
  TRUSTCHAIN_WRONG_SEED: 45063
};
function O(t) {
  switch (t) {
    // improve text of most common errors
    case 26368:
      return "Incorrect length";
    case 26624:
      return "Missing critical parameter";
    case 27010:
      return "Security not satisfied (dongle locked or have invalid access rights)";
    case 27013:
      return "Condition of use not satisfied (denied by the user?)";
    case 27264:
      return "Invalid data received";
    case 27392:
      return "Invalid parameter received";
    case 21781:
      return "Locked device";
  }
  if (28416 <= t && t <= 28671)
    return "Internal error, please report";
}
class E extends Error {
  /**
   * @param statusCode The error status code coming from a Transport implementation
   * @param options containing:
   *  - canBeMappedToChildError: enable the mapping of TransportStatusError to an error extending/inheriting from it
   *  . Ex: LockedDeviceError. Default to true.
   */
  constructor(n, { canBeMappedToChildError: o = !0 } = {}) {
    const r = Object.keys(d).find((x) => d[x] === n) || "UNKNOWN_ERROR", s = O(n) || r, a = n.toString(16), c = `Ledger device: ${s} (0x${a})`;
    if (super(c), this.name = "TransportStatusError", this.statusCode = n, this.statusText = r, Object.setPrototypeOf(this, E.prototype), o && n === d.LOCKED_DEVICE)
      return new p(c);
  }
}
class p extends E {
  constructor(n) {
    super(d.LOCKED_DEVICE, { canBeMappedToChildError: !1 }), n && (this.message = n), this.name = "LockedDeviceError", Object.setPrototypeOf(this, p.prototype);
  }
}
N("TransportStatusError", (t) => new E(t.statusCode));
const Kt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  AccountAwaitingSendPendingOperations: v,
  AccountNameRequiredError: U,
  AccountNotSupported: P,
  AmountRequired: F,
  BluetoothRequired: L,
  BtcUnmatchedApp: f,
  CantOpenDevice: y,
  CantScanQRCode: ht,
  CashAddrNotSupported: m,
  ClaimRewardsFeesWarning: w,
  CurrencyNotSupported: M,
  DBNotReset: Ht,
  DBWrongPassword: Gt,
  DeviceAppVerifyNotSupported: b,
  DeviceExtractOnboardingStateError: Q,
  DeviceGenuineSocketEarlyClose: B,
  DeviceHalted: W,
  DeviceInOSUExpected: V,
  DeviceNameInvalid: q,
  DeviceNeedsRestart: Y,
  DeviceNotGenuineError: k,
  DeviceOnDashboardExpected: G,
  DeviceOnDashboardUnexpected: H,
  DeviceOnboardingStatePollingError: J,
  DeviceShouldStayInApp: Nt,
  DeviceSocketFail: z,
  DeviceSocketNoBulkStatus: K,
  DisabledTransactionBroadcastError: Wt,
  DisconnectedDevice: X,
  DisconnectedDeviceDuringOperation: $,
  DustLimit: bt,
  ETHAddressNonEIP: Ot,
  EnpointConfigError: Z,
  EthAppPleaseEnableContractData: ee,
  ExpertModeRequired: ct,
  FeeEstimationFailed: te,
  FeeNotLoaded: Ct,
  FeeNotLoadedSwap: xt,
  FeeRequired: Rt,
  FeeTooHigh: _t,
  FirmwareNotRecognized: ne,
  FirmwareOrAppUpdateRequired: mt,
  GasLessThanEstimate: Me,
  GenuineCheckFailed: Lt,
  HardResetFail: oe,
  HwTransportError: g,
  get HwTransportErrorType() {
    return l;
  },
  InvalidAddress: se,
  InvalidAddressBecauseDestinationIsAlsoSource: ce,
  InvalidNonce: ae,
  InvalidXRPTag: re,
  LanguageNotFound: Bt,
  LatestMCUInstalledError: ie,
  LedgerAPI4xx: ft,
  LedgerAPI5xx: yt,
  LedgerAPIError: Ee,
  LedgerAPIErrorWithMessage: ue,
  LedgerAPINotAvailable: pe,
  LockedDeviceError: p,
  MCUNotGenuineToDashboard: Ye,
  ManagerAppAlreadyInstalledError: le,
  ManagerAppDepInstallRequired: ge,
  ManagerAppDepUninstallRequired: Ae,
  ManagerAppRelyOnBTCError: Ne,
  ManagerDeviceLockedError: De,
  ManagerFirmwareNotEnoughSpaceError: Te,
  ManagerNotEnoughSpaceError: Se,
  ManagerUninstallBTCDep: Ie,
  MaxFeeTooLow: Ge,
  MaybeKeepTronAccountAlive: me,
  NetworkDown: Oe,
  NetworkError: he,
  NoAccessToCamera: Fe,
  NoAddressesFound: Ce,
  NoDBPathGiven: kt,
  NotEnoughBalance: xe,
  NotEnoughBalanceBecauseDestinationNotCreated: ve,
  NotEnoughBalanceInParentAccount: Ue,
  NotEnoughBalanceSwap: Re,
  NotEnoughBalanceToDelegate: _e,
  NotEnoughGas: Le,
  NotEnoughGasSwap: fe,
  NotEnoughSpendableBalance: Pe,
  NotSupportedLegacyAddress: we,
  OpReturnDataSizeLimit: Mt,
  PairingFailed: vt,
  PasswordIncorrectError: Ve,
  PasswordsDontMatchError: He,
  PeerRemovedPairing: Ft,
  PendingOperation: Ut,
  PinNotSet: at,
  PriorityFeeHigherThanMaxFee: ke,
  PriorityFeeTooHigh: Be,
  PriorityFeeTooLow: be,
  RecipientRequired: je,
  RecommendSubAccountsToEmpty: We,
  RecommendUndelegation: qe,
  ReplacementTransactionUnderpriced: wt,
  SequenceNumberError: Vt,
  StatusCodes: d,
  SyncError: Pt,
  TimeoutTagged: ze,
  TransactionHasBeenValidatedError: pt,
  TransportError: I,
  TransportExchangeTimeoutError: lt,
  TransportInterfaceNotAvailable: dt,
  TransportOpenUserCancelled: it,
  TransportRaceCondition: Et,
  TransportStatusError: E,
  TransportWebUSBGestureRequired: ut,
  TronEmptyAccount: ye,
  UnavailableTezosOriginatedAccountReceive: Xe,
  UnavailableTezosOriginatedAccountSend: $e,
  UnexpectedBootloader: Ke,
  UnknownMCU: de,
  UnresponsiveDeviceError: j,
  UpdateFetchFileFail: Qe,
  UpdateIncorrectHash: Je,
  UpdateIncorrectSig: Ze,
  UpdateYourApp: et,
  UserRefusedAddress: nt,
  UserRefusedAllowManager: rt,
  UserRefusedDeviceNameChange: tt,
  UserRefusedFirmwareUpdate: ot,
  UserRefusedOnDevice: st,
  WebsocketConnectionError: gt,
  WebsocketConnectionFailed: At,
  WrongAppForCurrency: It,
  WrongDeviceForAccount: Dt,
  WrongDeviceForAccountPayout: Tt,
  WrongDeviceForAccountRefund: St,
  addCustomErrorDeserializer: N,
  createCustomErrorClass: e,
  deserializeError: T,
  getAltStatusMessage: O,
  serializeError: _
}, Symbol.toStringTag, { value: "Module" }));
let h = 0;
const i = [], Yt = (t, n, o) => {
  const r = {
    type: t,
    id: String(++h),
    date: /* @__PURE__ */ new Date()
  };
  n && (r.message = n), C(r);
}, qt = ({ type: t, message: n, data: o, context: r }) => {
  const s = {
    type: t,
    id: String(++h),
    date: /* @__PURE__ */ new Date()
  };
  n && (s.message = n), o && (s.data = o), r && (s.context = r), C(s);
};
class u {
  constructor(n, o) {
    this.type = n, this.context = o;
  }
  trace(n, o) {
    qt({
      type: this.type,
      message: n,
      data: o,
      context: this.context
    });
  }
  getContext() {
    return this.context;
  }
  setContext(n) {
    this.context = n;
  }
  updateContext(n) {
    this.context = Object.assign(Object.assign({}, this.context), n);
  }
  getType() {
    return this.type;
  }
  setType(n) {
    this.type = n;
  }
  /**
   * Create a new instance of the LocalTracer with an updated `type`
   *
   * It does not mutate the calling instance, but returns a new LocalTracer,
   * following a simple builder pattern.
   */
  withType(n) {
    return new u(n, this.context);
  }
  /**
   * Create a new instance of the LocalTracer with a new `context`
   *
   * It does not mutate the calling instance, but returns a new LocalTracer,
   * following a simple builder pattern.
   *
   * @param context A TraceContext, that can undefined to reset the context
   */
  withContext(n) {
    return new u(this.type, n);
  }
  /**
   * Create a new instance of the LocalTracer with an updated `context`,
   * on which an additional context is merged with the existing one.
   *
   * It does not mutate the calling instance, but returns a new LocalTracer,
   * following a simple builder pattern.
   */
  withUpdatedContext(n) {
    return new u(this.type, Object.assign(Object.assign({}, this.context), n));
  }
}
const zt = (t) => (i.push(t), () => {
  const n = i.indexOf(t);
  n !== -1 && (i[n] = i[i.length - 1], i.pop());
});
function C(t) {
  for (let n = 0; n < i.length; n++)
    try {
      i[n](t);
    } catch (o) {
      console.error(o);
    }
}
typeof window < "u" && (window.__ledgerLogsListen = zt);
export {
  $ as D,
  u as L,
  d as S,
  I as T,
  E as a,
  Et as b,
  Yt as c,
  it as d,
  X as e,
  T as f,
  Kt as l,
  _ as s
};
//# sourceMappingURL=index-CsusZbUF.js.map
