@onekeyfe/hwk-ledger-adapter 1.2.3-alpha.8 → 1.2.3

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 CHANGED
@@ -1,11 +1,10 @@
1
1
  import * as _onekeyfe_hwk_adapter_core from '@onekeyfe/hwk-adapter-core';
2
- import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, DeviceSearchTarget, ConnectionTarget, Response, BindBleDeviceParams, IHardwareConnectionContext, NullableCallArg, IHardwareCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxLedgerParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, IHardwareCommonCallParams, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, ZcashGetFullViewingKeyParams, ZcashFullViewingKey, ZcashGetShieldedAddressParams, ZcashShieldedAddress, DeviceAuthenticityParams, DeviceAuthenticityResult, HardwareEventMap, DeviceEventListener, ChainForFingerprint, DeviceDescriptor, DeviceChangeEvent, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorCallResult, ConnectorEventType, ConnectorEventMap, ConnectorConfig, Failure, HardwareErrorCode, HwkErrorOrigin, HwkRecoveryHint } from '@onekeyfe/hwk-adapter-core';
2
+ import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, Response, ChainCapability, NullableCallArg, IHardwareCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxLedgerParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, IHardwareCommonCallParams, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, DeviceAuthenticityParams, DeviceAuthenticityResult, HardwareEventMap, DeviceEventListener, ChainForFingerprint, DeviceDescriptor, DeviceChangeEvent, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorCallResult, ConnectorEventType, ConnectorEventMap, ConnectorConfig, Failure, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
3
3
  import { DeviceActionState as DeviceActionState$1, DiscoveredDevice, ExecuteDeviceActionReturnType, DeviceManagementKit } from '@ledgerhq/device-management-kit';
4
4
  import { Address, Signature, SignerEth as SignerEth$1, TypedData } from '@ledgerhq/device-signer-kit-ethereum';
5
5
  import { ContextModule } from '@ledgerhq/context-module';
6
6
  import { SignerBtc as SignerBtc$1 } from '@ledgerhq/device-signer-kit-bitcoin';
7
7
  import { SignerSolana } from '@ledgerhq/device-signer-kit-solana';
8
- import { SignerZcash as SignerZcash$1, FullViewingKeyOptions, GetFullViewingKeyDAOutput, GetShieldedAddressDAOutput } from '@ledgerhq/device-signer-kit-zcash';
9
8
  import Transport from '@ledgerhq/hw-transport';
10
9
 
11
10
  /**
@@ -96,30 +95,16 @@ type LedgerCallParams<T> = NullableCallArg<IHardwareCallParams<T>>;
96
95
  type LedgerCommonParams = NullableCallArg<IHardwareCommonCallParams>;
97
96
  declare class LedgerAdapter implements IHardwareWallet {
98
97
  readonly vendor: "ledger";
99
- readonly cancelCapability: "stops-waiting";
100
98
  private readonly connector;
101
99
  private readonly emitter;
102
- private readonly _operations;
103
100
  private _discoveredDevices;
104
101
  private _sessions;
105
- private readonly _pendingOperationBindings;
106
- private readonly _verifiedBleReconnectTargets;
107
102
  private readonly _uiRegistry;
108
103
  private _btcHighIndexConfirmedThisSession;
109
104
  private readonly _jobQueue;
110
105
  private _deviceAuthenticityQueueTail;
111
106
  private _doConnectAbortController;
112
107
  private readonly _defaultAutoInstallApp;
113
- private readonly _unsettledConnectorOperations;
114
- private readonly _connectorIdleWaiters;
115
- private _resetPromise;
116
- private _stateGeneration;
117
- private _connectorTeardownTail;
118
- private _pendingConnectorTeardowns;
119
- private _activeConnectionType;
120
- private _bindingSelectionRequestId;
121
- private _finishBleBinding;
122
- private _isBleConnection;
123
108
  constructor(connector: IConnector, options?: {
124
109
  autoInstallApp?: boolean;
125
110
  });
@@ -133,33 +118,22 @@ declare class LedgerAdapter implements IHardwareWallet {
133
118
  * The next operation will re-discover and re-connect automatically.
134
119
  */
