@onekeyfe/hwk-ledger-adapter 1.2.10-alpha.2 → 1.2.10-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -225,7 +225,7 @@ function isDeviceNotAdvertisingError(err) {
225
225
  if (!err || typeof err !== "object") return false;
226
226
  return err._tag === ERROR_TAG.DeviceNotAdvertising;
227
227
  }
228
- function isBleBondInvalidError(err) {
228
+ function someErrorInChain(err, matches) {
229
229
  const pending = [err];
230
230
  const seen = /* @__PURE__ */ new Set();
231
231
  while (pending.length > 0) {
@@ -233,19 +233,28 @@ function isBleBondInvalidError(err) {
233
233
  if (candidate && typeof candidate === "object" && !seen.has(candidate)) {
234
234
  seen.add(candidate);
235
235
  const e = candidate;
236
- if (e._tag === ERROR_TAG.PeerRemovedPairing || e.iosErrorCode === 14 || e.attErrorCode === 5 || e.nativeErrorDomain === "CBErrorDomain" && e.nativeErrorCode === 14) {
237
- return true;
238
- }
239
- const reason = typeof e.reason === "string" ? e.reason : "";
240
- const message = typeof e.message === "string" ? e.message : "";
241
- if (/\bCBErrorDomain:14(?:\s|$)/.test(message) || reason.includes("Peer removed pairing information") || reason.includes("GATT_INSUF_AUTHENTICATION")) {
242
- return true;
243
- }
236
+ if (matches(e)) return true;
244
237
  pending.push(e.originalError, e.err);
245
238
  }
246
239
  }
247
240
  return false;
248
241
  }
242
+ function isBleBondInvalidError(err) {
243
+ return someErrorInChain(err, (e) => {
244
+ if (e._tag === ERROR_TAG.PeerRemovedPairing || e.iosErrorCode === 14 || e.attErrorCode === 5 || e.nativeErrorDomain === "CBErrorDomain" && e.nativeErrorCode === 14) {
245
+ return true;
246
+ }
247
+ const reason = typeof e.reason === "string" ? e.reason : "";
248
+ const message = typeof e.message === "string" ? e.message : "";
249
+ return /\bCBErrorDomain:14(?:\s|$)/.test(message) || /'\$onekey-3p-ble-subscribe': Error: status: 3$/.test(message) || reason.includes("Peer removed pairing information") || reason.includes("GATT_INSUF_AUTHENTICATION");
250
+ });
251
+ }
252
+ function isBleNotAdvertisingTimeoutError(err) {
253
+ return someErrorInChain(
254
+ err,
255
+ (e) => typeof e.message === "string" && /connect timed out after \d+ms: device not advertising$/.test(e.message)
256
+ );
257
+ }
249
258
  var PAIRING_FAILURE_TAGS = /* @__PURE__ */ new Set([
250
259
  ERROR_TAG.BlePairingTimeout,
251
260
  ERROR_TAG.BleGattBondingFailed,
@@ -939,6 +948,7 @@ var _LedgerAdapter = class _LedgerAdapter {
939
948
  this._operations = new OperationRegistry({
940
949
  vendor: "ledger",
941
950
  onEnded: (operation, reason) => {
951
+ debugLog("[LedgerAdapter] operation ended", { operationId: operation.operationId, reason });
942
952
  this._discardPendingBinding(this._pendingOperationBindings.get(operation.operationId));
943
953
  this._pendingOperationBindings.delete(operation.operationId);
944
954
  this.emitter.emit(SDK.OPERATION_ENDED, {
@@ -5053,6 +5063,11 @@ async function _getDeviceApps(ctx, sessionId) {
5053
5063
  };
5054
5064
  return apps;
5055
5065
  }
5066
+ function describeCaller(error) {
5067
+ return (error.stack ?? "").split("\n").slice(2, 6).map(
5068
+ (frame) => frame.trim().replace(/^at /, "").replace(/ \(.*\)$/, "")
5069
+ ).join(" <- ");
5070
+ }
5056
5071
  var LedgerConnectorBase = class {
5057
5072
  constructor(createTransport, options) {
5058
5073
  this._deviceManager = null;
@@ -5288,6 +5303,7 @@ var LedgerConnectorBase = class {
5288
5303
  _tag: ERROR_TAG.PeerRemovedPairing
5289
5304
  });
5290
5305
  }
5306
+ if (isBleNotAdvertisingTimeoutError(err)) throwNotAdvertising();
5291
5307
  const tag = err?._tag;
5292
5308
  if (isKnownConnectionTag(tag) && !isConnectionOpeningTag(tag)) {
5293
5309
  throw err;
@@ -5312,6 +5328,7 @@ var LedgerConnectorBase = class {
5312
5328
  }
5313
5329
  async disconnect(sessionId) {
5314
5330
  if (!this._deviceManager) return;
5331
+ debugLog("[DMK] disconnect requested", { sessionId, caller: describeCaller(new Error()) });
5315
5332
  const deviceId = this._deviceManager.getDeviceId(sessionId);
5316
5333
  this._signerManager?.invalidate(sessionId);
5317
5334
  this._unwatchSessionState(sessionId);