@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.11 → 1.1.26-alpha.30
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 +154 -134
- package/dist/index.d.ts +154 -134
- package/dist/index.js +881 -328
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +889 -338
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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,
|
|
2
|
-
import {
|
|
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';
|
|
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 { SignerBtc as SignerBtc$1 } from '@ledgerhq/device-signer-kit-bitcoin';
|
|
5
5
|
import { SignerSolana } from '@ledgerhq/device-signer-kit-solana';
|
|
@@ -13,16 +13,6 @@ interface LedgerAdapterOptions {
|
|
|
13
13
|
*/
|
|
14
14
|
handleSelectDevice?: boolean;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Ledger hardware wallet adapter that delegates to an IConnector.
|
|
18
|
-
*
|
|
19
|
-
* This is a thin translation layer that:
|
|
20
|
-
* - Accepts a pre-configured IConnector (transport decisions are made at connector creation time)
|
|
21
|
-
* - Translates IHardwareWallet method calls to connector.call() invocations
|
|
22
|
-
* - Maps connector results/errors to our Response<T> format with enriched error messages
|
|
23
|
-
* - Translates connector events to HardwareEventMap events
|
|
24
|
-
* - Emits `REQUEST_DEVICE_PERMISSION` for OS-level permission checks
|
|
25
|
-
*/
|
|
26
16
|
declare class LedgerAdapter implements IHardwareWallet {
|
|
27
17
|
readonly vendor: "ledger";
|
|
28
18
|
private readonly connector;
|
|
@@ -31,15 +21,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
31
21
|
private _discoveredDevices;
|
|
32
22
|
private _sessions;
|
|
33
23
|
private readonly _uiRegistry;
|
|
24
|
+
private _btcHighIndexConfirmedThisSession;
|
|
34
25
|
private readonly _jobQueue;
|
|
26
|
+
private _doConnectAbortController;
|
|
35
27
|
constructor(connector: IConnector, options?: LedgerAdapterOptions);
|
|
36
|
-
/**
|
|
37
|
-
* Classify a method's interruptibility.
|
|
38
|
-
* - Signing / typed data / transaction → 'confirm' (user may decide via preemption UI)
|
|
39
|
-
* - Read-only queries (getAddress / getPublicKey / getMasterFingerprint) → 'safe'
|
|
40
|
-
* (auto-cancels any pending read for the same device)
|
|
41
|
-
*/
|
|
42
|
-
private static _getInterruptibility;
|
|
43
28
|
get activeTransport(): TransportType | null;
|
|
44
29
|
getAvailableTransports(): TransportType[];
|
|
45
30
|
switchTransport(_type: TransportType): Promise<void>;
|
|
@@ -53,6 +38,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
53
38
|
dispose(): Promise<void>;
|
|
54
39
|
uiResponse(response: UiResponseEvent): void;
|
|
55
40
|
searchDevices(): Promise<DeviceInfo[]>;
|
|
41
|
+
private static readonly MAX_BUSINESS_RETRY_BUDGET;
|
|
42
|
+
private static readonly MAX_DOCONNECT_CONFIRMS;
|
|
43
|
+
private _lastCancelReason;
|
|
44
|
+
private static _createDeviceBusyError;
|
|
56
45
|
connectDevice(connectId: string): Promise<Response<string>>;
|
|
57
46
|
disconnectDevice(connectId: string): Promise<void>;
|
|
58
47
|
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
@@ -109,12 +98,21 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
109
98
|
* - If ANY session exists (Ledger IDs are ephemeral), reuse it.
|
|
110
99
|
* - Otherwise: search → 1 device: auto-connect, multiple: ask user, 0: throw.
|
|
111
100
|
*/
|
|
112
|
-
private static readonly MAX_DEVICE_RETRY;
|
|
113
101
|
private _connectingPromise;
|
|
114
102
|
private _waitForDeviceConnect;
|
|
103
|
+
/**
|
|
104
|
+
* Decide whether a BTC pubkey call needs `showOnDevice=true` because of
|
|
105
|
+
* the BTC App's account-index policy, asking the user once per session.
|
|
106
|
+
*
|
|
107
|
+
* Returns the params to pass through (with `showOnDevice` possibly
|
|
108
|
+
* promoted), or `null` if the user declined.
|
|
109
|
+
*/
|
|
110
|
+
private _gateBtcHighIndex;
|
|
111
|
+
private _waitForBtcHighIndexConfirm;
|
|
115
112
|
private ensureConnected;
|
|
116
113
|
private _doConnect;
|
|
117
114
|
private _connectFirstOrSelect;
|
|
115
|
+
private _connectDeviceOrThrow;
|
|
118
116
|
private _chooseDeviceFromList;
|
|
119
117
|
/**
|
|
120
118
|
* Call the connector with automatic session resolution and disconnect retry.
|
|
@@ -126,11 +124,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
126
124
|
*/
|
|
127
125
|
private connectorCall;
|
|
128
126
|
/**
|
|
129
|
-
* Race a promise against an abort signal.
|
|
130
|
-
* signal
|
|
131
|
-
* actually be cancelled on Ledger DMK, but the caller gets the abort immediately.
|
|
127
|
+
* Race a promise against an abort signal. On abort, rejects with
|
|
128
|
+
* signal.reason → instance _lastCancelReason → generic Error('Aborted').
|
|
132
129
|
*/
|
|
133
|
-
private
|
|
130
|
+
private _abortable;
|
|
134
131
|
/** Throw an AbortError if signal is already aborted. */
|
|
135
132
|
private static _throwIfAborted;
|
|
136
133
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
@@ -138,12 +135,9 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
138
135
|
/**
|
|
139
136
|
* Clear stale session, reconnect, and retry the call.
|
|
140
137
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* — process killed, USB yanked, browser kept the offscreen page across
|
|
145
|
-
* a session boundary). In that case we fully `connector.reset()` to
|
|
146
|
-
* force a fresh DMK + transport on the next round.
|
|
138
|
+
* Timeout recovery starts with a full connector reset. After an APDU
|
|
139
|
+
* timeout, DMK/transport state may still emit malformed responses; retrying
|
|
140
|
+
* on the same DMK can poison the next chain switch.
|
|
147
141
|
*/
|
|
148
142
|
private _retryWithFreshConnection;
|
|
149
143
|
/**
|
|
@@ -172,6 +166,103 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
172
166
|
private connectorDeviceToDeviceInfo;
|
|
173
167
|
}
|
|
174
168
|
|
|
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
|
+
/**
|
|
197
|
+
* Manages device discovery, connection, and session tracking.
|
|
198
|
+
* Wraps DMK's Observable APIs into simpler imperative calls.
|
|
199
|
+
*/
|
|
200
|
+
declare class LedgerDeviceManager {
|
|
201
|
+
private readonly _dmk;
|
|
202
|
+
private readonly _discovered;
|
|
203
|
+
private readonly _sessions;
|
|
204
|
+
private readonly _sessionToDevice;
|
|
205
|
+
private _listenSub;
|
|
206
|
+
constructor(dmk: DeviceManagementKit);
|
|
207
|
+
/**
|
|
208
|
+
* One-shot enumeration: subscribe to listenToAvailableDevices,
|
|
209
|
+
* take the first emission, unsubscribe, return DeviceDescriptors.
|
|
210
|
+
*/
|
|
211
|
+
enumerate(): Promise<DeviceDescriptor[]>;
|
|
212
|
+
/**
|
|
213
|
+
* Continuous listening: tracks device connect/disconnect via diffing.
|
|
214
|
+
*/
|
|
215
|
+
listen(onChange: (event: DeviceChangeEvent) => void): void;
|
|
216
|
+
stopListening(): void;
|
|
217
|
+
/**
|
|
218
|
+
* Resolve to the latest snapshot of advertising devices observed within
|
|
219
|
+
* `timeoutMs`. Rewrites `_discovered` so it tracks the live list.
|
|
220
|
+
*
|
|
221
|
+
* `listenToAvailableDevices` is a BehaviorSubject — it emits the cached
|
|
222
|
+
* list on subscribe and *only* re-emits when the list changes. A stable
|
|
223
|
+
* list of currently-advertising devices therefore produces only the
|
|
224
|
+
* subscription frame; treating that frame as "fossil to be discarded"
|
|
225
|
+
* caused devices to flicker in/out of the UI as searches alternated
|
|
226
|
+
* between "saw a change frame" and "saw only the cached frame".
|
|
227
|
+
*
|
|
228
|
+
* The window still gives a chance for the active scan to update the list
|
|
229
|
+
* (e.g. drop a peripheral that just stopped broadcasting), but if nothing
|
|
230
|
+
* changes we trust the snapshot — DMK silence on a stable list means
|
|
231
|
+
* "everything's still there".
|
|
232
|
+
*/
|
|
233
|
+
getLiveDevices(timeoutMs?: number): Promise<DmkDiscoveredDevice[]>;
|
|
234
|
+
/**
|
|
235
|
+
* Trigger browser device selection (WebHID requestDevice).
|
|
236
|
+
* Starts discovery for a short period, then stops.
|
|
237
|
+
*/
|
|
238
|
+
/**
|
|
239
|
+
* Start BLE discovery if not already running.
|
|
240
|
+
* Does NOT stop — DMK keeps scanning in the background so that
|
|
241
|
+
* listenToAvailableDevices() always has fresh data.
|
|
242
|
+
*/
|
|
243
|
+
private _discoverySub;
|
|
244
|
+
requestDevice(): Promise<void>;
|
|
245
|
+
/** Lookup a previously-discovered device's display name. */
|
|
246
|
+
getDeviceName(deviceId: string): string | undefined;
|
|
247
|
+
/** Connect to a previously discovered device. Returns sessionId. */
|
|
248
|
+
connect(deviceId: string): Promise<string>;
|
|
249
|
+
/** Disconnect a session. */
|
|
250
|
+
disconnect(sessionId: string): Promise<void>;
|
|
251
|
+
getSessionId(deviceId: string): string | undefined;
|
|
252
|
+
getDeviceId(sessionId: string): string | undefined;
|
|
253
|
+
/** Get the underlying DMK instance (needed by SignerManager). */
|
|
254
|
+
getDmk(): DeviceManagementKit;
|
|
255
|
+
stopDiscovery(): void;
|
|
256
|
+
dispose(): void;
|
|
257
|
+
/**
|
|
258
|
+
* Tear down RxJS subscriptions and local state without closing the DMK.
|
|
259
|
+
* For light-reset paths that want to drop session state but keep the
|
|
260
|
+
* underlying transport alive for retry. Call this instead of orphaning
|
|
261
|
+
* the manager — bare null assignment leaks _listenSub / _discoverySub.
|
|
262
|
+
*/
|
|
263
|
+
disposeKeepingDmk(): void;
|
|
264
|
+
}
|
|
265
|
+
|
|
175
266
|
/**
|
|
176
267
|
* A function that lazily loads and returns the transport factory
|
|
177
268
|
* for the Ledger DMK builder (e.g. webHidTransportFactory, rnBleTransportFactory).
|
|
@@ -209,16 +300,12 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
209
300
|
readonly connectionType: ConnectionType;
|
|
210
301
|
private _connectIdToPath;
|
|
211
302
|
private _pathToConnectId;
|
|
212
|
-
/** Register a connectId <-> path mapping from a device descriptor. */
|
|
213
|
-
private _registerDeviceId;
|
|
214
303
|
/** Get DMK path from external connectId. Falls back to connectId itself. */
|
|
215
304
|
private _getPathForConnectId;
|
|
216
305
|
/** Get external connectId from DMK path. Falls back to path itself. */
|
|
217
306
|
private _getConnectIdForPath;
|
|
218
307
|
private readonly _cancellers;
|
|
219
308
|
private readonly _sessionStateSubs;
|
|
220
|
-
private _diagDeviceListSub;
|
|
221
|
-
private _diagDeviceListPrev;
|
|
222
309
|
/**
|
|
223
310
|
* Resolves a Ledger signer kit module by package name.
|
|
224
311
|
* Override via constructor to use CJS paths for Metro (React Native).
|
|
@@ -243,6 +330,12 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
243
330
|
* Override in subclasses to extract stable identifiers (e.g. BLE hex ID).
|
|
244
331
|
*/
|
|
245
332
|
protected _resolveConnectId(descriptor: DeviceDescriptor): string;
|
|
333
|
+
/**
|
|
334
|
+
* Authoritative discovery for this transport. Default = enumerate snapshot
|
|
335
|
+
* (USB/HID). BLE overrides to drive from a live scan window since DMK's
|
|
336
|
+
* enumerate() cache survives peripherals going offline.
|
|
337
|
+
*/
|
|
338
|
+
protected _discoverDescriptors(dm: LedgerDeviceManager): Promise<DeviceDescriptor[]>;
|
|
246
339
|
searchDevices(): Promise<ConnectorDevice[]>;
|
|
247
340
|
connect(deviceId?: string): Promise<ConnectorSession>;
|
|
248
341
|
disconnect(sessionId: string): Promise<void>;
|
|
@@ -259,15 +352,6 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
259
352
|
private _watchSessionState;
|
|
260
353
|
private _unwatchSessionState;
|
|
261
354
|
private _handleAutonomousDisconnect;
|
|
262
|
-
/**
|
|
263
|
-
* Start a long-lived listenToAvailableDevices subscription whose only job
|
|
264
|
-
* is to log every emission (with diff vs previous) so we can determine
|
|
265
|
-
* whether DMK proactively re-emits the device list when a USB device is
|
|
266
|
-
* unplugged or a BLE peripheral disappears. Pure observation — does NOT
|
|
267
|
-
* touch any cache or emit any event. See _diagDeviceListSub comment for
|
|
268
|
-
* rationale.
|
|
269
|
-
*/
|
|
270
|
-
private _startDiagnosticDeviceListListen;
|
|
271
355
|
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
272
356
|
private _dispatch;
|
|
273
357
|
cancel(sessionId: string): Promise<void>;
|
|
@@ -292,8 +376,12 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
292
376
|
*/
|
|
293
377
|
private _replaceSession;
|
|
294
378
|
/**
|
|
295
|
-
* Light reset: clear signer/session state but keep DMK
|
|
379
|
+
* Light reset: clear signer/session state but keep DMK and ID mapping alive.
|
|
296
380
|
* Used by connect() retry — we want to re-discover with the same transport.
|
|
381
|
+
*
|
|
382
|
+
* Note: drops the device manager but tears down its RxJS subs first via
|
|
383
|
+
* disposeKeepingDmk(). Bare null-assignment would leak _listenSub /
|
|
384
|
+
* _discoverySub and double-scan after the next _initManagers().
|
|
297
385
|
*/
|
|
298
386
|
private _resetSignersAndSessions;
|
|
299
387
|
private _resetAll;
|
|
@@ -307,77 +395,6 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
307
395
|
private _wrapError;
|
|
308
396
|
}
|
|
309
397
|
|
|
310
|
-
/**
|
|
311
|
-
* Manages device discovery, connection, and session tracking.
|
|
312
|
-
* Wraps DMK's Observable APIs into simpler imperative calls.
|
|
313
|
-
*/
|
|
314
|
-
declare class LedgerDeviceManager {
|
|
315
|
-
private readonly _dmk;
|
|
316
|
-
private readonly _discovered;
|
|
317
|
-
private readonly _sessions;
|
|
318
|
-
private readonly _sessionToDevice;
|
|
319
|
-
private _listenSub;
|
|
320
|
-
constructor(dmk: DeviceManagementKit);
|
|
321
|
-
/**
|
|
322
|
-
* One-shot enumeration: subscribe to listenToAvailableDevices,
|
|
323
|
-
* take the first emission, unsubscribe, return DeviceDescriptors.
|
|
324
|
-
*/
|
|
325
|
-
enumerate(): Promise<DeviceDescriptor[]>;
|
|
326
|
-
/**
|
|
327
|
-
* Continuous listening: tracks device connect/disconnect via diffing.
|
|
328
|
-
*/
|
|
329
|
-
listen(onChange: (event: DeviceChangeEvent) => void): void;
|
|
330
|
-
stopListening(): void;
|
|
331
|
-
/**
|
|
332
|
-
* Trigger browser device selection (WebHID requestDevice).
|
|
333
|
-
* Starts discovery for a short period, then stops.
|
|
334
|
-
*/
|
|
335
|
-
/**
|
|
336
|
-
* Start BLE discovery if not already running.
|
|
337
|
-
* Does NOT stop — DMK keeps scanning in the background so that
|
|
338
|
-
* listenToAvailableDevices() always has fresh data.
|
|
339
|
-
*/
|
|
340
|
-
private _discoverySub;
|
|
341
|
-
requestDevice(): Promise<void>;
|
|
342
|
-
/** Connect to a previously discovered device. Returns sessionId. */
|
|
343
|
-
connect(deviceId: string): Promise<string>;
|
|
344
|
-
/** Disconnect a session. */
|
|
345
|
-
disconnect(sessionId: string): Promise<void>;
|
|
346
|
-
getSessionId(deviceId: string): string | undefined;
|
|
347
|
-
getDeviceId(sessionId: string): string | undefined;
|
|
348
|
-
/** Get the underlying DMK instance (needed by SignerManager). */
|
|
349
|
-
getDmk(): DeviceManagementKit;
|
|
350
|
-
stopDiscovery(): void;
|
|
351
|
-
dispose(): void;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Re-export DMK types under local aliases for backward compatibility.
|
|
356
|
-
* These replace the previous duck-typed interfaces with the real SDK types.
|
|
357
|
-
*/
|
|
358
|
-
type DmkDiscoveredDevice = DiscoveredDevice;
|
|
359
|
-
/**
|
|
360
|
-
* DMK DeviceAction — the Observable-based return type of all DMK signer methods.
|
|
361
|
-
*
|
|
362
|
-
* This is a permissive alias for `ExecuteDeviceActionReturnType` that accepts
|
|
363
|
-
* any Error and IntermediateValue generics. Signer wrapper code only cares about
|
|
364
|
-
* the Output type and the observable/cancel shape.
|
|
365
|
-
*/
|
|
366
|
-
type DeviceAction<T> = ExecuteDeviceActionReturnType<T, any, any>;
|
|
367
|
-
/**
|
|
368
|
-
* DMK DeviceActionState — re-exported with permissive Error/IntermediateValue.
|
|
369
|
-
* The real type is a discriminated union on `status`.
|
|
370
|
-
*/
|
|
371
|
-
type DeviceActionState<T> = DeviceActionState$1<T, any, any>;
|
|
372
|
-
/** ETH address result — re-exported from DMK for backward compatibility. */
|
|
373
|
-
type SignerEvmAddress = Address;
|
|
374
|
-
/** ETH signature result — re-exported from DMK for backward compatibility. */
|
|
375
|
-
type SignerEvmSignature = Signature;
|
|
376
|
-
/** BTC address result (WalletAddress not exported from DMK top-level). */
|
|
377
|
-
interface SignerBtcAddress {
|
|
378
|
-
address: string;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
398
|
/** Optional context attached to the rejection when a canceller fires. */
|
|
382
399
|
interface CancelReason {
|
|
383
400
|
code?: number;
|
|
@@ -393,8 +410,9 @@ interface CancelReason {
|
|
|
393
410
|
* so upstream error classifiers can distinguish failure contexts (e.g. Blind signing
|
|
394
411
|
* disabled vs. generic Invalid data).
|
|
395
412
|
*
|
|
396
|
-
* @param timeoutMs
|
|
397
|
-
*
|
|
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).
|
|
398
416
|
* @param onRegisterCanceller Optional callback that receives a function which, when
|
|
399
417
|
* called, unsubscribes and cancels the underlying DeviceAction
|
|
400
418
|
* (releases DMK's IntentQueue slot). Caller is responsible
|
|
@@ -598,30 +616,17 @@ declare class AppManager {
|
|
|
598
616
|
private _wait;
|
|
599
617
|
}
|
|
600
618
|
|
|
601
|
-
/**
|
|
602
|
-
* Ledger-specific Failure: adds `appName` for "the currently-open app" — a
|
|
603
|
-
* Ledger hardware concept not shared with other vendors, so it lives here
|
|
604
|
-
* rather than in core's generic Failure.
|
|
605
|
-
*/
|
|
606
619
|
type LedgerFailure = Omit<Failure, 'payload'> & {
|
|
607
620
|
payload: Failure['payload'] & {
|
|
608
621
|
appName?: string;
|
|
622
|
+
_tag?: string;
|
|
609
623
|
};
|
|
610
624
|
};
|
|
611
625
|
interface WrapErrorOptions {
|
|
612
|
-
/**
|
|
613
|
-
* Fallback app name when the raw error doesn't carry `appName` itself
|
|
614
|
-
* (DMK signer errors don't). Used by mapLedgerError so downstream
|
|
615
|
-
* AppNotOpen / WrongApp / AppTooOld toasts can interpolate `{appName}`.
|
|
616
|
-
*/
|
|
626
|
+
/** Fallback when err has no `appName` (DMK signer errors don't carry it). */
|
|
617
627
|
defaultAppName?: string;
|
|
618
628
|
}
|
|
619
|
-
|
|
620
|
-
* Structurally compatible with `Failure`; writes `appName` only when provided,
|
|
621
|
-
* so `'appName' in payload` is a reliable "has info" signal for consumers.
|
|
622
|
-
*/
|
|
623
|
-
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string): LedgerFailure;
|
|
624
|
-
/** Check if an error (or any error in its chain) represents a locked Ledger device. */
|
|
629
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>): LedgerFailure;
|
|
625
630
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
626
631
|
/**
|
|
627
632
|
* Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
|
|
@@ -657,4 +662,19 @@ declare function offSdkEvent(listener: SdkEventListener): void;
|
|
|
657
662
|
*/
|
|
658
663
|
declare function extractBleHexId(name?: string): string | undefined;
|
|
659
664
|
|
|
660
|
-
|
|
665
|
+
/**
|
|
666
|
+
* Ledger DMK transport identifiers that represent BLE devices.
|
|
667
|
+
*
|
|
668
|
+
* Known today:
|
|
669
|
+
* - "BLE": generic/web BLE descriptors
|
|
670
|
+
* - "RN_BLE": @ledgerhq/device-transport-kit-react-native-ble
|
|
671
|
+
*
|
|
672
|
+
* Keep the suffix check here so future DMK BLE transports (for example
|
|
673
|
+
* "FOO_BLE") are handled in one place instead of scattering string checks.
|
|
674
|
+
*/
|
|
675
|
+
declare function isLedgerDmkBleTransport(transport?: string): boolean;
|
|
676
|
+
declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
|
|
677
|
+
declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
|
|
678
|
+
declare function isValidLedgerBleConnectId(connectId?: string): boolean;
|
|
679
|
+
|
|
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, deviceActionToPromise, extractBleHexId, isDeviceLockedError, isLedgerBleConnectionType, isLedgerBleDescriptor, isLedgerDmkBleTransport, isValidLedgerBleConnectId, ledgerFailure, mapLedgerError, offSdkEvent, onSdkEvent };
|