135
120
  resetState(): void;
136
- private _resetStateAndDisconnectSessions;
137
121
  dispose(): Promise<void>;
138
122
  uiResponse(response: UiResponseEvent): void;
139
123
  searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
140
- private _searchDevices;
141
- searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
142
- listConnectionTargets(options?: SearchDevicesOptions): Promise<ConnectionTarget[]>;
143
124
  private _evictAllSessions;
144
125
  private static readonly MAX_BUSINESS_RETRY_BUDGET;
145
126
  private static readonly STUCK_APP_RETRY_DELAY_MS;
146
127
  private static readonly MAX_DOCONNECT_CONFIRMS;
147
128
  private _lastCancelReason;
148
- private readonly _activeOperationJobs;
149
- private readonly _pendingOperationDisconnects;
150
129
  private static readonly APP_INSTALL_PROGRESS_MIN_DELTA;
151
130
  private _installProgressLastEmittedValue;
152
131
  private _installProgressLastKey;
153
132
  private static _createDeviceBusyError;
154
- connectDevice(searchTargetId: string): Promise<Response<string>>;
155
- bindBleDevice(params: BindBleDeviceParams): Promise<Response<string>>;
156
- acquireOperation(connectId: string, context: IHardwareConnectionContext): Promise<Response<string>>;
157
- private _createOperation;
158
- private _connectTarget;
159
- releaseOperation(operationId: string): Promise<void>;
160
- private _releaseOperationConnection;
161
- private _releaseLostOperationConnection;
162
- getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
133
+ connectDevice(connectId: string): Promise<Response<string>>;
134
+ disconnectDevice(connectId: string): Promise<void>;
135
+ getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
136
+ getSupportedChains(): ChainCapability[];
163
137
  allNetworkGetAddress: (connectId: string, _deviceId: string, params: _onekeyfe_hwk_adapter_core.AllNetworkGetAddressParams) => Promise<Response<_onekeyfe_hwk_adapter_core.AllNetworkAddressResponse[]>>;
164
138
  private callChain;
165
139
  private static normalizeCallArgs;
@@ -183,8 +157,6 @@ declare class LedgerAdapter implements IHardwareWallet {
183
157
  tronGetAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronGetAddressParams>): Promise<Response<TronAddress>>;
184
158
  tronSignTransaction(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignTxParams>): Promise<Response<TronSignedTx>>;
185
159
  tronSignMessage(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignMsgParams>): Promise<Response<TronSignature>>;
186
- zcashGetFullViewingKey(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetFullViewingKeyParams>): Promise<Response<ZcashFullViewingKey>>;
187
- zcashGetShieldedAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetShieldedAddressParams>): Promise<Response<ZcashShieldedAddress>>;
188
160
  installApp(connectId: string, appName: string): Promise<Response<void>>;
189
161
  listInstalledApps(connectId: string): Promise<Response<AppMetadata[]>>;
190
162
  listInstalledNames(connectId: string): Promise<Response<string[]>>;
