@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.11 → 1.1.26-alpha.13
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 +174 -134
- package/dist/index.d.ts +174 -134
- package/dist/index.js +1117 -363
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1120 -368
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
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';
|
|
@@ -13,16 +14,6 @@ interface LedgerAdapterOptions {
|
|
|
13
14
|
*/
|
|
14
15
|
handleSelectDevice?: boolean;
|
|
15
16
|
}
|
|
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
17
|
declare class LedgerAdapter implements IHardwareWallet {
|
|
27
18
|
readonly vendor: "ledger";
|
|
28
19
|
private readonly connector;
|
|
@@ -31,15 +22,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
31
22
|
private _discoveredDevices;
|
|
32
23
|
private _sessions;
|
|
33
24
|
private readonly _uiRegistry;
|
|
25
|
+
private _btcHighIndexConfirmedThisSession;
|
|
34
26
|
private readonly _jobQueue;
|
|
27
|
+
private _doConnectAbortController;
|
|
35
28
|
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
29
|
get activeTransport(): TransportType | null;
|
|
44
30
|
getAvailableTransports(): TransportType[];
|
|
45
31
|
switchTransport(_type: TransportType): Promise<void>;
|
|
@@ -53,6 +39,11 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
53
39
|
dispose(): Promise<void>;
|
|
54
40
|
uiResponse(response: UiResponseEvent): void;
|
|
55
41
|
searchDevices(): Promise<DeviceInfo[]>;
|
|
42
|
+
private static readonly MAX_BUSINESS_RETRY_BUDGET;
|
|
43
|
+
private static readonly STUCK_APP_RETRY_DELAY_MS;
|
|
44
|
+
private static readonly MAX_DOCONNECT_CONFIRMS;
|
|
45
|
+
private _lastCancelReason;
|
|
46
|
+
private static _createDeviceBusyError;
|
|
56
47
|
connectDevice(connectId: string): Promise<Response<string>>;
|
|
57
48
|
disconnectDevice(connectId: string): Promise<void>;
|
|
58
49
|
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
@@ -109,12 +100,21 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
109
100
|
* - If ANY session exists (Ledger IDs are ephemeral), reuse it.
|
|
110
101
|
* - Otherwise: search → 1 device: auto-connect, multiple: ask user, 0: throw.
|
|
111
102
|
*/
|
|
112
|
-
private static readonly MAX_DEVICE_RETRY;
|
|
113
103
|
private _connectingPromise;
|
|
114
104
|
private _waitForDeviceConnect;
|
|
105
|
+
/**
|
|
106
|
+
* Decide whether a BTC pubkey call needs `showOnDevice=true` because of
|
|
107
|
+
* the BTC App's account-index policy, asking the user once per session.
|
|
108
|
+
*
|
|
109
|
+
* Returns the params to pass through (with `showOnDevice` possibly
|
|
110
|
+
* promoted), or `null` if the user declined.
|
|
111
|
+
*/
|
|
112
|
+
private _gateBtcHighIndex;
|
|
113
|
+
private _waitForBtcHighIndexConfirm;
|
|
115
114
|
private ensureConnected;
|
|
116
115
|
private _doConnect;
|
|
117
116
|
private _connectFirstOrSelect;
|
|
117
|
+
private _connectDeviceOrThrow;
|
|
118
118
|
private _chooseDeviceFromList;
|
|
119
119
|
/**
|
|
120
120
|
* Call the connector with automatic session resolution and disconnect retry.
|
|
@@ -126,24 +126,30 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
126
126
|
*/
|
|
127
127
|
private connectorCall;
|
|
128
128
|
/**
|
|
129
|
-
* Race a promise against an abort signal.
|
|
130
|
-
* signal
|
|
131
|
-
* actually be cancelled on Ledger DMK, but the caller gets the abort immediately.
|
|
129
|
+
* Race a promise against an abort signal. On abort, rejects with
|
|
130
|
+
* signal.reason → instance _lastCancelReason → generic Error('Aborted').
|
|
132
131
|
*/
|
|
133
|
-
private
|
|
132
|
+
private _abortable;
|
|
134
133
|
/** Throw an AbortError if signal is already aborted. */
|
|
135
134
|
private static _throwIfAborted;
|
|
136
135
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
137
136
|
private _runConnectorCall;
|
|
137
|
+
/**
|
|
138
|
+
* Stuck-app recovery: pause for the device's UI transition, then retry once.
|
|
139
|
+
*
|
|
140
|
+
* Caller has already cleared the session + reset connector. We wait so Stax
|
|
141
|
+
* finishes its post-CloseApp animation, then go through ensureConnected +
|
|
142
|
+
* fingerprint check + call exactly once. Caller decides what to do on a
|
|
143
|
+
* second stuck-app hit.
|
|
144
|
+
*/
|
|
145
|
+
private _retryAfterStuckApp;
|
|
146
|
+
private _sleepAbortable;
|
|
138
147
|
/**
|
|
139
148
|
* Clear stale session, reconnect, and retry the call.
|
|
140
149
|
*
|
|
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.
|
|
150
|
+
* Timeout recovery starts with a full connector reset. After an APDU
|
|
151
|
+
* timeout, DMK/transport state may still emit malformed responses; retrying
|
|
152
|
+
* on the same DMK can poison the next chain switch.
|
|
147
153
|
*/
|
|
148
154
|
private _retryWithFreshConnection;
|
|
149
155
|
/**
|
|
@@ -172,6 +178,103 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
172
178
|
private connectorDeviceToDeviceInfo;
|
|
173
179
|
}
|
|
174
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Re-export DMK types under local aliases for backward compatibility.
|
|
183
|
+
* These replace the previous duck-typed interfaces with the real SDK types.
|
|
184
|
+
*/
|
|
185
|
+
type DmkDiscoveredDevice = DiscoveredDevice;
|
|
186
|
+
/**
|
|
187
|
+
* DMK DeviceAction — the Observable-based return type of all DMK signer methods.
|
|
188
|
+
*
|
|
189
|
+
* This is a permissive alias for `ExecuteDeviceActionReturnType` that accepts
|
|
190
|
+
* any Error and IntermediateValue generics. Signer wrapper code only cares about
|
|
191
|
+
* the Output type and the observable/cancel shape.
|
|
192
|
+
*/
|
|
193
|
+
type DeviceAction<T> = ExecuteDeviceActionReturnType<T, any, any>;
|
|
194
|
+
/**
|
|
195
|
+
* DMK DeviceActionState — re-exported with permissive Error/IntermediateValue.
|
|
196
|
+
* The real type is a discriminated union on `status`.
|
|
197
|
+
*/
|
|
198
|
+
type DeviceActionState<T> = DeviceActionState$1<T, any, any>;
|
|
199
|
+
/** ETH address result — re-exported from DMK for backward compatibility. */
|
|
200
|
+
type SignerEvmAddress = Address;
|
|
201
|
+
/** ETH signature result — re-exported from DMK for backward compatibility. */
|
|
202
|
+
type SignerEvmSignature = Signature;
|
|
203
|
+
/** BTC address result (WalletAddress not exported from DMK top-level). */
|
|
204
|
+
interface SignerBtcAddress {
|
|
205
|
+
address: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Manages device discovery, connection, and session tracking.
|
|
210
|
+
* Wraps DMK's Observable APIs into simpler imperative calls.
|
|
211
|
+
*/
|
|
212
|
+
declare class LedgerDeviceManager {
|
|
213
|
+
private readonly _dmk;
|
|
214
|
+
private readonly _discovered;
|
|
215
|
+
private readonly _sessions;
|
|
216
|
+
private readonly _sessionToDevice;
|
|
217
|
+
private _listenSub;
|
|
218
|
+
constructor(dmk: DeviceManagementKit);
|
|
219
|
+
/**
|
|
220
|
+
* One-shot enumeration: subscribe to listenToAvailableDevices,
|
|
221
|
+
* take the first emission, unsubscribe, return DeviceDescriptors.
|
|
222
|
+
*/
|
|
223
|
+
enumerate(): Promise<DeviceDescriptor[]>;
|
|
224
|
+
/**
|
|
225
|
+
* Continuous listening: tracks device connect/disconnect via diffing.
|
|
226
|
+
*/
|
|
227
|
+
listen(onChange: (event: DeviceChangeEvent) => void): void;
|
|
228
|
+
stopListening(): void;
|
|
229
|
+
/**
|
|
230
|
+
* Resolve to the latest snapshot of advertising devices observed within
|
|
231
|
+
* `timeoutMs`. Rewrites `_discovered` so it tracks the live list.
|
|
232
|
+
*
|
|
233
|
+
* `listenToAvailableDevices` is a BehaviorSubject — it emits the cached
|
|
234
|
+
* list on subscribe and *only* re-emits when the list changes. A stable
|
|
235
|
+
* list of currently-advertising devices therefore produces only the
|
|
236
|
+
* subscription frame; treating that frame as "fossil to be discarded"
|
|
237
|
+
* caused devices to flicker in/out of the UI as searches alternated
|
|
238
|
+
* between "saw a change frame" and "saw only the cached frame".
|
|
239
|
+
*
|
|
240
|
+
* The window still gives a chance for the active scan to update the list
|
|
241
|
+
* (e.g. drop a peripheral that just stopped broadcasting), but if nothing
|
|
242
|
+
* changes we trust the snapshot — DMK silence on a stable list means
|
|
243
|
+
* "everything's still there".
|
|
244
|
+
*/
|
|
245
|
+
getLiveDevices(timeoutMs?: number): Promise<DmkDiscoveredDevice[]>;
|
|
246
|
+
/**
|
|
247
|
+
* Trigger browser device selection (WebHID requestDevice).
|
|
248
|
+
* Starts discovery for a short period, then stops.
|
|
249
|
+
*/
|
|
250
|
+
/**
|
|
251
|
+
* Start BLE discovery if not already running.
|
|
252
|
+
* Does NOT stop — DMK keeps scanning in the background so that
|
|
253
|
+
* listenToAvailableDevices() always has fresh data.
|
|
254
|
+
*/
|
|
255
|
+
private _discoverySub;
|
|
256
|
+
requestDevice(): Promise<void>;
|
|
257
|
+
/** Lookup a previously-discovered device's display name. */
|
|
258
|
+
getDeviceName(deviceId: string): string | undefined;
|
|
259
|
+
/** Connect to a previously discovered device. Returns sessionId. */
|
|
260
|
+
connect(deviceId: string): Promise<string>;
|
|
261
|
+
/** Disconnect a session. */
|
|
262
|
+
disconnect(sessionId: string): Promise<void>;
|
|
263
|
+
getSessionId(deviceId: string): string | undefined;
|
|
264
|
+
getDeviceId(sessionId: string): string | undefined;
|
|
265
|
+
/** Get the underlying DMK instance (needed by SignerManager). */
|
|
266
|
+
getDmk(): DeviceManagementKit;
|
|
267
|
+
stopDiscovery(): void;
|
|
268
|
+
dispose(): void;
|
|
269
|
+
/**
|
|
270
|
+
* Tear down RxJS subscriptions and local state without closing the DMK.
|
|
271
|
+
* For light-reset paths that want to drop session state but keep the
|
|
272
|
+
* underlying transport alive for retry. Call this instead of orphaning
|
|
273
|
+
* the manager — bare null assignment leaks _listenSub / _discoverySub.
|
|
274
|
+
*/
|
|
275
|
+
disposeKeepingDmk(): void;
|
|
276
|
+
}
|
|
277
|
+
|
|
175
278
|
/**
|
|
176
279
|
* A function that lazily loads and returns the transport factory
|
|
177
280
|
* for the Ledger DMK builder (e.g. webHidTransportFactory, rnBleTransportFactory).
|
|
@@ -209,16 +312,12 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
209
312
|
readonly connectionType: ConnectionType;
|
|
210
313
|
private _connectIdToPath;
|
|
211
314
|
private _pathToConnectId;
|
|
212
|
-
/** Register a connectId <-> path mapping from a device descriptor. */
|
|
213
|
-
private _registerDeviceId;
|
|
214
315
|
/** Get DMK path from external connectId. Falls back to connectId itself. */
|
|
215
316
|
private _getPathForConnectId;
|
|
216
317
|
/** Get external connectId from DMK path. Falls back to path itself. */
|
|
217
318
|
private _getConnectIdForPath;
|
|
218
319
|
private readonly _cancellers;
|
|
219
320
|
private readonly _sessionStateSubs;
|
|
220
|
-
private _diagDeviceListSub;
|
|
221
|
-
private _diagDeviceListPrev;
|
|
222
321
|
/**
|
|
223
322
|
* Resolves a Ledger signer kit module by package name.
|
|
224
323
|
* Override via constructor to use CJS paths for Metro (React Native).
|
|
@@ -243,6 +342,12 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
243
342
|
* Override in subclasses to extract stable identifiers (e.g. BLE hex ID).
|
|
244
343
|
*/
|
|
245
344
|
protected _resolveConnectId(descriptor: DeviceDescriptor): string;
|
|
345
|
+
/**
|
|
346
|
+
* Authoritative discovery for this transport. Default = enumerate snapshot
|
|
347
|
+
* (USB/HID). BLE overrides to drive from a live scan window since DMK's
|
|
348
|
+
* enumerate() cache survives peripherals going offline.
|
|
349
|
+
*/
|
|
350
|
+
protected _discoverDescriptors(dm: LedgerDeviceManager): Promise<DeviceDescriptor[]>;
|
|
246
351
|
searchDevices(): Promise<ConnectorDevice[]>;
|
|
247
352
|
connect(deviceId?: string): Promise<ConnectorSession>;
|
|
248
353
|
disconnect(sessionId: string): Promise<void>;
|
|
@@ -259,15 +364,6 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
259
364
|
private _watchSessionState;
|
|
260
365
|
private _unwatchSessionState;
|
|
261
366
|
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
367
|
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
272
368
|
private _dispatch;
|
|
273
369
|
cancel(sessionId: string): Promise<void>;
|
|
@@ -292,8 +388,12 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
292
388
|
*/
|
|
293
389
|
private _replaceSession;
|
|
294
390
|
/**
|
|
295
|
-
* Light reset: clear signer/session state but keep DMK
|
|
391
|
+
* Light reset: clear signer/session state but keep DMK and ID mapping alive.
|
|
296
392
|
* Used by connect() retry — we want to re-discover with the same transport.
|
|
393
|
+
*
|
|
394
|
+
* Note: drops the device manager but tears down its RxJS subs first via
|
|
395
|
+
* disposeKeepingDmk(). Bare null-assignment would leak _listenSub /
|
|
396
|
+
* _discoverySub and double-scan after the next _initManagers().
|
|
297
397
|
*/
|
|
298
398
|
private _resetSignersAndSessions;
|
|
299
399
|
private _resetAll;
|
|
@@ -307,77 +407,6 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
307
407
|
private _wrapError;
|
|
308
408
|
}
|
|
309
409
|
|
|
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
410
|
/** Optional context attached to the rejection when a canceller fires. */
|
|
382
411
|
interface CancelReason {
|
|
383
412
|
code?: number;
|
|
@@ -393,8 +422,9 @@ interface CancelReason {
|
|
|
393
422
|
* so upstream error classifiers can distinguish failure contexts (e.g. Blind signing
|
|
394
423
|
* disabled vs. generic Invalid data).
|
|
395
424
|
*
|
|
396
|
-
* @param timeoutMs
|
|
397
|
-
*
|
|
425
|
+
* @param timeoutMs Idle watchdog ms. Re-armed on each emission, paused
|
|
426
|
+
* during interactive pending. 0 disables. Default 65s
|
|
427
|
+
* (covers DMK's 60s + margin; we're a backstop only).
|
|
398
428
|
* @param onRegisterCanceller Optional callback that receives a function which, when
|
|
399
429
|
* called, unsubscribes and cancels the underlying DeviceAction
|
|
400
430
|
* (releases DMK's IntentQueue slot). Caller is responsible
|
|
@@ -428,8 +458,14 @@ type SignerEthBuilderFn = (args: {
|
|
|
428
458
|
dmk: DeviceManagementKit;
|
|
429
459
|
sessionId: string;
|
|
430
460
|
}) => {
|
|
461
|
+
withContextModule?(contextModule: ContextModule): {
|
|
462
|
+
build(): SignerEth$1;
|
|
463
|
+
};
|
|
431
464
|
build(): SignerEth$1;
|
|
432
465
|
} | Promise<{
|
|
466
|
+
withContextModule?(contextModule: ContextModule): {
|
|
467
|
+
build(): SignerEth$1;
|
|
468
|
+
};
|
|
433
469
|
build(): SignerEth$1;
|
|
434
470
|
}>;
|
|
435
471
|
/**
|
|
@@ -445,6 +481,8 @@ declare class SignerManager {
|
|
|
445
481
|
invalidate(_sessionId: string): void;
|
|
446
482
|
clearAll(): void;
|
|
447
483
|
private static _defaultBuilder;
|
|
484
|
+
private static _createContextModule;
|
|
485
|
+
static wrapBlindSigningReportNonBlocking<T extends ContextModule>(contextModule: T): T;
|
|
448
486
|
}
|
|
449
487
|
|
|
450
488
|
type BtcWallet = Parameters<SignerBtc$1['getWalletAddress']>[0];
|
|
@@ -598,30 +636,17 @@ declare class AppManager {
|
|
|
598
636
|
private _wait;
|
|
599
637
|
}
|
|
600
638
|
|
|
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
639
|
type LedgerFailure = Omit<Failure, 'payload'> & {
|
|
607
640
|
payload: Failure['payload'] & {
|
|
608
641
|
appName?: string;
|
|
642
|
+
_tag?: string;
|
|
609
643
|
};
|
|
610
644
|
};
|
|
611
645
|
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
|
-
*/
|
|
646
|
+
/** Fallback when err has no `appName` (DMK signer errors don't carry it). */
|
|
617
647
|
defaultAppName?: string;
|
|
618
648
|
}
|
|
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. */
|
|
649
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>): LedgerFailure;
|
|
625
650
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
626
651
|
/**
|
|
627
652
|
* Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
|
|
@@ -657,4 +682,19 @@ declare function offSdkEvent(listener: SdkEventListener): void;
|
|
|
657
682
|
*/
|
|
658
683
|
declare function extractBleHexId(name?: string): string | undefined;
|
|
659
684
|
|
|
660
|
-
|
|
685
|
+
/**
|
|
686
|
+
* Ledger DMK transport identifiers that represent BLE devices.
|
|
687
|
+
*
|
|
688
|
+
* Known today:
|
|
689
|
+
* - "BLE": generic/web BLE descriptors
|
|
690
|
+
* - "RN_BLE": @ledgerhq/device-transport-kit-react-native-ble
|
|
691
|
+
*
|
|
692
|
+
* Keep the suffix check here so future DMK BLE transports (for example
|
|
693
|
+
* "FOO_BLE") are handled in one place instead of scattering string checks.
|
|
694
|
+
*/
|
|
695
|
+
declare function isLedgerDmkBleTransport(transport?: string): boolean;
|
|
696
|
+
declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
|
|
697
|
+
declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
|
|
698
|
+
declare function isValidLedgerBleConnectId(connectId?: string): boolean;
|
|
699
|
+
|
|
700
|
+
export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, type LedgerFailure, type SdkEvent, type SdkEventListener, type SdkLogEvent, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, deviceActionToPromise, extractBleHexId, isDeviceLockedError, isLedgerBleConnectionType, isLedgerBleDescriptor, isLedgerDmkBleTransport, isValidLedgerBleConnectId, ledgerFailure, mapLedgerError, offSdkEvent, onSdkEvent };
|