@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.106 → 1.1.26-alpha.4
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 +65 -9
- package/dist/index.d.ts +65 -9
- package/dist/index.js +417 -278
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +377 -240
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IHardwareWallet, IConnector, TransportType, IUiHandler, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
|
|
1
|
+
import { IHardwareWallet, IConnector, TransportType, IUiHandler, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, Failure, 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';
|
|
@@ -32,7 +32,15 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
32
32
|
private _discoveredDevices;
|
|
33
33
|
private _sessions;
|
|
34
34
|
private readonly _uiRegistry;
|
|
35
|
+
private readonly _jobQueue;
|
|
35
36
|
constructor(connector: IConnector, options?: LedgerAdapterOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Classify a method's interruptibility.
|
|
39
|
+
* - Signing / typed data / transaction → 'confirm' (user may decide via preemption UI)
|
|
40
|
+
* - Read-only queries (getAddress / getPublicKey / getMasterFingerprint) → 'safe'
|
|
41
|
+
* (auto-cancels any pending read for the same device)
|
|
42
|
+
*/
|
|
43
|
+
private static _getInterruptibility;
|
|
36
44
|
get activeTransport(): TransportType | null;
|
|
37
45
|
getAvailableTransports(): TransportType[];
|
|
38
46
|
switchTransport(_type: TransportType): Promise<void>;
|
|
@@ -128,6 +136,16 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
128
136
|
* 4. On disconnect error: clears stale session, re-connects, retries once
|
|
129
137
|
*/
|
|
130
138
|
private connectorCall;
|
|
139
|
+
/**
|
|
140
|
+
* Race a promise against an abort signal. If the signal fires, rejects with the
|
|
141
|
+
* signal's reason (or a generic Error). The underlying connector.call() cannot
|
|
142
|
+
* actually be cancelled on Ledger DMK, but the caller gets the abort immediately.
|
|
143
|
+
*/
|
|
144
|
+
private static _abortable;
|
|
145
|
+
/** Throw an AbortError if signal is already aborted. */
|
|
146
|
+
private static _throwIfAborted;
|
|
147
|
+
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
148
|
+
private _runConnectorCall;
|
|
131
149
|
/** Clear stale session, reconnect, and retry the call. */
|
|
132
150
|
private _retryWithFreshConnection;
|
|
133
151
|
/**
|
|
@@ -188,7 +206,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
188
206
|
private readonly _eventHandlers;
|
|
189
207
|
private readonly _providedDmk;
|
|
190
208
|
private readonly _createTransport;
|
|
191
|
-
|
|
209
|
+
readonly connectionType: ConnectionType;
|
|
192
210
|
private _connectIdToPath;
|
|
193
211
|
private _pathToConnectId;
|
|
194
212
|
/** Register a connectId <-> path mapping from a device descriptor. */
|
|
@@ -197,6 +215,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
197
215
|
private _getPathForConnectId;
|
|
198
216
|
/** Get external connectId from DMK path. Falls back to path itself. */
|
|
199
217
|
private _getConnectIdForPath;
|
|
218
|
+
private readonly _cancellers;
|
|
200
219
|
/**
|
|
201
220
|
* Resolves a Ledger signer kit module by package name.
|
|
202
221
|
* Override via constructor to use CJS paths for Metro (React Native).
|
|
@@ -225,7 +244,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
225
244
|
connect(deviceId?: string): Promise<ConnectorSession>;
|
|
226
245
|
disconnect(sessionId: string): Promise<void>;
|
|
227
246
|
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
228
|
-
cancel(
|
|
247
|
+
cancel(sessionId: string): Promise<void>;
|
|
229
248
|
uiResponse(_response: UiResponseEvent): void;
|
|
230
249
|
on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
231
250
|
off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
@@ -335,6 +354,12 @@ declare class SignerEth {
|
|
|
335
354
|
private readonly _sdk;
|
|
336
355
|
onInteraction?: (interaction: string) => void;
|
|
337
356
|
constructor(_sdk: SignerEth$1);
|
|
357
|
+
/**
|
|
358
|
+
* Optional callback registered per-call so the caller can obtain a canceller
|
|
359
|
+
* for the underlying DeviceAction. Caller can invoke it to release DMK's
|
|
360
|
+
* IntentQueue slot and unsubscribe from the action's observable.
|
|
361
|
+
*/
|
|
362
|
+
onRegisterCanceller?: (cancel: () => void) => void;
|
|
338
363
|
getAddress(derivationPath: string, options?: {
|
|
339
364
|
checkOnDevice?: boolean;
|
|
340
365
|
}): Promise<SignerEvmAddress>;
|
|
@@ -352,16 +377,16 @@ type SignerEthBuilderFn = (args: {
|
|
|
352
377
|
build(): SignerEth$1;
|
|
353
378
|
}>;
|
|
354
379
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
380
|
+
* Per-sessionId SignerEth factory. Builds fresh on every call — DMK signers
|
|
381
|
+
* hold DeviceAction state that isn't safe to reuse, so `invalidate` /
|
|
382
|
+
* `clearAll` are kept as no-op lifecycle hooks for callers.
|
|
357
383
|
*/
|
|
358
384
|
declare class SignerManager {
|
|
359
|
-
private readonly _cache;
|
|
360
385
|
private readonly _dmk;
|
|
361
386
|
private readonly _builderFn;
|
|
362
387
|
constructor(dmk: DeviceManagementKit, builderFn?: SignerEthBuilderFn);
|
|
363
388
|
getOrCreate(sessionId: string): Promise<SignerEth>;
|
|
364
|
-
invalidate(
|
|
389
|
+
invalidate(_sessionId: string): void;
|
|
365
390
|
clearAll(): void;
|
|
366
391
|
private static _defaultBuilder;
|
|
367
392
|
}
|
|
@@ -377,6 +402,7 @@ type BtcMessageOptions = Parameters<SignerBtc$1['signMessage']>[2];
|
|
|
377
402
|
declare class SignerBtc {
|
|
378
403
|
private readonly _sdk;
|
|
379
404
|
onInteraction?: (interaction: string) => void;
|
|
405
|
+
onRegisterCanceller?: (cancel: () => void) => void;
|
|
380
406
|
constructor(_sdk: SignerBtc$1);
|
|
381
407
|
getWalletAddress(wallet: BtcWallet, addressIndex: number, options?: {
|
|
382
408
|
checkOnDevice?: boolean;
|
|
@@ -422,6 +448,7 @@ type SolMsgOptions = Parameters<SignerSolana['signMessage']>[2];
|
|
|
422
448
|
declare class SignerSol {
|
|
423
449
|
private readonly _sdk;
|
|
424
450
|
onInteraction?: (interaction: string) => void;
|
|
451
|
+
onRegisterCanceller?: (cancel: () => void) => void;
|
|
425
452
|
constructor(_sdk: SignerSolana);
|
|
426
453
|
/**
|
|
427
454
|
* Get the Solana address (base58-encoded Ed25519 public key) at the given derivation path.
|
|
@@ -473,8 +500,12 @@ declare class DmkTransport extends Transport {
|
|
|
473
500
|
*
|
|
474
501
|
* @param timeoutMs Timeout in ms. Resets each time the Observable emits (device is alive).
|
|
475
502
|
* Pass 0 to disable. Default: 30s.
|
|
503
|
+
* @param onRegisterCanceller Optional callback that receives a function which, when
|
|
504
|
+
* called, unsubscribes and cancels the underlying DeviceAction
|
|
505
|
+
* (releases DMK's IntentQueue slot). Caller is responsible
|
|
506
|
+
* for invoking the canceller on timeout/abort scenarios.
|
|
476
507
|
*/
|
|
477
|
-
declare function deviceActionToPromise<T>(action: DeviceAction<T>, onInteraction?: (interaction: string) => void, timeoutMs?: number): Promise<T>;
|
|
508
|
+
declare function deviceActionToPromise<T>(action: DeviceAction<T>, onInteraction?: (interaction: string) => void, timeoutMs?: number, onRegisterCanceller?: (cancel: () => void) => void): Promise<T>;
|
|
478
509
|
|
|
479
510
|
interface AppManagerOptions {
|
|
480
511
|
waitMs?: number;
|
|
@@ -522,6 +553,21 @@ declare class AppManager {
|
|
|
522
553
|
private _wait;
|
|
523
554
|
}
|
|
524
555
|
|
|
556
|
+
/**
|
|
557
|
+
* Ledger-specific Failure: adds `appName` for "the currently-open app" — a
|
|
558
|
+
* Ledger hardware concept not shared with other vendors, so it lives here
|
|
559
|
+
* rather than in core's generic Failure.
|
|
560
|
+
*/
|
|
561
|
+
type LedgerFailure = Omit<Failure, 'payload'> & {
|
|
562
|
+
payload: Failure['payload'] & {
|
|
563
|
+
appName?: string;
|
|
564
|
+
};
|
|
565
|
+
};
|
|
566
|
+
/**
|
|
567
|
+
* Structurally compatible with `Failure`; writes `appName` only when provided,
|
|
568
|
+
* so `'appName' in payload` is a reliable "has info" signal for consumers.
|
|
569
|
+
*/
|
|
570
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string): LedgerFailure;
|
|
525
571
|
/** Check if an error (or any error in its chain) represents a locked Ledger device. */
|
|
526
572
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
527
573
|
/**
|
|
@@ -534,4 +580,14 @@ declare function mapLedgerError(err: unknown): {
|
|
|
534
580
|
appName?: string;
|
|
535
581
|
};
|
|
536
582
|
|
|
537
|
-
|
|
583
|
+
/**
|
|
584
|
+
* Centralised debug logger for the Ledger adapter.
|
|
585
|
+
*
|
|
586
|
+
* Off by default. Toggle programmatically via `setDebugEnabled(true)`.
|
|
587
|
+
*/
|
|
588
|
+
/** Enable or disable debug logging at runtime. */
|
|
589
|
+
declare function setDebugEnabled(value: boolean): void;
|
|
590
|
+
/** Returns the current debug-enabled state. */
|
|
591
|
+
declare function isDebugEnabled(): boolean;
|
|
592
|
+
|
|
593
|
+
export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, type LedgerFailure, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, deviceActionToPromise, isDebugEnabled, isDeviceLockedError, ledgerFailure, mapLedgerError, setDebugEnabled };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IHardwareWallet, IConnector, TransportType, IUiHandler, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
|
|
1
|
+
import { IHardwareWallet, IConnector, TransportType, IUiHandler, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, Failure, 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';
|
|
@@ -32,7 +32,15 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
32
32
|
private _discoveredDevices;
|
|
33
33
|
private _sessions;
|
|
34
34
|
private readonly _uiRegistry;
|
|
35
|
+
private readonly _jobQueue;
|
|
35
36
|
constructor(connector: IConnector, options?: LedgerAdapterOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Classify a method's interruptibility.
|
|
39
|
+
* - Signing / typed data / transaction → 'confirm' (user may decide via preemption UI)
|
|
40
|
+
* - Read-only queries (getAddress / getPublicKey / getMasterFingerprint) → 'safe'
|
|
41
|
+
* (auto-cancels any pending read for the same device)
|
|
42
|
+
*/
|
|
43
|
+
private static _getInterruptibility;
|
|
36
44
|
get activeTransport(): TransportType | null;
|
|
37
45
|
getAvailableTransports(): TransportType[];
|
|
38
46
|
switchTransport(_type: TransportType): Promise<void>;
|
|
@@ -128,6 +136,16 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
128
136
|
* 4. On disconnect error: clears stale session, re-connects, retries once
|
|
129
137
|
*/
|
|
130
138
|
private connectorCall;
|
|
139
|
+
/**
|
|
140
|
+
* Race a promise against an abort signal. If the signal fires, rejects with the
|
|
141
|
+
* signal's reason (or a generic Error). The underlying connector.call() cannot
|
|
142
|
+
* actually be cancelled on Ledger DMK, but the caller gets the abort immediately.
|
|
143
|
+
*/
|
|
144
|
+
private static _abortable;
|
|
145
|
+
/** Throw an AbortError if signal is already aborted. */
|
|
146
|
+
private static _throwIfAborted;
|
|
147
|
+
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
148
|
+
private _runConnectorCall;
|
|
131
149
|
/** Clear stale session, reconnect, and retry the call. */
|
|
132
150
|
private _retryWithFreshConnection;
|
|
133
151
|
/**
|
|
@@ -188,7 +206,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
188
206
|
private readonly _eventHandlers;
|
|
189
207
|
private readonly _providedDmk;
|
|
190
208
|
private readonly _createTransport;
|
|
191
|
-
|
|
209
|
+
readonly connectionType: ConnectionType;
|
|
192
210
|
private _connectIdToPath;
|
|
193
211
|
private _pathToConnectId;
|
|
194
212
|
/** Register a connectId <-> path mapping from a device descriptor. */
|
|
@@ -197,6 +215,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
197
215
|
private _getPathForConnectId;
|
|
198
216
|
/** Get external connectId from DMK path. Falls back to path itself. */
|
|
199
217
|
private _getConnectIdForPath;
|
|
218
|
+
private readonly _cancellers;
|
|
200
219
|
/**
|
|
201
220
|
* Resolves a Ledger signer kit module by package name.
|
|
202
221
|
* Override via constructor to use CJS paths for Metro (React Native).
|
|
@@ -225,7 +244,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
225
244
|
connect(deviceId?: string): Promise<ConnectorSession>;
|
|
226
245
|
disconnect(sessionId: string): Promise<void>;
|
|
227
246
|
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
228
|
-
cancel(
|
|
247
|
+
cancel(sessionId: string): Promise<void>;
|
|
229
248
|
uiResponse(_response: UiResponseEvent): void;
|
|
230
249
|
on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
231
250
|
off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
@@ -335,6 +354,12 @@ declare class SignerEth {
|
|
|
335
354
|
private readonly _sdk;
|
|
336
355
|
onInteraction?: (interaction: string) => void;
|
|
337
356
|
constructor(_sdk: SignerEth$1);
|
|
357
|
+
/**
|
|
358
|
+
* Optional callback registered per-call so the caller can obtain a canceller
|
|
359
|
+
* for the underlying DeviceAction. Caller can invoke it to release DMK's
|
|
360
|
+
* IntentQueue slot and unsubscribe from the action's observable.
|
|
361
|
+
*/
|
|
362
|
+
onRegisterCanceller?: (cancel: () => void) => void;
|
|
338
363
|
getAddress(derivationPath: string, options?: {
|
|
339
364
|
checkOnDevice?: boolean;
|
|
340
365
|
}): Promise<SignerEvmAddress>;
|
|
@@ -352,16 +377,16 @@ type SignerEthBuilderFn = (args: {
|
|
|
352
377
|
build(): SignerEth$1;
|
|
353
378
|
}>;
|
|
354
379
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
380
|
+
* Per-sessionId SignerEth factory. Builds fresh on every call — DMK signers
|
|
381
|
+
* hold DeviceAction state that isn't safe to reuse, so `invalidate` /
|
|
382
|
+
* `clearAll` are kept as no-op lifecycle hooks for callers.
|
|
357
383
|
*/
|
|
358
384
|
declare class SignerManager {
|
|
359
|
-
private readonly _cache;
|
|
360
385
|
private readonly _dmk;
|
|
361
386
|
private readonly _builderFn;
|
|
362
387
|
constructor(dmk: DeviceManagementKit, builderFn?: SignerEthBuilderFn);
|
|
363
388
|
getOrCreate(sessionId: string): Promise<SignerEth>;
|
|
364
|
-
invalidate(
|
|
389
|
+
invalidate(_sessionId: string): void;
|
|
365
390
|
clearAll(): void;
|
|
366
391
|
private static _defaultBuilder;
|
|
367
392
|
}
|
|
@@ -377,6 +402,7 @@ type BtcMessageOptions = Parameters<SignerBtc$1['signMessage']>[2];
|
|
|
377
402
|
declare class SignerBtc {
|
|
378
403
|
private readonly _sdk;
|
|
379
404
|
onInteraction?: (interaction: string) => void;
|
|
405
|
+
onRegisterCanceller?: (cancel: () => void) => void;
|
|
380
406
|
constructor(_sdk: SignerBtc$1);
|
|
381
407
|
getWalletAddress(wallet: BtcWallet, addressIndex: number, options?: {
|
|
382
408
|
checkOnDevice?: boolean;
|
|
@@ -422,6 +448,7 @@ type SolMsgOptions = Parameters<SignerSolana['signMessage']>[2];
|
|
|
422
448
|
declare class SignerSol {
|
|
423
449
|
private readonly _sdk;
|
|
424
450
|
onInteraction?: (interaction: string) => void;
|
|
451
|
+
onRegisterCanceller?: (cancel: () => void) => void;
|
|
425
452
|
constructor(_sdk: SignerSolana);
|
|
426
453
|
/**
|
|
427
454
|
* Get the Solana address (base58-encoded Ed25519 public key) at the given derivation path.
|
|
@@ -473,8 +500,12 @@ declare class DmkTransport extends Transport {
|
|
|
473
500
|
*
|
|
474
501
|
* @param timeoutMs Timeout in ms. Resets each time the Observable emits (device is alive).
|
|
475
502
|
* Pass 0 to disable. Default: 30s.
|
|
503
|
+
* @param onRegisterCanceller Optional callback that receives a function which, when
|
|
504
|
+
* called, unsubscribes and cancels the underlying DeviceAction
|
|
505
|
+
* (releases DMK's IntentQueue slot). Caller is responsible
|
|
506
|
+
* for invoking the canceller on timeout/abort scenarios.
|
|
476
507
|
*/
|
|
477
|
-
declare function deviceActionToPromise<T>(action: DeviceAction<T>, onInteraction?: (interaction: string) => void, timeoutMs?: number): Promise<T>;
|
|
508
|
+
declare function deviceActionToPromise<T>(action: DeviceAction<T>, onInteraction?: (interaction: string) => void, timeoutMs?: number, onRegisterCanceller?: (cancel: () => void) => void): Promise<T>;
|
|
478
509
|
|
|
479
510
|
interface AppManagerOptions {
|
|
480
511
|
waitMs?: number;
|
|
@@ -522,6 +553,21 @@ declare class AppManager {
|
|
|
522
553
|
private _wait;
|
|
523
554
|
}
|
|
524
555
|
|
|
556
|
+
/**
|
|
557
|
+
* Ledger-specific Failure: adds `appName` for "the currently-open app" — a
|
|
558
|
+
* Ledger hardware concept not shared with other vendors, so it lives here
|
|
559
|
+
* rather than in core's generic Failure.
|
|
560
|
+
*/
|
|
561
|
+
type LedgerFailure = Omit<Failure, 'payload'> & {
|
|
562
|
+
payload: Failure['payload'] & {
|
|
563
|
+
appName?: string;
|
|
564
|
+
};
|
|
565
|
+
};
|
|
566
|
+
/**
|
|
567
|
+
* Structurally compatible with `Failure`; writes `appName` only when provided,
|
|
568
|
+
* so `'appName' in payload` is a reliable "has info" signal for consumers.
|
|
569
|
+
*/
|
|
570
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string): LedgerFailure;
|
|
525
571
|
/** Check if an error (or any error in its chain) represents a locked Ledger device. */
|
|
526
572
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
527
573
|
/**
|
|
@@ -534,4 +580,14 @@ declare function mapLedgerError(err: unknown): {
|
|
|
534
580
|
appName?: string;
|
|
535
581
|
};
|
|
536
582
|
|
|
537
|
-
|
|
583
|
+
/**
|
|
584
|
+
* Centralised debug logger for the Ledger adapter.
|
|
585
|
+
*
|
|
586
|
+
* Off by default. Toggle programmatically via `setDebugEnabled(true)`.
|
|
587
|
+
*/
|
|
588
|
+
/** Enable or disable debug logging at runtime. */
|
|
589
|
+
declare function setDebugEnabled(value: boolean): void;
|
|
590
|
+
/** Returns the current debug-enabled state. */
|
|
591
|
+
declare function isDebugEnabled(): boolean;
|
|
592
|
+
|
|
593
|
+
export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, type LedgerFailure, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, deviceActionToPromise, isDebugEnabled, isDeviceLockedError, ledgerFailure, mapLedgerError, setDebugEnabled };
|