@@ -209,11 +181,11 @@ declare class LedgerAdapter implements IHardwareWallet {
209
181
  off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
210
182
  off(event: string, listener: DeviceEventListener): void;
211
183
  cancel(connectId?: string): void;
212
- /** A non-empty deviceId is an expected chain fingerprint, not a transport identifier. */
213
184
  getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
214
- /** Discovery may select a BLE target before a later call verifies its wallet. */
215
- private _publishVerifiedBleBinding;
216
- /** Verify on the acquired session without re-entering the job queue. */
185
+ /**
186
+ * Verify fingerprint using an existing sessionId directly.
187
+ * Safe to call inside connectorCall without causing queue deadlock.
188
+ */
217
189
  private _verifyDeviceFingerprintWithSession;
218
190
  /**
219
191
  * Compute the chain fingerprint via a caller-supplied call strategy.
@@ -235,17 +207,9 @@ declare class LedgerAdapter implements IHardwareWallet {
235
207
  *
236
208
  * - If a session already exists for the given connectId, reuse it.
237
209
  * - If ANY session exists (Ledger IDs are ephemeral), reuse it.
238
- * - Otherwise: search → one USB device auto-connects; multiple asks the host to choose.
210
+ * - Otherwise: search → exactly 1 USB device auto-connects; multiple or none throws.
239
211
  */
240
212
  private _connectingPromise;
241
- /**
242
- * The operation the running device job belongs to, so a UI request raised
243
- * mid-call can name it. A call pinned to an operation queues under its id
244
- * (`ledgerQueueKey`); a call without one queues under the connectId, and the
245
- * live operation on that connection is still the owner. Only work with no
246
- * operation at all (cold start) comes back undefined.
247
- */
248
- private _activeOperationId;
249
213
  private _waitForDeviceConnect;
250
214
  /**
251
215
  * Decide whether a BTC pubkey call needs `showOnDevice=true` because of
@@ -286,23 +250,34 @@ declare class LedgerAdapter implements IHardwareWallet {
286
250
  * lives in one place.
287
251
  */
288
252
  private _callConnector;
289
- private _assertConnectorReady;
290
- private _runConnectorTeardown;
291
- private _waitForConnectorOperationsToDrain;
292
- private _retainConnectorOperation;
293
253
  private connectorCall;
294
254
  /**
295
255
  * Race a promise against an abort signal. On abort, rejects with
296
256
  * signal.reason → instance _lastCancelReason → generic Error('Aborted').
297
257
  */
298
- /** Hermes/RN polyfills don't always populate signal.reason; fall back. */
299
- private _abortReason;
300
258
  private _abortable;
301
259
  /** Throw an AbortError if signal is already aborted. */
302
260
  private static _throwIfAborted;
303
261
  /** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
304
262
  private _runConnectorCall;
263
+ /**
264
+ * Stuck-app recovery: pause for the device's UI transition, then retry once.
265
+ *
266
+ * Caller has already cleared the session + reset connector. We wait so Stax
267
+ * finishes its post-CloseApp animation, then go through ensureConnected +
268
+ * fingerprint check + call exactly once. Caller decides what to do on a
269
+ * second stuck-app hit.
270
+ */
271
+ private _retryAfterStuckApp;
305
272
  private _sleepAbortable;
273
+ /**
274
+ * Clear stale session, reconnect, and retry the call.
275
+ *
276
+ * Timeout recovery starts with a full connector reset. After an APDU
277
+ * timeout, DMK/transport state may still emit malformed responses; retrying
278
+ * on the same DMK can poison the next chain switch.
279
+ */
280
+ private _retryWithFreshConnection;
306
281
  /**
307
282
  * Ensure OS-level device permission (Bluetooth / USB) before proceeding.
308
283
  *
@@ -523,18 +498,6 @@ declare class LedgerConnectorBase implements IConnector {
523
498
  private _getSignerManager;
524
499
  private _getDeviceAppsManager;
525
500
  private _invalidateSession;
526
- /**
527
- * Teardown for the OS-level actions that open a manager-api secure channel
528
- * (install, uninstall, genuine check). Cancelling the device action is what
529
- * stops DMK's xstate actor, which unsubscribes the secure-channel observable
530
- * and closes its WebSocket; dropping the canceller without firing it leaves
531
- * that teardown to run only if the action settled on its own.
532
- *
533
- * The DMK device session is deliberately kept: the secure channel is a
534
- * separate WebSocket per call, and disconnecting here would break the bounded
535
- * unlock/retry recovery the adapter runs on the original session.
536
- */
537
- private _teardownSecureChannelSession;
538
501
  /**
539
502
  * Replace an old session with a new one after app switch.
540
503
  * Emits device-connect so the adapter updates its _sessions Map.
@@ -691,25 +654,6 @@ declare class SignerSol {
691
654
  }>;
692
655
  }
693
656
 
694
- /**
695
- * Wraps Ledger's Zcash SDK signer (Observable-based DeviceActions) into a
696
- * simple async interface. Only the viewing-key and shielded-address reads are
697
- * exposed; PCZT signing goes through a different host-side pipeline.
698
- */
699
- declare class SignerZcash {
700
- private readonly _sdk;
701
- onInteraction?: (interaction: string) => void;
702
- onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void;
703
- constructor(_sdk: SignerZcash$1);
704
- /** GET_VK: UFVK string (default) or raw 96-byte Orchard FVK. */
705
- getFullViewingKey(derivationPath: string, options?: FullViewingKeyOptions): Promise<GetFullViewingKeyDAOutput>;
706
- /** GET_SHIELDED_ADDRESS: single-Orchard-receiver UA for a 5-level transparent path. */
707
- getShieldedAddress(derivationPath: string, options?: {
708
- checkOnDevice?: boolean;
709
- skipOpenApp?: boolean;
710
- }): Promise<GetShieldedAddressDAOutput>;
711
- }
712
-
713
657
  /**
714
658
  * Transport adapter that bridges Ledger's legacy hw-app-* SDKs to DMK's sendApdu.
715
659
  *
@@ -793,7 +737,7 @@ interface WrapErrorOptions {
793
737
  /** Fallback when err has no `appName` (DMK signer errors don't carry it). */
794
738
  defaultAppName?: string;
795
739
  }
