@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.101 → 1.1.26-alpha.104

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,10 +1,18 @@
1
- import { IHardwareWallet, IConnector, TransportType, IUiHandler, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, EvmGetPublicKeyParams, EvmPublicKey, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolGetPublicKeyParams, SolPublicKey, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
1
+ import { IHardwareWallet, IConnector, TransportType, IUiHandler, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, 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, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
2
2
  import { DeviceManagementKit, DeviceActionState as DeviceActionState$1, DiscoveredDevice, ExecuteDeviceActionReturnType } from '@ledgerhq/device-management-kit';
3
3
  import { Address, Signature, SignerEth as SignerEth$1, TypedData } from '@ledgerhq/device-signer-kit-ethereum';
4
4
  import { SignerBtc as SignerBtc$1 } from '@ledgerhq/device-signer-kit-bitcoin';
5
5
  import { SignerSolana } from '@ledgerhq/device-signer-kit-solana';
6
6
  import Transport from '@ledgerhq/hw-transport';
7
7
 
8
+ interface LedgerAdapterOptions {
9
+ /**
10
+ * `true` — emit `REQUEST_SELECT_DEVICE` on multi-device discovery and await
11
+ * `uiResponse({ type: RECEIVE_SELECT_DEVICE, payload: { sdkConnectId } })`.
12
+ * `false` (default) — silently pick the first device.
13
+ */
14
+ handleSelectDevice?: boolean;
15
+ }
8
16
  /**
9
17
  * Ledger hardware wallet adapter that delegates to an IConnector.
10
18
  *
@@ -20,9 +28,11 @@ declare class LedgerAdapter implements IHardwareWallet {
20
28
  private readonly connector;
21
29
  private readonly emitter;
22
30
  private _uiHandler;
31
+ private readonly _handleSelectDevice;
23
32
  private _discoveredDevices;
24
33
  private _sessions;
25
- constructor(connector: IConnector);
34
+ private readonly _uiRegistry;
35
+ constructor(connector: IConnector, options?: LedgerAdapterOptions);
26
36
  get activeTransport(): TransportType | null;
27
37
  getAvailableTransports(): TransportType[];
28
38
  switchTransport(_type: TransportType): Promise<void>;
@@ -35,6 +45,7 @@ declare class LedgerAdapter implements IHardwareWallet {
35
45
  */
36
46
  resetState(): void;
37
47
  dispose(): Promise<void>;
48
+ uiResponse(response: UiResponseEvent): void;
38
49
  searchDevices(): Promise<DeviceInfo[]>;
39
50
  connectDevice(connectId: string): Promise<Response<string>>;
40
51
  disconnectDevice(connectId: string): Promise<void>;
@@ -42,13 +53,12 @@ declare class LedgerAdapter implements IHardwareWallet {
42
53
  getSupportedChains(): ChainCapability[];
43
54
  private callChain;
44
55
  /**
45
- * Batch version of callChain — checks permission and fingerprint once,
46
- * then calls the connector for each param sequentially.
56
+ * Batch version of callChain — checks permission once,
57
+ * fingerprint is verified on the first call inside connectorCall.
47
58
  */
48
59
  private callChainBatch;
49
60
  evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams): Promise<Response<EvmAddress>>;
50
61
  evmGetAddresses(connectId: string, deviceId: string, params: EvmGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<EvmAddress[]>>;
51
- evmGetPublicKey(connectId: string, deviceId: string, params: EvmGetPublicKeyParams): Promise<Response<EvmPublicKey>>;
52
62
  evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams): Promise<Response<EvmSignedTx>>;
53
63
  evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams): Promise<Response<EvmSignature>>;
54
64
  evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams): Promise<Response<EvmSignature>>;
@@ -63,7 +73,6 @@ declare class LedgerAdapter implements IHardwareWallet {
63
73
  }>>;
64
74
  solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams): Promise<Response<SolAddress>>;
65
75
  solGetAddresses(connectId: string, deviceId: string, params: SolGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<SolAddress[]>>;
66
- solGetPublicKey(connectId: string, deviceId: string, params: SolGetPublicKeyParams): Promise<Response<SolPublicKey>>;
67
76
  solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams): Promise<Response<SolSignedTx>>;
