@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.100 → 1.1.26-alpha.102
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 +25 -21
- package/dist/index.d.ts +25 -21
- package/dist/index.js +286 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +287 -115
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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, 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, 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';
|
|
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
|
-
|
|
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>;
|
|
@@ -56,6 +67,7 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
56
67
|
btcGetAddresses(connectId: string, deviceId: string, params: BtcGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<BtcAddress[]>>;
|
|
57
68
|
btcGetPublicKey(connectId: string, deviceId: string, params: BtcGetPublicKeyParams): Promise<Response<BtcPublicKey>>;
|
|
58
69
|
btcSignTransaction(connectId: string, deviceId: string, params: BtcSignTxParams): Promise<Response<BtcSignedTx>>;
|
|
70
|
+
btcSignPsbt(connectId: string, deviceId: string, params: BtcSignPsbtParams): Promise<Response<BtcSignedPsbt>>;
|
|
59
71
|
btcSignMessage(connectId: string, deviceId: string, params: BtcSignMsgParams): Promise<Response<BtcSignature>>;
|
|
60
72
|
btcGetMasterFingerprint(connectId: string, deviceId: string): Promise<Response<{
|
|
61
73
|
masterFingerprint: string;
|
|
@@ -78,8 +90,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
78
90
|
/**
|
|
79
91
|
* Verify that the connected device matches the expected fingerprint.
|
|
80
92
|
*
|
|
81
|
-
* - If deviceId is empty, verification is skipped (returns true).
|
|
93
|
+
* - If deviceId is empty, verification is skipped (returns { success: true }).
|
|
82
94
|
* - deviceId is used here as the stored fingerprint to compare against.
|
|
95
|
+
* - On mismatch, returns both expected and actual fingerprints so the caller
|
|
96
|
+
* can surface an informative error (e.g. for logs / bug reports).
|
|
83
97
|
*/
|
|
84
98
|
private _verifyDeviceFingerprint;
|
|
85
99
|
/**
|
|
@@ -94,25 +108,12 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
94
108
|
* - Otherwise: search → 1 device: auto-connect, multiple: ask user, 0: throw.
|
|
95
109
|
*/
|
|
96
110
|
private static readonly MAX_DEVICE_RETRY;
|
|
97
|
-
private _deviceConnectResolve;
|
|
98
111
|
private _connectingPromise;
|
|
99
|
-
private static readonly DEVICE_CONNECT_TIMEOUT_MS;
|
|
100
|
-
/**
|
|
101
|
-
* Wait for user to connect and unlock device.
|
|
102
|
-
* Emits 'ui-request' event via the adapter's own emitter.
|
|
103
|
-
* The consumer (monorepo adapter wrapper) listens for this and shows UI.
|
|
104
|
-
* When user confirms, they call adapter.deviceConnectResponse() which resolves this promise.
|
|
105
|
-
* Times out after 60 seconds if no response is received.
|
|
106
|
-
*/
|
|
107
112
|
private _waitForDeviceConnect;
|
|
108
|
-
/**
|
|
109
|
-
* Called by consumer to respond to ui-request-device-connect.
|
|
110
|
-
* type='confirm' → retry search, type='cancel' → abort.
|
|
111
|
-
*/
|
|
112
|
-
deviceConnectResponse(type: 'confirm' | 'cancel'): void;
|
|
113
113
|
private ensureConnected;
|
|
114
114
|
private _doConnect;
|
|
115
115
|
private _connectFirstOrSelect;
|
|
116
|
+
private _chooseDeviceFromList;
|
|
116
117
|
/**
|
|
117
118
|
* Call the connector with automatic session resolution and disconnect retry.
|
|
118
119
|
*
|
|
@@ -220,10 +221,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
220
221
|
disconnect(sessionId: string): Promise<void>;
|
|
221
222
|
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
222
223
|
cancel(_sessionId: string): Promise<void>;
|
|
223
|
-
uiResponse(_response:
|
|
224
|
-
type: string;
|
|
225
|
-
payload: unknown;
|
|
226
|
-
}): void;
|
|
224
|
+
uiResponse(_response: UiResponseEvent): void;
|
|
227
225
|
on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
228
226
|
off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
229
227
|
reset(): void;
|
|
@@ -464,6 +462,11 @@ declare class DmkTransport extends Transport {
|
|
|
464
462
|
* Convert a DMK DeviceAction (Observable-based) into a Promise.
|
|
465
463
|
* Handles pending -> completed/error state transitions and interaction callbacks.
|
|
466
464
|
*
|
|
465
|
+
* Tracks the last DMK step observed (e.g. `signer.eth.steps.blindSignTransactionFallback`)
|
|
466
|
+
* and attaches it to the rejected error as a non-enumerable `_lastStep` property,
|
|
467
|
+
* so upstream error classifiers can distinguish failure contexts (e.g. Blind signing
|
|
468
|
+
* disabled vs. generic Invalid data).
|
|
469
|
+
*
|
|
467
470
|
* @param timeoutMs Timeout in ms. Resets each time the Observable emits (device is alive).
|
|
468
471
|
* Pass 0 to disable. Default: 30s.
|
|
469
472
|
*/
|
|
@@ -524,6 +527,7 @@ declare function isDeviceLockedError(err: unknown): boolean;
|
|
|
524
527
|
declare function mapLedgerError(err: unknown): {
|
|
525
528
|
code: HardwareErrorCode;
|
|
526
529
|
message: string;
|
|
530
|
+
appName?: string;
|
|
527
531
|
};
|
|
528
532
|
|
|
529
533
|
export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, deviceActionToPromise, isDeviceLockedError, mapLedgerError };
|
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, 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, 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';
|
|
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
|
-
|
|
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>;
|
|
@@ -56,6 +67,7 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
56
67
|
btcGetAddresses(connectId: string, deviceId: string, params: BtcGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<BtcAddress[]>>;
|
|
57
68
|
btcGetPublicKey(connectId: string, deviceId: string, params: BtcGetPublicKeyParams): Promise<Response<BtcPublicKey>>;
|
|
58
69
|
btcSignTransaction(connectId: string, deviceId: string, params: BtcSignTxParams): Promise<Response<BtcSignedTx>>;
|
|
70
|
+
btcSignPsbt(connectId: string, deviceId: string, params: BtcSignPsbtParams): Promise<Response<BtcSignedPsbt>>;
|
|
59
71
|
btcSignMessage(connectId: string, deviceId: string, params: BtcSignMsgParams): Promise<Response<BtcSignature>>;
|
|
60
72
|
btcGetMasterFingerprint(connectId: string, deviceId: string): Promise<Response<{
|
|
61
73
|
masterFingerprint: string;
|
|
@@ -78,8 +90,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
78
90
|
/**
|
|
79
91
|
* Verify that the connected device matches the expected fingerprint.
|
|
80
92
|
*
|
|
81
|
-
* - If deviceId is empty, verification is skipped (returns true).
|
|
93
|
+
* - If deviceId is empty, verification is skipped (returns { success: true }).
|
|
82
94
|
* - deviceId is used here as the stored fingerprint to compare against.
|
|
95
|
+
* - On mismatch, returns both expected and actual fingerprints so the caller
|
|
96
|
+
* can surface an informative error (e.g. for logs / bug reports).
|
|
83
97
|
*/
|
|
84
98
|
private _verifyDeviceFingerprint;
|
|
85
99
|
/**
|
|
@@ -94,25 +108,12 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
94
108
|
* - Otherwise: search → 1 device: auto-connect, multiple: ask user, 0: throw.
|
|
95
109
|
*/
|
|
96
110
|
private static readonly MAX_DEVICE_RETRY;
|
|
97
|
-
private _deviceConnectResolve;
|
|
98
111
|
private _connectingPromise;
|
|
99
|
-
private static readonly DEVICE_CONNECT_TIMEOUT_MS;
|
|
100
|
-
/**
|
|
101
|
-
* Wait for user to connect and unlock device.
|
|
102
|
-
* Emits 'ui-request' event via the adapter's own emitter.
|
|
103
|
-
* The consumer (monorepo adapter wrapper) listens for this and shows UI.
|
|
104
|
-
* When user confirms, they call adapter.deviceConnectResponse() which resolves this promise.
|
|
105
|
-
* Times out after 60 seconds if no response is received.
|
|
106
|
-
*/
|
|
107
112
|
private _waitForDeviceConnect;
|
|
108
|
-
/**
|
|
109
|
-
* Called by consumer to respond to ui-request-device-connect.
|
|
110
|
-
* type='confirm' → retry search, type='cancel' → abort.
|
|
111
|
-
*/
|
|
112
|
-
deviceConnectResponse(type: 'confirm' | 'cancel'): void;
|
|
113
113
|
private ensureConnected;
|
|
114
114
|
private _doConnect;
|
|
115
115
|
private _connectFirstOrSelect;
|
|
116
|
+
private _chooseDeviceFromList;
|
|
116
117
|
/**
|
|
117
118
|
* Call the connector with automatic session resolution and disconnect retry.
|
|
118
119
|
*
|
|
@@ -220,10 +221,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
220
221
|
disconnect(sessionId: string): Promise<void>;
|
|
221
222
|
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
222
223
|
cancel(_sessionId: string): Promise<void>;
|
|
223
|
-
uiResponse(_response:
|
|
224
|
-
type: string;
|
|
225
|
-
payload: unknown;
|
|
226
|
-
}): void;
|
|
224
|
+
uiResponse(_response: UiResponseEvent): void;
|
|
227
225
|
on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
228
226
|
off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
229
227
|
reset(): void;
|
|
@@ -464,6 +462,11 @@ declare class DmkTransport extends Transport {
|
|
|
464
462
|
* Convert a DMK DeviceAction (Observable-based) into a Promise.
|
|
465
463
|
* Handles pending -> completed/error state transitions and interaction callbacks.
|
|
466
464
|
*
|
|
465
|
+
* Tracks the last DMK step observed (e.g. `signer.eth.steps.blindSignTransactionFallback`)
|
|
466
|
+
* and attaches it to the rejected error as a non-enumerable `_lastStep` property,
|
|
467
|
+
* so upstream error classifiers can distinguish failure contexts (e.g. Blind signing
|
|
468
|
+
* disabled vs. generic Invalid data).
|
|
469
|
+
*
|
|
467
470
|
* @param timeoutMs Timeout in ms. Resets each time the Observable emits (device is alive).
|
|
468
471
|
* Pass 0 to disable. Default: 30s.
|
|
469
472
|
*/
|
|
@@ -524,6 +527,7 @@ declare function isDeviceLockedError(err: unknown): boolean;
|
|
|
524
527
|
declare function mapLedgerError(err: unknown): {
|
|
525
528
|
code: HardwareErrorCode;
|
|
526
529
|
message: string;
|
|
530
|
+
appName?: string;
|
|
527
531
|
};
|
|
528
532
|
|
|
529
533
|
export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, deviceActionToPromise, isDeviceLockedError, mapLedgerError };
|