@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.13 → 1.1.26-alpha.15

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
@@ -1,4 +1,4 @@
1
- import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, DeviceDescriptor, DeviceChangeEvent, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, Failure, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
1
+ import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, DeviceDescriptor, DeviceChangeEvent, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, Failure, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
2
2
  import { DeviceActionState as DeviceActionState$1, DiscoveredDevice, ExecuteDeviceActionReturnType, DeviceManagementKit } from '@ledgerhq/device-management-kit';
3
3
  import { Address, Signature, SignerEth as SignerEth$1, TypedData } from '@ledgerhq/device-signer-kit-ethereum';
4
4
  import { ContextModule } from '@ledgerhq/context-module';
@@ -38,7 +38,7 @@ declare class LedgerAdapter implements IHardwareWallet {
38
38
  resetState(): void;
39
39
  dispose(): Promise<void>;
40
40
  uiResponse(response: UiResponseEvent): void;
41
- searchDevices(): Promise<DeviceInfo[]>;
41
+ searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
42
42
  private static readonly MAX_BUSINESS_RETRY_BUDGET;
43
43
  private static readonly STUCK_APP_RETRY_DELAY_MS;
44
44
  private static readonly MAX_DOCONNECT_CONFIRMS;
@@ -256,6 +256,14 @@ declare class LedgerDeviceManager {
256
256
  requestDevice(): Promise<void>;
257
257
  /** Lookup a previously-discovered device's display name. */
258
258
  getDeviceName(deviceId: string): string | undefined;
259
+ /** Lookup minimal model/signal info from a previously-discovered device. */
260
+ getDiscoveredDeviceInfo(deviceId: string): {
261
+ model?: string;
262
+ modelName?: string;
263
+ name?: string;
264
+ rssi?: number | null;
265
+ } | undefined;
266
+ hasDiscoveredDevice(deviceId: string): boolean;
259
267
  /** Connect to a previously discovered device. Returns sessionId. */
260
268
  connect(deviceId: string): Promise<string>;
261
269
  /** Disconnect a session. */
@@ -300,7 +308,14 @@ interface LedgerConnectorBaseOptions {
300
308
  * Subclasses only need to:
301
309
  * 1. Supply a transport factory via the constructor.
302
310
  * 2. Optionally override `_resolveConnectId()` for transport-specific
303
- * device identity resolution (e.g. BLE hex ID extraction).
311
+ * device identity resolution.
312
+ *
313
+ * Invariant: one instance = one transport. `connectionType` is fixed at
314
+ * construction. To switch transport (e.g. desktop BLE ↔ WebHID), the host
315
+ * must build a new connector instance and replace the old one — don't add
316
+ * multiple transports to a single instance. Lifting this constraint would
317
+ * require routing `connectionType` from `descriptor.transport` per-device
318
+ * and updating every `this.connectionType` branch in this file.
304
319
  */
305
320
  declare class LedgerConnectorBase implements IConnector {
306
321
  private _deviceManager;
@@ -310,12 +325,6 @@ declare class LedgerConnectorBase implements IConnector {
310
325
  private readonly _providedDmk;
311
326
  private readonly _createTransport;
312
327
  readonly connectionType: ConnectionType;
313
- private _connectIdToPath;
314
- private _pathToConnectId;
315
- /** Get DMK path from external connectId. Falls back to connectId itself. */
316
- private _getPathForConnectId;
317
- /** Get external connectId from DMK path. Falls back to path itself. */
318
- private _getConnectIdForPath;
319
328
  private readonly _cancellers;
320
329
  private readonly _sessionStateSubs;
321
330
  /**
@@ -326,6 +335,10 @@ declare class LedgerConnectorBase implements IConnector {
326
335
  protected _importLedgerKit: (pkg: string) => Promise<any>;
327
336
  /** Context object passed to per-chain handler functions. */
328
337
  private readonly _ctx;
338
+ /** When true, BLE direct-connect throws NotAdvertising if the pre-flight
339
+ * scan can't see the device — guard for GATT stacks that wedge on
340
+ * non-advertising peripherals (iOS). */
341
+ private readonly _requirePreFlightScan;
329
342
  constructor(createTransport: TransportFactory, options?: {
330
343
  connectionType?: ConnectionType;
331
344
  dmk?: DeviceManagementKit;
@@ -335,11 +348,13 @@ declare class LedgerConnectorBase implements IConnector {
335
348
  * For Metro (React Native): pass a resolver that uses CJS paths.
336
349
  */
337
350
  importLedgerKit?: (pkg: string) => Promise<any>;
351
+ /** Default false. RN-iOS subclass should pass `true`. */
352
+ requirePreFlightScan?: boolean;
338
353
  });
339
354
  /**
340
355
  * Resolve the connectId for a discovered device descriptor.
341
356
  * Default: use the DMK path (ephemeral UUID).
342
- * Override in subclasses to extract stable identifiers (e.g. BLE hex ID).
357
+ * Override in subclasses only when the public connectId differs from the transport path.
343
358
  */
344
359
  protected _resolveConnectId(descriptor: DeviceDescriptor): string;
345
360
  /**
@@ -383,12 +398,11 @@ declare class LedgerConnectorBase implements IConnector {
383
398
  private _invalidateSession;
384
399
  /**
385
400
  * Replace an old session with a new one after app switch.
386
- * Updates the connectId→path mapping so subsequent calls() use the new session,
387
- * and emits device-connect so the adapter updates its _sessions Map.
401
+ * Emits device-connect so the adapter updates its _sessions Map.
388
402
  */
389
403
  private _replaceSession;
390
404
  /**
391
- * Light reset: clear signer/session state but keep DMK and ID mapping alive.
405
+ * Light reset: clear signer/session state but keep DMK alive.
392
406
  * Used by connect() retry — we want to re-discover with the same transport.
393
407
  *
394
408
  * Note: drops the device manager but tears down its RxJS subs first via
@@ -675,12 +689,7 @@ type SdkEventListener = (event: SdkEvent) => void;
675
689
  declare function onSdkEvent(listener: SdkEventListener): () => void;
676
690
  declare function offSdkEvent(listener: SdkEventListener): void;
677
691
 
678
- /**
679
- * Extract the stable 4-digit HEX identifier from a Ledger BLE device name.
680
- * e.g., "Nano X 123A" -> "123A", "Ledger Nano X AB12" -> "AB12"
681
- * Returns undefined if no valid HEX suffix found.
682
- */
683
- declare function extractBleHexId(name?: string): string | undefined;
692
+ declare function debugLog(...args: unknown[]): void;
684
693
 
685
694
  /**
686
695
  * Ledger DMK transport identifiers that represent BLE devices.
@@ -695,6 +704,5 @@ declare function extractBleHexId(name?: string): string | undefined;
695
704
  declare function isLedgerDmkBleTransport(transport?: string): boolean;
696
705
  declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
697
706
  declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
698
- declare function isValidLedgerBleConnectId(connectId?: string): boolean;
699
707
 
700
- export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, type LedgerFailure, type SdkEvent, type SdkEventListener, type SdkLogEvent, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, deviceActionToPromise, extractBleHexId, isDeviceLockedError, isLedgerBleConnectionType, isLedgerBleDescriptor, isLedgerDmkBleTransport, isValidLedgerBleConnectId, ledgerFailure, mapLedgerError, offSdkEvent, onSdkEvent };
708
+ export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, type LedgerFailure, type SdkEvent, type SdkEventListener, type SdkLogEvent, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, debugLog, deviceActionToPromise, isDeviceLockedError, isLedgerBleConnectionType, isLedgerBleDescriptor, isLedgerDmkBleTransport, ledgerFailure, mapLedgerError, offSdkEvent, onSdkEvent };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, DeviceDescriptor, DeviceChangeEvent, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, Failure, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
1
+ import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, DeviceDescriptor, DeviceChangeEvent, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, Failure, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
2
2
  import { DeviceActionState as DeviceActionState$1, DiscoveredDevice, ExecuteDeviceActionReturnType, DeviceManagementKit } from '@ledgerhq/device-management-kit';
3
3
  import { Address, Signature, SignerEth as SignerEth$1, TypedData } from '@ledgerhq/device-signer-kit-ethereum';
4
4
  import { ContextModule } from '@ledgerhq/context-module';
@@ -38,7 +38,7 @@ declare class LedgerAdapter implements IHardwareWallet {
38
38
  resetState(): void;
39
39
  dispose(): Promise<void>;
40
40
  uiResponse(response: UiResponseEvent): void;
41
- searchDevices(): Promise<DeviceInfo[]>;
41
+ searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
42
42
  private static readonly MAX_BUSINESS_RETRY_BUDGET;
43
43
  private static readonly STUCK_APP_RETRY_DELAY_MS;
44
44
  private static readonly MAX_DOCONNECT_CONFIRMS;
@@ -256,6 +256,14 @@ declare class LedgerDeviceManager {
256
256
  requestDevice(): Promise<void>;
257
257
  /** Lookup a previously-discovered device's display name. */
258
258
  getDeviceName(deviceId: string): string | undefined;
259
+ /** Lookup minimal model/signal info from a previously-discovered device. */
260
+ getDiscoveredDeviceInfo(deviceId: string): {
261
+ model?: string;
262
+ modelName?: string;
263
+ name?: string;
264
+ rssi?: number | null;
265
+ } | undefined;
266
+ hasDiscoveredDevice(deviceId: string): boolean;
259
267
  /** Connect to a previously discovered device. Returns sessionId. */
260
268
  connect(deviceId: string): Promise<string>;
261
269
  /** Disconnect a session. */
@@ -300,7 +308,14 @@ interface LedgerConnectorBaseOptions {
300
308
  * Subclasses only need to:
301
309
  * 1. Supply a transport factory via the constructor.
302
310
  * 2. Optionally override `_resolveConnectId()` for transport-specific
303
- * device identity resolution (e.g. BLE hex ID extraction).
311
+ * device identity resolution.
312
+ *
313
+ * Invariant: one instance = one transport. `connectionType` is fixed at
314
+ * construction. To switch transport (e.g. desktop BLE ↔ WebHID), the host
315
+ * must build a new connector instance and replace the old one — don't add
316
+ * multiple transports to a single instance. Lifting this constraint would
317
+ * require routing `connectionType` from `descriptor.transport` per-device
318
+ * and updating every `this.connectionType` branch in this file.
304
319
  */
305
320
  declare class LedgerConnectorBase implements IConnector {
306
321
  private _deviceManager;
@@ -310,12 +325,6 @@ declare class LedgerConnectorBase implements IConnector {
310
325
  private readonly _providedDmk;
311
326
  private readonly _createTransport;
312
327
  readonly connectionType: ConnectionType;
313
- private _connectIdToPath;
314
- private _pathToConnectId;
315
- /** Get DMK path from external connectId. Falls back to connectId itself. */
316
- private _getPathForConnectId;
317
- /** Get external connectId from DMK path. Falls back to path itself. */
318
- private _getConnectIdForPath;
319
328
  private readonly _cancellers;
320
329
  private readonly _sessionStateSubs;
321
330
  /**
@@ -326,6 +335,10 @@ declare class LedgerConnectorBase implements IConnector {
326
335
  protected _importLedgerKit: (pkg: string) => Promise<any>;
327
336
  /** Context object passed to per-chain handler functions. */
328
337
  private readonly _ctx;
338
+ /** When true, BLE direct-connect throws NotAdvertising if the pre-flight
339
+ * scan can't see the device — guard for GATT stacks that wedge on
340
+ * non-advertising peripherals (iOS). */
341
+ private readonly _requirePreFlightScan;
329
342
  constructor(createTransport: TransportFactory, options?: {
330
343
  connectionType?: ConnectionType;
331
344
  dmk?: DeviceManagementKit;
@@ -335,11 +348,13 @@ declare class LedgerConnectorBase implements IConnector {
335
348
  * For Metro (React Native): pass a resolver that uses CJS paths.
336
349
  */
337
350
  importLedgerKit?: (pkg: string) => Promise<any>;
351
+ /** Default false. RN-iOS subclass should pass `true`. */
352
+ requirePreFlightScan?: boolean;
338
353
  });
339
354
  /**
340
355
  * Resolve the connectId for a discovered device descriptor.
341
356
  * Default: use the DMK path (ephemeral UUID).
342
- * Override in subclasses to extract stable identifiers (e.g. BLE hex ID).
357
+ * Override in subclasses only when the public connectId differs from the transport path.
343
358
  */
344
359
  protected _resolveConnectId(descriptor: DeviceDescriptor): string;
345
360
  /**
@@ -383,12 +398,11 @@ declare class LedgerConnectorBase implements IConnector {
383
398
  private _invalidateSession;
384
399
  /**
385
400
  * Replace an old session with a new one after app switch.
386
- * Updates the connectId→path mapping so subsequent calls() use the new session,
387
- * and emits device-connect so the adapter updates its _sessions Map.
401
+ * Emits device-connect so the adapter updates its _sessions Map.
388
402
  */
389
403
  private _replaceSession;
390
404
  /**
391
- * Light reset: clear signer/session state but keep DMK and ID mapping alive.
405
+ * Light reset: clear signer/session state but keep DMK alive.
392
406
  * Used by connect() retry — we want to re-discover with the same transport.
393
407
  *
394
408
  * Note: drops the device manager but tears down its RxJS subs first via
@@ -675,12 +689,7 @@ type SdkEventListener = (event: SdkEvent) => void;
675
689
  declare function onSdkEvent(listener: SdkEventListener): () => void;
676
690
  declare function offSdkEvent(listener: SdkEventListener): void;
677
691
 
678
- /**
679
- * Extract the stable 4-digit HEX identifier from a Ledger BLE device name.
680
- * e.g., "Nano X 123A" -> "123A", "Ledger Nano X AB12" -> "AB12"
681
- * Returns undefined if no valid HEX suffix found.
682
- */
683
- declare function extractBleHexId(name?: string): string | undefined;
692
+ declare function debugLog(...args: unknown[]): void;
684
693
 
685
694
  /**
686
695
  * Ledger DMK transport identifiers that represent BLE devices.
@@ -695,6 +704,5 @@ declare function extractBleHexId(name?: string): string | undefined;
695
704
  declare function isLedgerDmkBleTransport(transport?: string): boolean;
696
705
  declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
697
706
  declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
698
- declare function isValidLedgerBleConnectId(connectId?: string): boolean;
699
707
 
700
- export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, type LedgerFailure, type SdkEvent, type SdkEventListener, type SdkLogEvent, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, deviceActionToPromise, extractBleHexId, isDeviceLockedError, isLedgerBleConnectionType, isLedgerBleDescriptor, isLedgerDmkBleTransport, isValidLedgerBleConnectId, ledgerFailure, mapLedgerError, offSdkEvent, onSdkEvent };
708
+ export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, type LedgerFailure, type SdkEvent, type SdkEventListener, type SdkLogEvent, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, debugLog, deviceActionToPromise, isDeviceLockedError, isLedgerBleConnectionType, isLedgerBleDescriptor, isLedgerDmkBleTransport, ledgerFailure, mapLedgerError, offSdkEvent, onSdkEvent };