68
77
  solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams): Promise<Response<SolSignature>>;
69
78
  tronGetAddress(connectId: string, deviceId: string, params: TronGetAddressParams): Promise<Response<TronAddress>>;
@@ -77,18 +86,21 @@ declare class LedgerAdapter implements IHardwareWallet {
77
86
  cancel(connectId: string): void;
78
87
  getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
79
88
  /**
80
- * Verify that the connected device matches the expected fingerprint.
81
- *
82
- * - If deviceId is empty, verification is skipped (returns { success: true }).
83
- * - deviceId is used here as the stored fingerprint to compare against.
84
- * - On mismatch, returns both expected and actual fingerprints so the caller
85
- * can surface an informative error (e.g. for logs / bug reports).
89
+ * Verify fingerprint using an existing sessionId directly.
90
+ * Safe to call inside connectorCall without causing queue deadlock.
86
91
  */
87
- private _verifyDeviceFingerprint;
92
+ private _verifyDeviceFingerprintWithSession;
88
93
  /**
89
94
  * Derive an address at the fixed testnet path for fingerprint generation.
95
+ * Uses connectorCall (goes through ensureConnected). For public API use.
90
96
  */
91
97
  private _deriveAddressForFingerprint;
98
+ /**
99
+ * Derive an address using an existing sessionId directly.
100
+ * Does NOT go through connectorCall — safe to call inside connectorCall
101
+ * without causing queue deadlock.
102
+ */
103
+ private _deriveAddressWithSession;
92
104
  /**
93
105
  * Ensure at least one device is connected and return a valid connectId.
94
106
  *
@@ -97,25 +109,12 @@ declare class LedgerAdapter implements IHardwareWallet {
97
109
  * - Otherwise: search → 1 device: auto-connect, multiple: ask user, 0: throw.
98
110
  */
99
111
  private static readonly MAX_DEVICE_RETRY;
100
- private _deviceConnectResolve;
101
112
  private _connectingPromise;
102
- private static readonly DEVICE_CONNECT_TIMEOUT_MS;
103
- /**
104
- * Wait for user to connect and unlock device.
105
- * Emits 'ui-request' event via the adapter's own emitter.
106
- * The consumer (monorepo adapter wrapper) listens for this and shows UI.
107
- * When user confirms, they call adapter.deviceConnectResponse() which resolves this promise.
108
- * Times out after 60 seconds if no response is received.
109
- */
110
113
  private _waitForDeviceConnect;
111
- /**
112
- * Called by consumer to respond to ui-request-device-connect.
113
- * type='confirm' → retry search, type='cancel' → abort.
114
- */
115
- deviceConnectResponse(type: 'confirm' | 'cancel'): void;
116
114
  private ensureConnected;
117
115
  private _doConnect;
118
116
  private _connectFirstOrSelect;
117
+ private _chooseDeviceFromList;
119
118
  /**
120
119
  * Call the connector with automatic session resolution and disconnect retry.
121
120
  *
@@ -223,10 +222,7 @@ declare class LedgerConnectorBase implements IConnector {
223
222
  disconnect(sessionId: string): Promise<void>;
224
223
  call(sessionId: string, method: string, params: unknown): Promise<unknown>;
225
224
  cancel(_sessionId: string): Promise<void>;
226
- uiResponse(_response: {
227
- type: string;
228
- payload: unknown;
229
- }): void;
225
+ uiResponse(_response: UiResponseEvent): void;
230
226
  on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
231
227
  off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
232
228
  reset(): void;
@@ -370,7 +366,6 @@ type BtcWallet = Parameters<SignerBtc$1['getWalletAddress']>[0];
370
366
  type BtcPsbt = Parameters<SignerBtc$1['signPsbt']>[1];
371
367
  type BtcPsbtOptions = Parameters<SignerBtc$1['signPsbt']>[2];
372
368
  type BtcMessageOptions = Parameters<SignerBtc$1['signMessage']>[2];
373
-
374
369
  /**
375
370
  * Wraps Ledger's BTC SDK signer (Observable-based DeviceActions) into
376
371
  * a simple async interface returning plain serializable data.
package/dist/index.d.ts CHANGED
@@ -1,10 +1,18 @@
1
- import { IHardwareWallet, IConnector, TransportType, IUiHandler, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, EvmGetPublicKeyParams, EvmPublicKey, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolGetPublicKeyParams, SolPublicKey, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
1
+ import { IHardwareWallet, IConnector, TransportType, IUiHandler, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, 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, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
2
2
  import { DeviceManagementKit, DeviceActionState as DeviceActionState$1, DiscoveredDevice, ExecuteDeviceActionReturnType } from '@ledgerhq/device-management-kit';
3
3
  import { Address, Signature, SignerEth as SignerEth$1, TypedData } from '@ledgerhq/device-signer-kit-ethereum';
4
4
  import { SignerBtc as SignerBtc$1 } from '@ledgerhq/device-signer-kit-bitcoin';
5
5
  import { SignerSolana } from '@ledgerhq/device-signer-kit-solana';
6
6
  import Transport from '@ledgerhq/hw-transport';
7
7
 
8
+ interface LedgerAdapterOptions {
9
+ /**
10
+ * `true` — emit `REQUEST_SELECT_DEVICE` on multi-device discovery and await
11
+ * `uiResponse({ type: RECEIVE_SELECT_DEVICE, payload: { sdkConnectId } })`.
12
+ * `false` (default) — silently pick the first device.
13
+ */
14
+ handleSelectDevice?: boolean;
15
+ }
8
16
  /**
9
17
  * Ledger hardware wallet adapter that delegates to an IConnector.
10
18
  *
@@ -20,9 +28,11 @@ declare class LedgerAdapter implements IHardwareWallet {
20
28
  private readonly connector;
21
29
  private readonly emitter;
22
30
  private _uiHandler;
31
+ private readonly _handleSelectDevice;
23
32
  private _discoveredDevices;
24
33
  private _sessions;
25
- constructor(connector: IConnector);
34
+ private readonly _uiRegistry;
35
+ constructor(connector: IConnector, options?: LedgerAdapterOptions);
26
36
  get activeTransport(): TransportType | null;
27
37
  getAvailableTransports(): TransportType[];
28
38
  switchTransport(_type: TransportType): Promise<void>;
@@ -35,6 +45,7 @@ declare class LedgerAdapter implements IHardwareWallet {
35
45
  */