796
- declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>, origin?: HwkErrorOrigin, recovery?: HwkRecoveryHint): LedgerFailure;
740
+ declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>): LedgerFailure;
797
741
  declare function isDeviceLockedError(err: unknown): boolean;
798
742
  /**
799
743
  * Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
@@ -803,7 +747,6 @@ declare function isDeviceLockedError(err: unknown): boolean;
803
747
  declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
804
748
  code: HardwareErrorCode;
805
749
  message: string;
806
- origin?: HwkErrorOrigin;
807
750
  appName?: string;
808
751
  };
809
752
 
@@ -839,4 +782,4 @@ declare function isLedgerDmkBleTransport(transport?: string): boolean;
839
782
  declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
840
783
  declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
841
784
 
842
- 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, SignerZcash, type TransportFactory, debugLog, deviceActionToPromise, isDeviceLockedError, isLedgerBleConnectionType, isLedgerBleDescriptor, isLedgerDmkBleTransport, ledgerFailure, mapLedgerError, offSdkEvent, onSdkEvent };
785
+ 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 };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import * as _onekeyfe_hwk_adapter_core from '@onekeyfe/hwk-adapter-core';
2
- import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, DeviceSearchTarget, ConnectionTarget, Response, BindBleDeviceParams, IHardwareConnectionContext, NullableCallArg, IHardwareCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxLedgerParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, IHardwareCommonCallParams, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, ZcashGetFullViewingKeyParams, ZcashFullViewingKey, ZcashGetShieldedAddressParams, ZcashShieldedAddress, DeviceAuthenticityParams, DeviceAuthenticityResult, HardwareEventMap, DeviceEventListener, ChainForFingerprint, DeviceDescriptor, DeviceChangeEvent, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorCallResult, ConnectorEventType, ConnectorEventMap, ConnectorConfig, Failure, HardwareErrorCode, HwkErrorOrigin, HwkRecoveryHint } from '@onekeyfe/hwk-adapter-core';
2
+ import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, Response, ChainCapability, NullableCallArg, IHardwareCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxLedgerParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, IHardwareCommonCallParams, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, DeviceAuthenticityParams, DeviceAuthenticityResult, HardwareEventMap, DeviceEventListener, ChainForFingerprint, DeviceDescriptor, DeviceChangeEvent, ConnectionType, ConnectorDevice, ConnectorSession, ConnectorCallResult, ConnectorEventType, ConnectorEventMap, ConnectorConfig, Failure, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
3
3
  import { DeviceActionState as DeviceActionState$1, DiscoveredDevice, ExecuteDeviceActionReturnType, DeviceManagementKit } from '@ledgerhq/device-management-kit';
4
4
  import { Address, Signature, SignerEth as SignerEth$1, TypedData } from '@ledgerhq/device-signer-kit-ethereum';
5
5
  import { ContextModule } from '@ledgerhq/context-module';
6
6
  import { SignerBtc as SignerBtc$1 } from '@ledgerhq/device-signer-kit-bitcoin';
7
7
  import { SignerSolana } from '@ledgerhq/device-signer-kit-solana';
8
- import { SignerZcash as SignerZcash$1, FullViewingKeyOptions, GetFullViewingKeyDAOutput, GetShieldedAddressDAOutput } from '@ledgerhq/device-signer-kit-zcash';
9
8
  import Transport from '@ledgerhq/hw-transport';
10
9
 
11
10
  /**
@@ -96,30 +95,16 @@ type LedgerCallParams<T> = NullableCallArg<IHardwareCallParams<T>>;
96
95
  type LedgerCommonParams = NullableCallArg<IHardwareCommonCallParams>;
97
96
  declare class LedgerAdapter implements IHardwareWallet {
98
97
  readonly vendor: "ledger";
99
- readonly cancelCapability: "stops-waiting";
100
98
  private readonly connector;
101
99
  private readonly emitter;
102
- private readonly _operations;
103
100
  private _discoveredDevices;
104
101
  private _sessions;
105
- private readonly _pendingOperationBindings;
106
- private readonly _verifiedBleReconnectTargets;
107
102
  private readonly _uiRegistry;
108
103
  private _btcHighIndexConfirmedThisSession;
109
104
  private readonly _jobQueue;
110
105
  private _deviceAuthenticityQueueTail;
111
106
  private _doConnectAbortController;
112
107
  private readonly _defaultAutoInstallApp;
113
- private readonly _unsettledConnectorOperations;
114
- private readonly _connectorIdleWaiters;
115
- private _resetPromise;
116
- private _stateGeneration;
117
- private _connectorTeardownTail;
118
- private _pendingConnectorTeardowns;
119
- private _activeConnectionType;
120
- private _bindingSelectionRequestId;
121
- private _finishBleBinding;
122
- private _isBleConnection;
123
108
  constructor(connector: IConnector, options?: {
124
109
  autoInstallApp?: boolean;
125
110
  });
@@ -133,33 +118,22 @@ declare class LedgerAdapter implements IHardwareWallet {
133
118
  * The next operation will re-discover and re-connect automatically.
134
119
  */
