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

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,6 +418,28 @@ 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
+ */
421
443
  declare class LedgerConnectorBase implements IConnector {
422
444
  private _deviceManager;
423
445
  private _signerManager;
package/dist/index.d.ts CHANGED
@@ -418,6 +418,28 @@ 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
+ */
421
443
  declare class LedgerConnectorBase implements IConnector {
422
444
  private _deviceManager;
423
445
  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 someErrorInChain(err, matches) {
251
+ function isBleBondInvalidError(err) {
252
252
  const pending = [err];
253
253
  const seen = /* @__PURE__ */ new Set();
254
254
  while (pending.length > 0) {
@@ -256,28 +256,19 @@ function someErrorInChain(err, matches) {
256
256
  if (candidate && typeof candidate === "object" && !seen.has(candidate)) {
257
257
  seen.add(candidate);
258
258
  const e = candidate;
259
- if (matches(e)) return true;
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
+ }
260
267
  pending.push(e.originalError, e.err);
261
268
  }
262
269
  }
263
270
  return false;
264
271
  }
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
- }
281
272
  var PAIRING_FAILURE_TAGS = /* @__PURE__ */ new Set([
282
273
  ERROR_TAG.BlePairingTimeout,
283
274
  ERROR_TAG.BleGattBondingFailed,
@@ -961,7 +952,6 @@ var _LedgerAdapter = class _LedgerAdapter {
961
952
  this._operations = new import_hwk_adapter_core4.OperationRegistry({
962
953
  vendor: "ledger",
963
954
  onEnded: (operation, reason) => {
964
- debugLog("[LedgerAdapter] operation ended", { operationId: operation.operationId, reason });
965
955
  this._discardPendingBinding(this._pendingOperationBindings.get(operation.operationId));
966
956
  this._pendingOperationBindings.delete(operation.operationId);
967
957
  this.emitter.emit(import_hwk_adapter_core4.SDK.OPERATION_ENDED, {
@@ -5070,11 +5060,6 @@ async function _getDeviceApps(ctx, sessionId) {
5070
5060
  };
5071
5061
  return apps;
5072
5062
  }
5073
- function describeCaller(error) {
5074
- return (error.stack ?? "").split("\n").slice(2, 6).map(
5075
- (frame) => frame.trim().replace(/^at /, "").replace(/ \(.*\)$/, "")
5076
- ).join(" <- ");
5077
- }
5078
5063
  var LedgerConnectorBase = class {
5079
5064
  constructor(createTransport, options) {
5080
5065
  this._deviceManager = null;
@@ -5310,7 +5295,6 @@ var LedgerConnectorBase = class {
5310
5295
  _tag: ERROR_TAG.PeerRemovedPairing
5311
5296
  });
5312
5297
  }
5313
- if (isBleNotAdvertisingTimeoutError(err)) throwNotAdvertising();
5314
5298
  const tag = err?._tag;
5315
5299
  if (isKnownConnectionTag(tag) && !isConnectionOpeningTag(tag)) {
5316
5300
  throw err;
@@ -5335,7 +5319,6 @@ var LedgerConnectorBase = class {
5335
5319
  }
5336
5320
  async disconnect(sessionId) {
5337
5321
  if (!this._deviceManager) return;
5338
- debugLog("[DMK] disconnect requested", { sessionId, caller: describeCaller(new Error()) });
5339
5322
  const deviceId = this._deviceManager.getDeviceId(sessionId);
5340
5323
  this._signerManager?.invalidate(sessionId);
5341
5324
  this._unwatchSessionState(sessionId);