36
46
  resetState(): void;
37
47
  dispose(): Promise<void>;
48
+ uiResponse(response: UiResponseEvent): void;
38
49
  searchDevices(): Promise<DeviceInfo[]>;
39
50
  connectDevice(connectId: string): Promise<Response<string>>;
40
51
  disconnectDevice(connectId: string): Promise<void>;
@@ -42,13 +53,12 @@ declare class LedgerAdapter implements IHardwareWallet {
42
53
  getSupportedChains(): ChainCapability[];
43
54
  private callChain;
44
55
  /**
45
- * Batch version of callChain — checks permission and fingerprint once,
46
- * then calls the connector for each param sequentially.
56
+ * Batch version of callChain — checks permission once,
57
+ * fingerprint is verified on the first call inside connectorCall.
47
58
  */
48
59
  private callChainBatch;
49
60
  evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams): Promise<Response<EvmAddress>>;
50
61
  evmGetAddresses(connectId: string, deviceId: string, params: EvmGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<EvmAddress[]>>;
51
- evmGetPublicKey(connectId: string, deviceId: string, params: EvmGetPublicKeyParams): Promise<Response<EvmPublicKey>>;
52
62
  evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams): Promise<Response<EvmSignedTx>>;
53
63
  evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams): Promise<Response<EvmSignature>>;
54
64
  evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams): Promise<Response<EvmSignature>>;
@@ -63,7 +73,6 @@ declare class LedgerAdapter implements IHardwareWallet {
63
73
  }>>;
64
74
  solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams): Promise<Response<SolAddress>>;
65
75
  solGetAddresses(connectId: string, deviceId: string, params: SolGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<SolAddress[]>>;
66
- solGetPublicKey(connectId: string, deviceId: string, params: SolGetPublicKeyParams): Promise<Response<SolPublicKey>>;
67
76
  solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams): Promise<Response<SolSignedTx>>;