135
120
  resetState(): void;
136
- private _resetStateAndDisconnectSessions;
137
121
  dispose(): Promise<void>;
138
122
  uiResponse(response: UiResponseEvent): void;
139
123
  searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
140
- private _searchDevices;
141
- searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
142
- listConnectionTargets(options?: SearchDevicesOptions): Promise<ConnectionTarget[]>;
143
124
  private _evictAllSessions;
144
125
  private static readonly MAX_BUSINESS_RETRY_BUDGET;
145
126
  private static readonly STUCK_APP_RETRY_DELAY_MS;
146
127
  private static readonly MAX_DOCONNECT_CONFIRMS;
147
128
  private _lastCancelReason;
148
- private readonly _activeOperationJobs;
149
- private readonly _pendingOperationDisconnects;
150
129
  private static readonly APP_INSTALL_PROGRESS_MIN_DELTA;
151
130
  private _installProgressLastEmittedValue;
152
131
  private _installProgressLastKey;
153
132
  private static _createDeviceBusyError;
154
- connectDevice(searchTargetId: string): Promise<Response<string>>;
155
- bindBleDevice(params: BindBleDeviceParams): Promise<Response<string>>;
156
- acquireOperation(connectId: string, context: IHardwareConnectionContext): Promise<Response<string>>;
157
- private _createOperation;
158
- private _connectTarget;
159
- releaseOperation(operationId: string): Promise<void>;
160
- private _releaseOperationConnection;
161
- private _releaseLostOperationConnection;
162
- getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
133
+ connectDevice(connectId: string): Promise<Response<string>>;
134
+ disconnectDevice(connectId: string): Promise<void>;
135
+ getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
136
+ getSupportedChains(): ChainCapability[];
163
137
  allNetworkGetAddress: (connectId: string, _deviceId: string, params: _onekeyfe_hwk_adapter_core.AllNetworkGetAddressParams) => Promise<Response<_onekeyfe_hwk_adapter_core.AllNetworkAddressResponse[]>>;
164
138
  private callChain;
165
139
  private static normalizeCallArgs;
