@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.d.mts CHANGED
@@ -418,28 +418,6 @@ interface LedgerConnectorBaseOptions {
418
418
  */
419
419
  dmk?: DeviceManagementKit;
420
420
  }
421
- /**
422
- * Shared base class for Ledger IConnector implementations.
423
- *
424
- * Encapsulates all shared logic: device discovery, connection management,
425
- * method dispatch (EVM / BTC / SOL / TRON), signer lifecycle, event emission,
426
- * and error handling.
427
- *
428
- * Chain-specific method implementations live in `./chains/` and receive
429
- * a ConnectorContext that exposes shared helpers.
430
- *
431
- * Subclasses only need to:
432
- * 1. Supply a transport factory via the constructor.
433
- * 2. Optionally override `_resolveConnectId()` for transport-specific
434
- * device identity resolution.
435
- *
436
- * Invariant: one instance = one transport. `connectionType` is fixed at
437
- * construction. To switch transport (e.g. desktop BLE ↔ WebHID), the host
438
- * must build a new connector instance and replace the old one — don't add
439
- * multiple transports to a single instance. Lifting this constraint would
440
- * require routing `connectionType` from `descriptor.transport` per-device
441
- * and updating every `this.connectionType` branch in this file.
442
- */
443
421
  declare class LedgerConnectorBase implements IConnector {
444
422
  private _deviceManager;
445
423
  private _signerManager;
package/dist/index.d.ts CHANGED
@@ -418,28 +418,6 @@ interface LedgerConnectorBaseOptions {
418
418
  */
419
419
  dmk?: DeviceManagementKit;
420
420
  }
421
- /**
422
- * Shared base class for Ledger IConnector implementations.
423
- *
424
- * Encapsulates all shared logic: device discovery, connection management,
425
- * method dispatch (EVM / BTC / SOL / TRON), signer lifecycle, event emission,
426
- * and error handling.
427
- *
428
- * Chain-specific method implementations live in `./chains/` and receive
429
- * a ConnectorContext that exposes shared helpers.
430
- *
431
- * Subclasses only need to:
432
- * 1. Supply a transport factory via the constructor.
433
- * 2. Optionally override `_resolveConnectId()` for transport-specific
434
- * device identity resolution.
435
- *
436
- * Invariant: one instance = one transport. `connectionType` is fixed at
437
- * construction. To switch transport (e.g. desktop BLE ↔ WebHID), the host
438
- * must build a new connector instance and replace the old one — don't add
439
- * multiple transports to a single instance. Lifting this constraint would
440
- * require routing `connectionType` from `descriptor.transport` per-device
441
- * and updating every `this.connectionType` branch in this file.
442
- */
443
421
  declare class LedgerConnectorBase implements IConnector {
444
422
  private _deviceManager;
445
423
  private _signerManager;
package/dist/index.js CHANGED
@@ -248,7 +248,7 @@ function isDeviceNotAdvertisingError(err) {
248
248
  if (!err || typeof err !== "object") return false;
249
249
  return err._tag === ERROR_TAG.DeviceNotAdvertising;
250
250
  }
251
- function isBleBondInvalidError(err) {
251
+ function someErrorInChain(err, matches) {
252
252
  const pending = [err];
253
253
  const seen = /* @__PURE__ */ new Set();
254
254
  while (pending.length > 0) {
@@ -256,19 +256,28 @@ function isBleBondInvalidError(err) {
256
256
  if (candidate && typeof candidate === "object" && !seen.has(candidate)) {
257
257
  seen.add(candidate);
258
258
  const e = candidate;
259
- if (e._tag === ERROR_TAG.PeerRemovedPairing || e.iosErrorCode === 14 || e.attErrorCode === 5 || e.nativeErrorDomain === "CBErrorDomain" && e.nativeErrorCode === 14) {
260
- return true;
261
- }
262
- const reason = typeof e.reason === "string" ? e.reason : "";
263
- const message = typeof e.message === "string" ? e.message : "";
264
- if (/\bCBErrorDomain:14(?:\s|$)/.test(message) || reason.includes("Peer removed pairing information") || reason.includes("GATT_INSUF_AUTHENTICATION")) {
265
- return true;
266
- }
259
+ if (matches(e)) return true;
267
260
  pending.push(e.originalError, e.err);
268
261
  }
269
262
  }
270
263
  return false;
271
264
  }
265
+ function isBleBondInvalidError(err) {
266
+ return someErrorInChain(err, (e) => {
267
+ if (e._tag === ERROR_TAG.PeerRemovedPairing || e.iosErrorCode === 14 || e.attErrorCode === 5 || e.nativeErrorDomain === "CBErrorDomain" && e.nativeErrorCode === 14) {
268
+ return true;
269
+ }
270
+ const reason = typeof e.reason === "string" ? e.reason : "";
271
+ const message = typeof e.message === "string" ? e.message : "";
272
+ 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");
273
+ });
274
+ }
275
+ function isBleNotAdvertisingTimeoutError(err) {
276
+ return someErrorInChain(
277
+ err,
278
+ (e) => typeof e.message === "string" && /connect timed out after \d+ms: device not advertising$/.test(e.message)
279
+ );
280
+ }
272
281
  var PAIRING_FAILURE_TAGS = /* @__PURE__ */ new Set([
273
282
  ERROR_TAG.BlePairingTimeout,
274
283
  ERROR_TAG.BleGattBondingFailed,
@@ -952,6 +961,7 @@ var _LedgerAdapter = class _LedgerAdapter {
952
961
  this._operations = new import_hwk_adapter_core4.OperationRegistry({
953
962
  vendor: "ledger",
954
963
  onEnded: (operation, reason) => {
964
+ debugLog("[LedgerAdapter] operation ended", { operationId: operation.operationId, reason });
955
965
  this._discardPendingBinding(this._pendingOperationBindings.get(operation.operationId));
956
966
  this._pendingOperationBindings.delete(operation.operationId);
957
967
  this.emitter.emit(import_hwk_adapter_core4.SDK.OPERATION_ENDED, {
@@ -5060,6 +5070,11 @@ async function _getDeviceApps(ctx, sessionId) {
5060
5070
  };
5061
5071
  return apps;
5062
5072
  }
5073
+ function describeCaller(error) {
5074
+ return (error.stack ?? "").split("\n").slice(2, 6).map(
5075
+ (frame) => frame.trim().replace(/^at /, "").replace(/ \(.*\)$/, "")
5076
+ ).join(" <- ");
5077
+ }
5063
5078
  var LedgerConnectorBase = class {
5064
5079
  constructor(createTransport, options) {
5065
5080
  this._deviceManager = null;
@@ -5295,6 +5310,7 @@ var LedgerConnectorBase = class {
5295
5310
  _tag: ERROR_TAG.PeerRemovedPairing
5296
5311
  });
5297
5312
  }
5313
+ if (isBleNotAdvertisingTimeoutError(err)) throwNotAdvertising();
5298
5314
  const tag = err?._tag;
5299
5315
  if (isKnownConnectionTag(tag) && !isConnectionOpeningTag(tag)) {
5300
5316
  throw err;
@@ -5319,6 +5335,7 @@ var LedgerConnectorBase = class {
5319
5335
  }
5320
5336
  async disconnect(sessionId) {
5321
5337
  if (!this._deviceManager) return;
5338
+ debugLog("[DMK] disconnect requested", { sessionId, caller: describeCaller(new Error()) });
5322
5339
  const deviceId = this._deviceManager.getDeviceId(sessionId);
5323
5340
  this._signerManager?.invalidate(sessionId);
5324
5341
  this._unwatchSessionState(sessionId);