68
77
  solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams): Promise<Response<SolSignature>>;
69
78
  tronGetAddress(connectId: string, deviceId: string, params: TronGetAddressParams): Promise<Response<TronAddress>>;
@@ -77,18 +86,21 @@ declare class LedgerAdapter implements IHardwareWallet {
77
86
  cancel(connectId: string): void;
78
87
  getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
79
88
  /**
80
- * Verify that the connected device matches the expected fingerprint.
81
- *
82
- * - If deviceId is empty, verification is skipped (returns { success: true }).
83
- * - deviceId is used here as the stored fingerprint to compare against.
84
- * - On mismatch, returns both expected and actual fingerprints so the caller
85
- * can surface an informative error (e.g. for logs / bug reports).
89
+ * Verify fingerprint using an existing sessionId directly.
90
+ * Safe to call inside connectorCall without causing queue deadlock.
86
91
  */
87
- private _verifyDeviceFingerprint;
92
+ private _verifyDeviceFingerprintWithSession;
88
93
  /**
89
94
  * Derive an address at the fixed testnet path for fingerprint generation.
95
+ * Uses connectorCall (goes through ensureConnected). For public API use.
90
96
  */
91
97
  private _deriveAddressForFingerprint;
98
+ /**
99
+ * Derive an address using an existing sessionId directly.
100
+ * Does NOT go through connectorCall — safe to call inside connectorCall
101
+ * without causing queue deadlock.
102
+ */
103
+ private _deriveAddressWithSession;
92
104
  /**
93
105
  * Ensure at least one device is connected and return a valid connectId.
94
106
  *
@@ -97,25 +109,12 @@ declare class LedgerAdapter implements IHardwareWallet {
97
109
  * - Otherwise: search → 1 device: auto-connect, multiple: ask user, 0: throw.
98
110
  */
99
111
  private static readonly MAX_DEVICE_RETRY;
100
- private _deviceConnectResolve;
101
112
  private _connectingPromise;
102
- private static readonly DEVICE_CONNECT_TIMEOUT_MS;
103
- /**
104
- * Wait for user to connect and unlock device.
105
- * Emits 'ui-request' event via the adapter's own emitter.
106
- * The consumer (monorepo adapter wrapper) listens for this and shows UI.
107
- * When user confirms, they call adapter.deviceConnectResponse() which resolves this promise.
108
- * Times out after 60 seconds if no response is received.
109
- */
110
113
  private _waitForDeviceConnect;
111
- /**
112
- * Called by consumer to respond to ui-request-device-connect.
113
- * type='confirm' → retry search, type='cancel' → abort.
114
- */
115
- deviceConnectResponse(type: 'confirm' | 'cancel'): void;
116
114
  private ensureConnected;
117
115
  private _doConnect;
118
116
  private _connectFirstOrSelect;
117
+ private _chooseDeviceFromList;
119
118
  /**
120
119
  * Call the connector with automatic session resolution and disconnect retry.
121
120
  *
@@ -223,10 +222,7 @@ declare class LedgerConnectorBase implements IConnector {
223
222
  disconnect(sessionId: string): Promise<void>;
224
223
  call(sessionId: string, method: string, params: unknown): Promise<unknown>;
225
224
  cancel(_sessionId: string): Promise<void>;
226
- uiResponse(_response: {
227
- type: string;
228
- payload: unknown;
229
- }): void;
225
+ uiResponse(_response: UiResponseEvent): void;
230
226
  on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
231
227
  off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
232
228
  reset(): void;
@@ -370,7 +366,6 @@ type BtcWallet = Parameters<SignerBtc$1['getWalletAddress']>[0];
370
366
  type BtcPsbt = Parameters<SignerBtc$1['signPsbt']>[1];
371
367
  type BtcPsbtOptions = Parameters<SignerBtc$1['signPsbt']>[2];
372
368
  type BtcMessageOptions = Parameters<SignerBtc$1['signMessage']>[2];
373
-
374
369
  /**
375
370
  * Wraps Ledger's BTC SDK signer (Observable-based DeviceActions) into
376
371
  * a simple async interface returning plain serializable data.