@@ -183,8 +157,6 @@ declare class LedgerAdapter implements IHardwareWallet {
183
157
  tronGetAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronGetAddressParams>): Promise<Response<TronAddress>>;
184
158
  tronSignTransaction(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignTxParams>): Promise<Response<TronSignedTx>>;
185
159
  tronSignMessage(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignMsgParams>): Promise<Response<TronSignature>>;
186
- zcashGetFullViewingKey(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetFullViewingKeyParams>): Promise<Response<ZcashFullViewingKey>>;
187
- zcashGetShieldedAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetShieldedAddressParams>): Promise<Response<ZcashShieldedAddress>>;
188
160
  installApp(connectId: string, appName: string): Promise<Response<void>>;
189
161
  listInstalledApps(connectId: string): Promise<Response<AppMetadata[]>>;
190
162
  listInstalledNames(connectId: string): Promise<Response<string[]>>;
@@ -209,11 +181,11 @@ declare class LedgerAdapter implements IHardwareWallet {
209
181
  off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
210
182
  off(event: string, listener: DeviceEventListener): void;
211
183
  cancel(connectId?: string): void;
212
- /** A non-empty deviceId is an expected chain fingerprint, not a transport identifier. */
213
184
  getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
214
- /** Discovery may select a BLE target before a later call verifies its wallet. */
215
- private _publishVerifiedBleBinding;
216
- /** Verify on the acquired session without re-entering the job queue. */
185
+ /**
186
+ * Verify fingerprint using an existing sessionId directly.
187
+ * Safe to call inside connectorCall without causing queue deadlock.
188
+ */
217
189
  private _verifyDeviceFingerprintWithSession;
218
190
  /**
219
191
  * Compute the chain fingerprint via a caller-supplied call strategy.
@@ -235,17 +207,9 @@ declare class LedgerAdapter implements IHardwareWallet {
235
207
  *
236
208
  * - If a session already exists for the given connectId, reuse it.
237
209
  * - If ANY session exists (Ledger IDs are ephemeral), reuse it.
238
- * - Otherwise: search → one USB device auto-connects; multiple asks the host to choose.
210
+ * - Otherwise: search → exactly 1 USB device auto-connects; multiple or none throws.
239
211
  */
240
212
  private _connectingPromise;
241
- /**
242
- * The operation the running device job belongs to, so a UI request raised
243
- * mid-call can name it. A call pinned to an operation queues under its id
244
- * (`ledgerQueueKey`); a call without one queues under the connectId, and the
245
- * live operation on that connection is still the owner. Only work with no
246
- * operation at all (cold start) comes back undefined.
247
- */
248
- private _activeOperationId;
249
213
  private _waitForDeviceConnect;
250
214
  /**
251
215
  * Decide whether a BTC pubkey call needs `showOnDevice=true` because of
@@ -286,23 +250,34 @@ declare class LedgerAdapter implements IHardwareWallet {
286
250
  * lives in one place.
287
251
  */
288
252
  private _callConnector;
289
- private _assertConnectorReady;
290
- private _runConnectorTeardown;
291
- private _waitForConnectorOperationsToDrain;
292
- private _retainConnectorOperation;
293
253
  private connectorCall;
294
254
  /**
295
255
  * Race a promise against an abort signal. On abort, rejects with
296
256
  * signal.reason → instance _lastCancelReason → generic Error('Aborted').
297
257
  */
298
- /** Hermes/RN polyfills don't always populate signal.reason; fall back. */
299
- private _abortReason;
300
258
  private _abortable;
301
259
  /** Throw an AbortError if signal is already aborted. */
302
260
  private static _throwIfAborted;
303
261
  /** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
304
262
  private _runConnectorCall;
263
+ /**
264
+ * Stuck-app recovery: pause for the device's UI transition, then retry once.
265
+ *
266
+ * Caller has already cleared the session + reset connector. We wait so Stax
267
+ * finishes its post-CloseApp animation, then go through ensureConnected +
268
+ * fingerprint check + call exactly once. Caller decides what to do on a
269
+ * second stuck-app hit.
270
+ */
271
+ private _retryAfterStuckApp;
305
272
  private _sleepAbortable;
273
+ /**
274
+ * Clear stale session, reconnect, and retry the call.
275
+ *
276
+ * Timeout recovery starts with a full connector reset. After an APDU
277
+ * timeout, DMK/transport state may still emit malformed responses; retrying
278
+ * on the same DMK can poison the next chain switch.
279
+ */
280
+ private _retryWithFreshConnection;
306
281
  /**
307
282
  * Ensure OS-level device permission (Bluetooth / USB) before proceeding.
308
283
  *
@@ -523,18 +498,6 @@ declare class LedgerConnectorBase implements IConnector {
523
498
  private _getSignerManager;
524
499
  private _getDeviceAppsManager;
525
500
  private _invalidateSession;
526
- /**
527
- * Teardown for the OS-level actions that open a manager-api secure channel
528
- * (install, uninstall, genuine check). Cancelling the device action is what
529
- * stops DMK's xstate actor, which unsubscribes the secure-channel observable
530
- * and closes its WebSocket; dropping the canceller without firing it leaves
531
- * that teardown to run only if the action settled on its own.
532
- *
533
- * The DMK device session is deliberately kept: the secure channel is a
534
- * separate WebSocket per call, and disconnecting here would break the bounded
535
- * unlock/retry recovery the adapter runs on the original session.
536
- */
537
- private _teardownSecureChannelSession;
538
501
  /**
539
502
  * Replace an old session with a new one after app switch.
540
503
  * Emits device-connect so the adapter updates its _sessions Map.
@@ -691,25 +654,6 @@ declare class SignerSol {
691
654
  }>;
692
655
  }
693
656
 
694
- /**
695
- * Wraps Ledger's Zcash SDK signer (Observable-based DeviceActions) into a
696
- * simple async interface. Only the viewing-key and shielded-address reads are
697
- * exposed; PCZT signing goes through a different host-side pipeline.
698
- */
699
- declare class SignerZcash {
700
- private readonly _sdk;
701
- onInteraction?: (interaction: string) => void;
702
- onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void;
703
- constructor(_sdk: SignerZcash$1);
704
- /** GET_VK: UFVK string (default) or raw 96-byte Orchard FVK. */
705
- getFullViewingKey(derivationPath: string, options?: FullViewingKeyOptions): Promise<GetFullViewingKeyDAOutput>;
706
- /** GET_SHIELDED_ADDRESS: single-Orchard-receiver UA for a 5-level transparent path. */
707
- getShieldedAddress(derivationPath: string, options?: {
708
- checkOnDevice?: boolean;
709
- skipOpenApp?: boolean;
710
- }): Promise<GetShieldedAddressDAOutput>;
711
- }
712
-
713
657
  /**
714
658
  * Transport adapter that bridges Ledger's legacy hw-app-* SDKs to DMK's sendApdu.
715
659
  *
@@ -793,7 +737,7 @@ interface WrapErrorOptions {
793
737
  /** Fallback when err has no `appName` (DMK signer errors don't carry it). */
794
738
  defaultAppName?: string;
795
739
  }
796
- declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>, origin?: HwkErrorOrigin, recovery?: HwkRecoveryHint): LedgerFailure;
740
+ declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>): LedgerFailure;
797
741
  declare function isDeviceLockedError(err: unknown): boolean;
798
742
  /**
799
743
  * Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
@@ -803,7 +747,6 @@ declare function isDeviceLockedError(err: unknown): boolean;
803
747
  declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
804
748
  code: HardwareErrorCode;
805
749
  message: string;
806
- origin?: HwkErrorOrigin;
807
750
  appName?: string;
808
751
  };
809
752
 
@@ -839,4 +782,4 @@ declare function isLedgerDmkBleTransport(transport?: string): boolean;
839
782
  declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
840
783
  declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
841
784
 
842
- 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, SignerZcash, type TransportFactory, debugLog, deviceActionToPromise, isDeviceLockedError, isLedgerBleConnectionType, isLedgerBleDescriptor, isLedgerDmkBleTransport, ledgerFailure, mapLedgerError, offSdkEvent, onSdkEvent };
785
+ 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 };