@onekeyfe/hwk-ledger-adapter 1.1.27-alpha.41 → 1.1.27-alpha.43
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 +181 -103
- package/dist/index.d.ts +181 -103
- package/dist/index.js +1199 -313
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1198 -306
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,30 +1,109 @@
|
|
|
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, ICommonCallParams, 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, ConnectorCallResult, 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
|
+
import { ContextModule } from '@ledgerhq/context-module';
|
|
4
5
|
import { SignerBtc as SignerBtc$1 } from '@ledgerhq/device-signer-kit-bitcoin';
|
|
5
6
|
import { SignerSolana } from '@ledgerhq/device-signer-kit-solana';
|
|
6
7
|
import Transport from '@ledgerhq/hw-transport';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Re-export DMK types under local aliases for backward compatibility.
|
|
11
|
+
* These replace the previous duck-typed interfaces with the real SDK types.
|
|
12
|
+
*/
|
|
13
|
+
type DmkDiscoveredDevice = DiscoveredDevice;
|
|
14
|
+
/**
|
|
15
|
+
* DMK DeviceAction — the Observable-based return type of all DMK signer methods.
|
|
16
|
+
*
|
|
17
|
+
* This is a permissive alias for `ExecuteDeviceActionReturnType` that accepts
|
|
18
|
+
* any Error and IntermediateValue generics. Signer wrapper code only cares about
|
|
19
|
+
* the Output type and the observable/cancel shape.
|
|
20
|
+
*/
|
|
21
|
+
type DeviceAction<T> = ExecuteDeviceActionReturnType<T, any, any>;
|
|
22
|
+
/**
|
|
23
|
+
* DMK DeviceActionState — re-exported with permissive Error/IntermediateValue.
|
|
24
|
+
* The real type is a discriminated union on `status`.
|
|
25
|
+
*/
|
|
26
|
+
type DeviceActionState<T> = DeviceActionState$1<T, any, any>;
|
|
27
|
+
/** ETH address result — re-exported from DMK for backward compatibility. */
|
|
28
|
+
type SignerEvmAddress = Address;
|
|
29
|
+
/** ETH signature result — re-exported from DMK for backward compatibility. */
|
|
30
|
+
type SignerEvmSignature = Signature;
|
|
31
|
+
/** BTC address result (WalletAddress not exported from DMK top-level). */
|
|
32
|
+
interface SignerBtcAddress {
|
|
33
|
+
address: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Optional context attached to the rejection when a canceller fires. */
|
|
37
|
+
interface CancelReason {
|
|
38
|
+
code?: number;
|
|
39
|
+
tag?: string;
|
|
40
|
+
message?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Convert a DMK DeviceAction (Observable-based) into a Promise.
|
|
44
|
+
* Handles pending -> completed/error state transitions and interaction callbacks.
|
|
45
|
+
*
|
|
46
|
+
* Tracks the last DMK step observed (e.g. `signer.eth.steps.blindSignTransactionFallback`)
|
|
47
|
+
* and attaches it to the rejected error as a non-enumerable `_lastStep` property,
|
|
48
|
+
* so upstream error classifiers can distinguish failure contexts (e.g. Blind signing
|
|
49
|
+
* disabled vs. generic Invalid data).
|
|
50
|
+
*
|
|
51
|
+
* @param timeoutMs Idle watchdog ms. Re-armed on each emission, paused
|
|
52
|
+
* during interactive pending. 0 disables. Default 65s
|
|
53
|
+
* (covers DMK's 60s + margin; we're a backstop only).
|
|
54
|
+
* @param onRegisterCanceller Optional callback that receives a function which, when
|
|
55
|
+
* called, unsubscribes and cancels the underlying DeviceAction
|
|
56
|
+
* (releases DMK's IntentQueue slot). Caller is responsible
|
|
57
|
+
* for invoking the canceller on timeout/abort scenarios.
|
|
58
|
+
*/
|
|
59
|
+
declare function deviceActionToPromise<T>(action: DeviceAction<T>, onInteraction?: (interaction: string) => void, timeoutMs?: number, onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void, onIntermediate?: (intermediateValue: unknown) => void): Promise<T>;
|
|
60
|
+
|
|
61
|
+
interface AppMetadata {
|
|
62
|
+
versionName: string;
|
|
63
|
+
versionId: number;
|
|
64
|
+
version: string;
|
|
65
|
+
versionDisplayName: string | null;
|
|
66
|
+
description: string | null;
|
|
67
|
+
icon: string | null;
|
|
68
|
+
bytes: number | null;
|
|
69
|
+
currencyId: string | null;
|
|
70
|
+
isDevTools: boolean;
|
|
15
71
|
}
|
|
72
|
+
interface FirmwareVersion {
|
|
73
|
+
/** BOLOS version on the secure element — the user-facing firmware version. */
|
|
74
|
+
seVersion: string;
|
|
75
|
+
/** MCU SEPH (SE–MCU link protocol) version. */
|
|
76
|
+
mcuSephVersion: string;
|
|
77
|
+
/** MCU bootloader version. */
|
|
78
|
+
mcuBootloaderVersion: string;
|
|
79
|
+
/** Hardware revision (e.g. "00" / "01" on Nano X). */
|
|
80
|
+
hwVersion: string;
|
|
81
|
+
}
|
|
82
|
+
/** Full GetOsVersionResponse projected to a plain serializable shape. */
|
|
83
|
+
interface LedgerDeviceInfo extends FirmwareVersion {
|
|
84
|
+
isBootloader: boolean;
|
|
85
|
+
isOsu: boolean;
|
|
86
|
+
targetId: number;
|
|
87
|
+
seTargetId?: number;
|
|
88
|
+
mcuTargetId?: number;
|
|
89
|
+
/** Secure element flags as hex string (raw bytes turned readable). */
|
|
90
|
+
seFlagsHex: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
16
93
|
declare class LedgerAdapter implements IHardwareWallet {
|
|
17
94
|
readonly vendor: "ledger";
|
|
18
95
|
private readonly connector;
|
|
19
96
|
private readonly emitter;
|
|
20
|
-
private readonly _handleSelectDevice;
|
|
21
97
|
private _discoveredDevices;
|
|
22
98
|
private _sessions;
|
|
23
99
|
private readonly _uiRegistry;
|
|
24
100
|
private _btcHighIndexConfirmedThisSession;
|
|
25
101
|
private readonly _jobQueue;
|
|
26
102
|
private _doConnectAbortController;
|
|
27
|
-
|
|
103
|
+
private readonly _defaultAutoInstallApp;
|
|
104
|
+
constructor(connector: IConnector, options?: {
|
|
105
|
+
autoInstallApp?: boolean;
|
|
106
|
+
});
|
|
28
107
|
get activeTransport(): TransportType | null;
|
|
29
108
|
getAvailableTransports(): TransportType[];
|
|
30
109
|
switchTransport(_type: TransportType): Promise<void>;
|
|
@@ -37,8 +116,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
37
116
|
resetState(): void;
|
|
38
117
|
dispose(): Promise<void>;
|
|
39
118
|
uiResponse(response: UiResponseEvent): void;
|
|
40
|
-
searchDevices(): Promise<DeviceInfo[]>;
|
|
119
|
+
searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
|
|
120
|
+
private _evictAllSessions;
|
|
41
121
|
private static readonly MAX_BUSINESS_RETRY_BUDGET;
|
|
122
|
+
private static readonly STUCK_APP_RETRY_DELAY_MS;
|
|
42
123
|
private static readonly MAX_DOCONNECT_CONFIRMS;
|
|
43
124
|
private _lastCancelReason;
|
|
44
125
|
private static _createDeviceBusyError;
|
|
@@ -47,24 +128,29 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
47
128
|
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
48
129
|
getSupportedChains(): ChainCapability[];
|
|
49
130
|
private callChain;
|
|
50
|
-
evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams): Promise<Response<EvmAddress>>;
|
|
51
|
-
evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams): Promise<Response<EvmSignedTx>>;
|
|
52
|
-
evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams): Promise<Response<EvmSignature>>;
|
|
53
|
-
evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams): Promise<Response<EvmSignature>>;
|
|
54
|
-
btcGetAddress(connectId: string, deviceId: string, params: BtcGetAddressParams): Promise<Response<BtcAddress>>;
|
|
55
|
-
btcGetPublicKey(connectId: string, deviceId: string, params: BtcGetPublicKeyParams): Promise<Response<BtcPublicKey>>;
|
|
56
|
-
btcSignTransaction(connectId: string, deviceId: string, params: BtcSignTxParams): Promise<Response<BtcSignedTx>>;
|
|
57
|
-
btcSignPsbt(connectId: string, deviceId: string, params: BtcSignPsbtParams): Promise<Response<BtcSignedPsbt>>;
|
|
58
|
-
btcSignMessage(connectId: string, deviceId: string, params: BtcSignMsgParams): Promise<Response<BtcSignature>>;
|
|
59
|
-
btcGetMasterFingerprint(connectId: string, deviceId: string): Promise<Response<{
|
|
131
|
+
evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams, commonParams?: ICommonCallParams): Promise<Response<EvmAddress>>;
|
|
132
|
+
evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams, commonParams?: ICommonCallParams): Promise<Response<EvmSignedTx>>;
|
|
133
|
+
evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams, commonParams?: ICommonCallParams): Promise<Response<EvmSignature>>;
|
|
134
|
+
evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams, commonParams?: ICommonCallParams): Promise<Response<EvmSignature>>;
|
|
135
|
+
btcGetAddress(connectId: string, deviceId: string, params: BtcGetAddressParams, commonParams?: ICommonCallParams): Promise<Response<BtcAddress>>;
|
|
136
|
+
btcGetPublicKey(connectId: string, deviceId: string, params: BtcGetPublicKeyParams, commonParams?: ICommonCallParams): Promise<Response<BtcPublicKey>>;
|
|
137
|
+
btcSignTransaction(connectId: string, deviceId: string, params: BtcSignTxParams, commonParams?: ICommonCallParams): Promise<Response<BtcSignedTx>>;
|
|
138
|
+
btcSignPsbt(connectId: string, deviceId: string, params: BtcSignPsbtParams, commonParams?: ICommonCallParams): Promise<Response<BtcSignedPsbt>>;
|
|
139
|
+
btcSignMessage(connectId: string, deviceId: string, params: BtcSignMsgParams, commonParams?: ICommonCallParams): Promise<Response<BtcSignature>>;
|
|
140
|
+
btcGetMasterFingerprint(connectId: string, deviceId: string, commonParams?: ICommonCallParams): Promise<Response<{
|
|
60
141
|
masterFingerprint: string;
|
|
61
142
|
}>>;
|
|
62
|
-
solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams): Promise<Response<SolAddress>>;
|
|
63
|
-
solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams): Promise<Response<SolSignedTx>>;
|
|
64
|
-
solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams): Promise<Response<SolSignature>>;
|
|
65
|
-
tronGetAddress(connectId: string, deviceId: string, params: TronGetAddressParams): Promise<Response<TronAddress>>;
|
|
66
|
-
tronSignTransaction(connectId: string, deviceId: string, params: TronSignTxParams): Promise<Response<TronSignedTx>>;
|
|
67
|
-
tronSignMessage(connectId: string, deviceId: string, params: TronSignMsgParams): Promise<Response<TronSignature>>;
|
|
143
|
+
solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams, commonParams?: ICommonCallParams): Promise<Response<SolAddress>>;
|
|
144
|
+
solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams, commonParams?: ICommonCallParams): Promise<Response<SolSignedTx>>;
|
|
145
|
+
solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams, commonParams?: ICommonCallParams): Promise<Response<SolSignature>>;
|
|
146
|
+
tronGetAddress(connectId: string, deviceId: string, params: TronGetAddressParams, commonParams?: ICommonCallParams): Promise<Response<TronAddress>>;
|
|
147
|
+
tronSignTransaction(connectId: string, deviceId: string, params: TronSignTxParams, commonParams?: ICommonCallParams): Promise<Response<TronSignedTx>>;
|
|
148
|
+
tronSignMessage(connectId: string, deviceId: string, params: TronSignMsgParams, commonParams?: ICommonCallParams): Promise<Response<TronSignature>>;
|
|
149
|
+
installApp(connectId: string, appName: string): Promise<Response<void>>;
|
|
150
|
+
listInstalledApps(connectId: string): Promise<Response<AppMetadata[]>>;
|
|
151
|
+
listAvailableApps(connectId: string): Promise<Response<AppMetadata[]>>;
|
|
152
|
+
getLedgerFirmwareVersion(connectId: string): Promise<Response<FirmwareVersion>>;
|
|
153
|
+
getLedgerDeviceInfo(connectId: string): Promise<Response<LedgerDeviceInfo>>;
|
|
68
154
|
on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
69
155
|
on(event: string, listener: DeviceEventListener): void;
|
|
70
156
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
@@ -96,7 +182,7 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
96
182
|
*
|
|
97
183
|
* - If a session already exists for the given connectId, reuse it.
|
|
98
184
|
* - If ANY session exists (Ledger IDs are ephemeral), reuse it.
|
|
99
|
-
* - Otherwise: search → 1 device
|
|
185
|
+
* - Otherwise: search → exactly 1 USB device auto-connects; multiple or none throws.
|
|
100
186
|
*/
|
|
101
187
|
private _connectingPromise;
|
|
102
188
|
private _waitForDeviceConnect;
|
|
@@ -109,11 +195,11 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
109
195
|
*/
|
|
110
196
|
private _gateBtcHighIndex;
|
|
111
197
|
private _waitForBtcHighIndexConfirm;
|
|
198
|
+
private _waitForInstallAppConfirm;
|
|
112
199
|
private ensureConnected;
|
|
113
200
|
private _doConnect;
|
|
114
201
|
private _connectFirstOrSelect;
|
|
115
202
|
private _connectDeviceOrThrow;
|
|
116
|
-
private _chooseDeviceFromList;
|
|
117
203
|
/**
|
|
118
204
|
* Call the connector with automatic session resolution and disconnect retry.
|
|
119
205
|
*
|
|
@@ -122,6 +208,23 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
122
208
|
* 3. Calls connector.call()
|
|
123
209
|
* 4. On disconnect error: clears stale session, re-connects, retries once
|
|
124
210
|
*/
|
|
211
|
+
/**
|
|
212
|
+
* Unwrap a `ConnectorCallResult` back into the throw-based control flow this
|
|
213
|
+
* class relies on. On failure, rehydrate a FLAT Error (lifting `params.*`
|
|
214
|
+
* back to own-properties) so the downstream recovery predicates
|
|
215
|
+
* (`isStuckAppStateError`, `isDeviceLockedError`, …) and `mapLedgerError`
|
|
216
|
+
* (which read `err._tag` / `err.code` / `err.appName` / `err.originalError`)
|
|
217
|
+
* keep working exactly as before — the Result shape is confined to the
|
|
218
|
+
* connector boundary.
|
|
219
|
+
*/
|
|
220
|
+
private _unwrapConnectorResult;
|
|
221
|
+
/**
|
|
222
|
+
* `connector.call` + result unwrap, optionally raced against an abort
|
|
223
|
+
* signal. Returns the call payload or throws the rehydrated error. All
|
|
224
|
+
* `this.connector.call` usage goes through here so the Result→throw seam
|
|
225
|
+
* lives in one place.
|
|
226
|
+
*/
|
|
227
|
+
private _callConnector;
|
|
125
228
|
private connectorCall;
|
|
126
229
|
/**
|
|
127
230
|
* Race a promise against an abort signal. On abort, rejects with
|
|
@@ -132,6 +235,16 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
132
235
|
private static _throwIfAborted;
|
|
133
236
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
134
237
|
private _runConnectorCall;
|
|
238
|
+
/**
|
|
239
|
+
* Stuck-app recovery: pause for the device's UI transition, then retry once.
|
|
240
|
+
*
|
|
241
|
+
* Caller has already cleared the session + reset connector. We wait so Stax
|
|
242
|
+
* finishes its post-CloseApp animation, then go through ensureConnected +
|
|
243
|
+
* fingerprint check + call exactly once. Caller decides what to do on a
|
|
244
|
+
* second stuck-app hit.
|
|
245
|
+
*/
|
|
246
|
+
private _retryAfterStuckApp;
|
|
247
|
+
private _sleepAbortable;
|
|
135
248
|
/**
|
|
136
249
|
* Clear stale session, reconnect, and retry the call.
|
|
137
250
|
*
|
|
@@ -166,33 +279,6 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
166
279
|
private connectorDeviceToDeviceInfo;
|
|
167
280
|
}
|
|
168
281
|
|
|
169
|
-
/**
|
|
170
|
-
* Re-export DMK types under local aliases for backward compatibility.
|
|
171
|
-
* These replace the previous duck-typed interfaces with the real SDK types.
|
|
172
|
-
*/
|
|
173
|
-
type DmkDiscoveredDevice = DiscoveredDevice;
|
|
174
|
-
/**
|
|
175
|
-
* DMK DeviceAction — the Observable-based return type of all DMK signer methods.
|
|
176
|
-
*
|
|
177
|
-
* This is a permissive alias for `ExecuteDeviceActionReturnType` that accepts
|
|
178
|
-
* any Error and IntermediateValue generics. Signer wrapper code only cares about
|
|
179
|
-
* the Output type and the observable/cancel shape.
|
|
180
|
-
*/
|
|
181
|
-
type DeviceAction<T> = ExecuteDeviceActionReturnType<T, any, any>;
|
|
182
|
-
/**
|
|
183
|
-
* DMK DeviceActionState — re-exported with permissive Error/IntermediateValue.
|
|
184
|
-
* The real type is a discriminated union on `status`.
|
|
185
|
-
*/
|
|
186
|
-
type DeviceActionState<T> = DeviceActionState$1<T, any, any>;
|
|
187
|
-
/** ETH address result — re-exported from DMK for backward compatibility. */
|
|
188
|
-
type SignerEvmAddress = Address;
|
|
189
|
-
/** ETH signature result — re-exported from DMK for backward compatibility. */
|
|
190
|
-
type SignerEvmSignature = Signature;
|
|
191
|
-
/** BTC address result (WalletAddress not exported from DMK top-level). */
|
|
192
|
-
interface SignerBtcAddress {
|
|
193
|
-
address: string;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
282
|
/**
|
|
197
283
|
* Manages device discovery, connection, and session tracking.
|
|
198
284
|
* Wraps DMK's Observable APIs into simpler imperative calls.
|
|
@@ -244,6 +330,14 @@ declare class LedgerDeviceManager {
|
|
|
244
330
|
requestDevice(): Promise<void>;
|
|
245
331
|
/** Lookup a previously-discovered device's display name. */
|
|
246
332
|
getDeviceName(deviceId: string): string | undefined;
|
|
333
|
+
/** Lookup minimal model/signal info from a previously-discovered device. */
|
|
334
|
+
getDiscoveredDeviceInfo(deviceId: string): {
|
|
335
|
+
model?: string;
|
|
336
|
+
modelName?: string;
|
|
337
|
+
name?: string;
|
|
338
|
+
rssi?: number | null;
|
|
339
|
+
} | undefined;
|
|
340
|
+
hasDiscoveredDevice(deviceId: string): boolean;
|
|
247
341
|
/** Connect to a previously discovered device. Returns sessionId. */
|
|
248
342
|
connect(deviceId: string): Promise<string>;
|
|
249
343
|
/** Disconnect a session. */
|
|
@@ -288,22 +382,24 @@ interface LedgerConnectorBaseOptions {
|
|
|
288
382
|
* Subclasses only need to:
|
|
289
383
|
* 1. Supply a transport factory via the constructor.
|
|
290
384
|
* 2. Optionally override `_resolveConnectId()` for transport-specific
|
|
291
|
-
* device identity resolution
|
|
385
|
+
* device identity resolution.
|
|
386
|
+
*
|
|
387
|
+
* Invariant: one instance = one transport. `connectionType` is fixed at
|
|
388
|
+
* construction. To switch transport (e.g. desktop BLE ↔ WebHID), the host
|
|
389
|
+
* must build a new connector instance and replace the old one — don't add
|
|
390
|
+
* multiple transports to a single instance. Lifting this constraint would
|
|
391
|
+
* require routing `connectionType` from `descriptor.transport` per-device
|
|
392
|
+
* and updating every `this.connectionType` branch in this file.
|
|
292
393
|
*/
|
|
293
394
|
declare class LedgerConnectorBase implements IConnector {
|
|
294
395
|
private _deviceManager;
|
|
295
396
|
private _signerManager;
|
|
397
|
+
private _deviceAppsManager;
|
|
296
398
|
private _dmk;
|
|
297
399
|
private readonly _eventHandlers;
|
|
298
400
|
private readonly _providedDmk;
|
|
299
401
|
private readonly _createTransport;
|
|
300
402
|
readonly connectionType: ConnectionType;
|
|
301
|
-
private _connectIdToPath;
|
|
302
|
-
private _pathToConnectId;
|
|
303
|
-
/** Get DMK path from external connectId. Falls back to connectId itself. */
|
|
304
|
-
private _getPathForConnectId;
|
|
305
|
-
/** Get external connectId from DMK path. Falls back to path itself. */
|
|
306
|
-
private _getConnectIdForPath;
|
|
307
403
|
private readonly _cancellers;
|
|
308
404
|
private readonly _sessionStateSubs;
|
|
309
405
|
/**
|
|
@@ -314,6 +410,10 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
314
410
|
protected _importLedgerKit: (pkg: string) => Promise<any>;
|
|
315
411
|
/** Context object passed to per-chain handler functions. */
|
|
316
412
|
private readonly _ctx;
|
|
413
|
+
/** When true, BLE direct-connect throws NotAdvertising if the pre-flight
|
|
414
|
+
* scan can't see the device — guard for GATT stacks that wedge on
|
|
415
|
+
* non-advertising peripherals (iOS). */
|
|
416
|
+
private readonly _requirePreFlightScan;
|
|
317
417
|
constructor(createTransport: TransportFactory, options?: {
|
|
318
418
|
connectionType?: ConnectionType;
|
|
319
419
|
dmk?: DeviceManagementKit;
|
|
@@ -323,11 +423,13 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
323
423
|
* For Metro (React Native): pass a resolver that uses CJS paths.
|
|
324
424
|
*/
|
|
325
425
|
importLedgerKit?: (pkg: string) => Promise<any>;
|
|
426
|
+
/** Default false. RN-iOS subclass should pass `true`. */
|
|
427
|
+
requirePreFlightScan?: boolean;
|
|
326
428
|
});
|
|
327
429
|
/**
|
|
328
430
|
* Resolve the connectId for a discovered device descriptor.
|
|
329
431
|
* Default: use the DMK path (ephemeral UUID).
|
|
330
|
-
* Override in subclasses
|
|
432
|
+
* Override in subclasses only when the public connectId differs from the transport path.
|
|
331
433
|
*/
|
|
332
434
|
protected _resolveConnectId(descriptor: DeviceDescriptor): string;
|
|
333
435
|
/**
|
|
@@ -346,13 +448,12 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
346
448
|
* `LedgerAdapter._sessions` map would hold a dead session entry until
|
|
347
449
|
* the next call hit `DeviceSessionNotFound`.
|
|
348
450
|
*
|
|
349
|
-
*
|
|
350
|
-
* doesn't break the connect path.
|
|
451
|
+
* Subscribe failure is fatal — see the inline note at the subscribe call.
|
|
351
452
|
*/
|
|
352
453
|
private _watchSessionState;
|
|
353
454
|
private _unwatchSessionState;
|
|
354
455
|
private _handleAutonomousDisconnect;
|
|
355
|
-
call(sessionId: string, method: string, params: unknown): Promise<
|
|
456
|
+
call(sessionId: string, method: string, params: unknown): Promise<ConnectorCallResult>;
|
|
356
457
|
private _dispatch;
|
|
357
458
|
cancel(sessionId: string): Promise<void>;
|
|
358
459
|
uiResponse(_response: UiResponseEvent): void;
|
|
@@ -368,15 +469,15 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
368
469
|
private _initManagers;
|
|
369
470
|
private _getDeviceManager;
|
|
370
471
|
private _getSignerManager;
|
|
472
|
+
private _getDeviceAppsManager;
|
|
371
473
|
private _invalidateSession;
|
|
372
474
|
/**
|
|
373
475
|
* Replace an old session with a new one after app switch.
|
|
374
|
-
*
|
|
375
|
-
* and emits device-connect so the adapter updates its _sessions Map.
|
|
476
|
+
* Emits device-connect so the adapter updates its _sessions Map.
|
|
376
477
|
*/
|
|
377
478
|
private _replaceSession;
|
|
378
479
|
/**
|
|
379
|
-
* Light reset: clear signer/session state but keep DMK
|
|
480
|
+
* Light reset: clear signer/session state but keep DMK alive.
|
|
380
481
|
* Used by connect() retry — we want to re-discover with the same transport.
|
|
381
482
|
*
|
|
382
483
|
* Note: drops the device manager but tears down its RxJS subs first via
|
|
@@ -395,31 +496,6 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
395
496
|
private _wrapError;
|
|
396
497
|
}
|
|
397
498
|
|
|
398
|
-
/** Optional context attached to the rejection when a canceller fires. */
|
|
399
|
-
interface CancelReason {
|
|
400
|
-
code?: number;
|
|
401
|
-
tag?: string;
|
|
402
|
-
message?: string;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Convert a DMK DeviceAction (Observable-based) into a Promise.
|
|
406
|
-
* Handles pending -> completed/error state transitions and interaction callbacks.
|
|
407
|
-
*
|
|
408
|
-
* Tracks the last DMK step observed (e.g. `signer.eth.steps.blindSignTransactionFallback`)
|
|
409
|
-
* and attaches it to the rejected error as a non-enumerable `_lastStep` property,
|
|
410
|
-
* so upstream error classifiers can distinguish failure contexts (e.g. Blind signing
|
|
411
|
-
* disabled vs. generic Invalid data).
|
|
412
|
-
*
|
|
413
|
-
* @param timeoutMs Idle watchdog ms. Re-armed on each emission, paused
|
|
414
|
-
* during interactive pending. 0 disables. Default 65s
|
|
415
|
-
* (covers DMK's 60s + margin; we're a backstop only).
|
|
416
|
-
* @param onRegisterCanceller Optional callback that receives a function which, when
|
|
417
|
-
* called, unsubscribes and cancels the underlying DeviceAction
|
|
418
|
-
* (releases DMK's IntentQueue slot). Caller is responsible
|
|
419
|
-
* for invoking the canceller on timeout/abort scenarios.
|
|
420
|
-
*/
|
|
421
|
-
declare function deviceActionToPromise<T>(action: DeviceAction<T>, onInteraction?: (interaction: string) => void, timeoutMs?: number, onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void): Promise<T>;
|
|
422
|
-
|
|
423
499
|
/**
|
|
424
500
|
* Wraps Ledger's SDK signer (Observable-based DeviceActions) into
|
|
425
501
|
* a simple async interface returning plain serializable data.
|
|
@@ -446,8 +522,14 @@ type SignerEthBuilderFn = (args: {
|
|
|
446
522
|
dmk: DeviceManagementKit;
|
|
447
523
|
sessionId: string;
|
|
448
524
|
}) => {
|
|
525
|
+
withContextModule?(contextModule: ContextModule): {
|
|
526
|
+
build(): SignerEth$1;
|
|
527
|
+
};
|
|
449
528
|
build(): SignerEth$1;
|
|
450
529
|
} | Promise<{
|
|
530
|
+
withContextModule?(contextModule: ContextModule): {
|
|
531
|
+
build(): SignerEth$1;
|
|
532
|
+
};
|
|
451
533
|
build(): SignerEth$1;
|
|
452
534
|
}>;
|
|
453
535
|
/**
|
|
@@ -463,6 +545,8 @@ declare class SignerManager {
|
|
|
463
545
|
invalidate(_sessionId: string): void;
|
|
464
546
|
clearAll(): void;
|
|
465
547
|
private static _defaultBuilder;
|
|
548
|
+
private static _createContextModule;
|
|
549
|
+
static wrapBlindSigningReportNonBlocking<T extends ContextModule>(contextModule: T): T;
|
|
466
550
|
}
|
|
467
551
|
|
|
468
552
|
type BtcWallet = Parameters<SignerBtc$1['getWalletAddress']>[0];
|
|
@@ -655,12 +739,7 @@ type SdkEventListener = (event: SdkEvent) => void;
|
|
|
655
739
|
declare function onSdkEvent(listener: SdkEventListener): () => void;
|
|
656
740
|
declare function offSdkEvent(listener: SdkEventListener): void;
|
|
657
741
|
|
|
658
|
-
|
|
659
|
-
* Extract the stable 4-digit HEX identifier from a Ledger BLE device name.
|
|
660
|
-
* e.g., "Nano X 123A" -> "123A", "Ledger Nano X AB12" -> "AB12"
|
|
661
|
-
* Returns undefined if no valid HEX suffix found.
|
|
662
|
-
*/
|
|
663
|
-
declare function extractBleHexId(name?: string): string | undefined;
|
|
742
|
+
declare function debugLog(...args: unknown[]): void;
|
|
664
743
|
|
|
665
744
|
/**
|
|
666
745
|
* Ledger DMK transport identifiers that represent BLE devices.
|
|
@@ -675,6 +754,5 @@ declare function extractBleHexId(name?: string): string | undefined;
|
|
|
675
754
|
declare function isLedgerDmkBleTransport(transport?: string): boolean;
|
|
676
755
|
declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
|
|
677
756
|
declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
|
|
678
|
-
declare function isValidLedgerBleConnectId(connectId?: string): boolean;
|
|
679
757
|
|
|
680
|
-
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,
|
|
758
|
+
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 };
|