@onekeyfe/hwk-ledger-adapter 1.2.8-alpha.50 → 1.2.8-alpha.51
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 +52 -86
- package/dist/index.d.ts +52 -86
- package/dist/index.js +969 -1931
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +878 -1865
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -14
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,
|
|
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,34 +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 _pendingPickBindings;
|
|
107
|
-
private readonly _sessionTransports;
|
|
108
|
-
private readonly _selectedBleReconnectTargets;
|
|
109
102
|
private readonly _uiRegistry;
|
|
110
103
|
private _btcHighIndexConfirmedThisSession;
|
|
111
104
|
private readonly _jobQueue;
|
|
112
105
|
private _deviceAuthenticityQueueTail;
|
|
113
106
|
private _doConnectAbortController;
|
|
114
|
-
private _connectingConnectId;
|
|
115
107
|
private readonly _defaultAutoInstallApp;
|
|
116
|
-
private readonly _unsettledConnectorOperations;
|
|
117
|
-
private readonly _connectorIdleWaiters;
|
|
118
|
-
private _resetPromise;
|
|
119
|
-
private _stateGeneration;
|
|
120
|
-
private _connectorTeardownTail;
|
|
121
|
-
private _pendingConnectorTeardowns;
|
|
122
|
-
private _activeConnectionType;
|
|
123
|
-
private _bindingSelectionRequestId;
|
|
124
|
-
private _discardPendingBinding;
|
|
125
|
-
private _finishBleBinding;
|
|
126
|
-
private _isBleConnection;
|
|
127
108
|
constructor(connector: IConnector, options?: {
|
|
128
109
|
autoInstallApp?: boolean;
|
|
129
110
|
});
|
|
@@ -137,41 +118,23 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
137
118
|
* The next operation will re-discover and re-connect automatically.
|
|
138
119
|
*/
|
|
139
120
|
resetState(): void;
|
|
140
|
-
private _resetStateAndDisconnectSessions;
|
|
141
121
|
dispose(): Promise<void>;
|
|
142
122
|
uiResponse(response: UiResponseEvent): void;
|
|
143
123
|
searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
|
|
144
|
-
private _searchDevices;
|
|
145
|
-
searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
|
|
146
124
|
private _evictAllSessions;
|
|
147
125
|
private static readonly MAX_BUSINESS_RETRY_BUDGET;
|
|
148
126
|
private static readonly STUCK_APP_RETRY_DELAY_MS;
|
|
149
127
|
private static readonly MAX_DOCONNECT_CONFIRMS;
|
|
150
128
|
private _lastCancelReason;
|
|
151
|
-
private readonly _activeOperationJobs;
|
|
152
|
-
private readonly _pendingOperationDisconnects;
|
|
153
129
|
private static readonly APP_INSTALL_PROGRESS_MIN_DELTA;
|
|
154
130
|
private _installProgressLastEmittedValue;
|
|
155
131
|
private _installProgressLastKey;
|
|
156
132
|
private static _createDeviceBusyError;
|
|
157
|
-
connectDevice(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
private _createOperation;
|
|
162
|
-
private _connectTarget;
|
|
163
|
-
releaseOperation(operationId: string): Promise<void>;
|
|
164
|
-
/**
|
|
165
|
-
* Ends a released operation's calls and prompts before teardown, which otherwise waits on a call
|
|
166
|
-
* that waits on a prompt nobody will answer. Device I/O already on the wire still drains.
|
|
167
|
-
*/
|
|
168
|
-
private _cancelOperationWork;
|
|
169
|
-
private _releaseOperationConnection;
|
|
170
|
-
private _releaseLostOperationConnection;
|
|
171
|
-
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[];
|
|
172
137
|
allNetworkGetAddress: (connectId: string, _deviceId: string, params: _onekeyfe_hwk_adapter_core.AllNetworkGetAddressParams) => Promise<Response<_onekeyfe_hwk_adapter_core.AllNetworkAddressResponse[]>>;
|
|
173
|
-
/** A bundle's BLE pick that no item got past the wallet check is not kept. */
|
|
174
|
-
private _dropUncheckedBundlePick;
|
|
175
138
|
private callChain;
|
|
176
139
|
private static normalizeCallArgs;
|
|
177
140
|
private static splitCommonParams;
|
|
@@ -194,8 +157,6 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
194
157
|
tronGetAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronGetAddressParams>): Promise<Response<TronAddress>>;
|
|
195
158
|
tronSignTransaction(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignTxParams>): Promise<Response<TronSignedTx>>;
|
|
196
159
|
tronSignMessage(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignMsgParams>): Promise<Response<TronSignature>>;
|
|
197
|
-
zcashGetFullViewingKey(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetFullViewingKeyParams>): Promise<Response<ZcashFullViewingKey>>;
|
|
198
|
-
zcashGetShieldedAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetShieldedAddressParams>): Promise<Response<ZcashShieldedAddress>>;
|
|
199
160
|
installApp(connectId: string, appName: string): Promise<Response<void>>;
|
|
200
161
|
listInstalledApps(connectId: string): Promise<Response<AppMetadata[]>>;
|
|
201
162
|
listInstalledNames(connectId: string): Promise<Response<string[]>>;
|
|
@@ -220,12 +181,11 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
220
181
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
221
182
|
off(event: string, listener: DeviceEventListener): void;
|
|
222
183
|
cancel(connectId?: string): void;
|
|
223
|
-
/** A non-empty deviceId is an expected chain fingerprint, not a transport identifier. */
|
|
224
184
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
225
|
-
/**
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Verify fingerprint using an existing sessionId directly.
|
|
187
|
+
* Safe to call inside connectorCall without causing queue deadlock.
|
|
188
|
+
*/
|
|
229
189
|
private _verifyDeviceFingerprintWithSession;
|
|
230
190
|
/**
|
|
231
191
|
* Compute the chain fingerprint via a caller-supplied call strategy.
|
|
@@ -242,12 +202,14 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
242
202
|
* to avoid queue deadlocks when running inside `connectorCall`.
|
|
243
203
|
*/
|
|
244
204
|
private _computeChainFingerprint;
|
|
245
|
-
private _connectingPromise;
|
|
246
205
|
/**
|
|
247
|
-
*
|
|
248
|
-
*
|
|
206
|
+
* Ensure at least one device is connected and return a valid connectId.
|
|
207
|
+
*
|
|
208
|
+
* - If a session already exists for the given connectId, reuse it.
|
|
209
|
+
* - If ANY session exists (Ledger IDs are ephemeral), reuse it.
|
|
210
|
+
* - Otherwise: search → exactly 1 USB device auto-connects; multiple or none throws.
|
|
249
211
|
*/
|
|
250
|
-
private
|
|
212
|
+
private _connectingPromise;
|
|
251
213
|
private _waitForDeviceConnect;
|
|
252
214
|
/**
|
|
253
215
|
* Decide whether a BTC pubkey call needs `showOnDevice=true` because of
|
|
@@ -258,13 +220,19 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
258
220
|
*/
|
|
259
221
|
private _gateBtcHighIndex;
|
|
260
222
|
private _waitForBtcHighIndexConfirm;
|
|
261
|
-
/** A cancel of the job ends its open prompt, even when no operation names that prompt. */
|
|
262
|
-
private _awaitUiAnswer;
|
|
263
223
|
private _waitForInstallAppConfirm;
|
|
264
224
|
private ensureConnected;
|
|
265
225
|
private _doConnect;
|
|
266
226
|
private _connectFirstOrSelect;
|
|
267
227
|
private _connectDeviceOrThrow;
|
|
228
|
+
/**
|
|
229
|
+
* Call the connector with automatic session resolution and disconnect retry.
|
|
230
|
+
*
|
|
231
|
+
* 1. Resolves a valid connectId via ensureConnected()
|
|
232
|
+
* 2. Looks up sessionId from _sessions
|
|
233
|
+
* 3. Calls connector.call()
|
|
234
|
+
* 4. On disconnect error: clears stale session, re-connects, retries once
|
|
235
|
+
*/
|
|
268
236
|
/**
|
|
269
237
|
* Unwrap a `ConnectorCallResult` back into the throw-based control flow this
|
|
270
238
|
* class relies on. On failure, rehydrate a FLAT Error (lifting `params.*`
|
|
@@ -282,13 +250,7 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
282
250
|
* lives in one place.
|
|
283
251
|
*/
|
|
284
252
|
private _callConnector;
|
|
285
|
-
private _assertConnectorReady;
|
|
286
|
-
private _runConnectorTeardown;
|
|
287
|
-
private _waitForConnectorOperationsToDrain;
|
|
288
|
-
private _retainConnectorOperation;
|
|
289
253
|
private connectorCall;
|
|
290
|
-
/** Hermes/RN polyfills don't always populate signal.reason; fall back. */
|
|
291
|
-
private _abortReason;
|
|
292
254
|
/**
|
|
293
255
|
* Race a promise against an abort signal. On abort, rejects with
|
|
294
256
|
* signal.reason → instance _lastCancelReason → generic Error('Aborted').
|
|
@@ -298,10 +260,35 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
298
260
|
private static _throwIfAborted;
|
|
299
261
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
300
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;
|
|
301
272
|
private _sleepAbortable;
|
|
302
273
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
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;
|
|
281
|
+
/**
|
|
282
|
+
* Ensure OS-level device permission (Bluetooth / USB) before proceeding.
|
|
283
|
+
*
|
|
284
|
+
* Emits `REQUEST_DEVICE_PERMISSION` and awaits the consumer's
|
|
285
|
+
* `RECEIVE_DEVICE_PERMISSION` reply (60s budget covers "probe → system
|
|
286
|
+
* prompt → user tap" plus a generous margin). If the consumer never wires
|
|
287
|
+
* a handler or never replies, the wait times out and the operation fails
|
|
288
|
+
* fast so scanners/callers don't hang silently.
|
|
289
|
+
*
|
|
290
|
+
* - No connectId (searchDevices): environment-level permission
|
|
291
|
+
* - With connectId (business methods): device-level permission
|
|
305
292
|
*/
|
|
306
293
|
private _ensureDevicePermission;
|
|
307
294
|
/**
|
|
@@ -511,7 +498,6 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
511
498
|
private _getSignerManager;
|
|
512
499
|
private _getDeviceAppsManager;
|
|
513
500
|
private _invalidateSession;
|
|
514
|
-
private _teardownSecureChannelSession;
|
|
515
501
|
/**
|
|
516
502
|
* Replace an old session with a new one after app switch.
|
|
517
503
|
* Emits device-connect so the adapter updates its _sessions Map.
|
|
@@ -668,25 +654,6 @@ declare class SignerSol {
|
|
|
668
654
|
}>;
|
|
669
655
|
}
|
|
670
656
|
|
|
671
|
-
/**
|
|
672
|
-
* Wraps Ledger's Zcash SDK signer (Observable-based DeviceActions) into a
|
|
673
|
-
* simple async interface. Only the viewing-key and shielded-address reads are
|
|
674
|
-
* exposed; PCZT signing goes through a different host-side pipeline.
|
|
675
|
-
*/
|
|
676
|
-
declare class SignerZcash {
|
|
677
|
-
private readonly _sdk;
|
|
678
|
-
onInteraction?: (interaction: string) => void;
|
|
679
|
-
onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void;
|
|
680
|
-
constructor(_sdk: SignerZcash$1);
|
|
681
|
-
/** GET_VK: UFVK string (default) or raw 96-byte Orchard FVK. */
|
|
682
|
-
getFullViewingKey(derivationPath: string, options?: FullViewingKeyOptions): Promise<GetFullViewingKeyDAOutput>;
|
|
683
|
-
/** GET_SHIELDED_ADDRESS: single-Orchard-receiver UA for a 5-level transparent path. */
|
|
684
|
-
getShieldedAddress(derivationPath: string, options?: {
|
|
685
|
-
checkOnDevice?: boolean;
|
|
686
|
-
skipOpenApp?: boolean;
|
|
687
|
-
}): Promise<GetShieldedAddressDAOutput>;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
657
|
/**
|
|
691
658
|
* Transport adapter that bridges Ledger's legacy hw-app-* SDKs to DMK's sendApdu.
|
|
692
659
|
*
|
|
@@ -770,7 +737,7 @@ interface WrapErrorOptions {
|
|
|
770
737
|
/** Fallback when err has no `appName` (DMK signer errors don't carry it). */
|
|
771
738
|
defaultAppName?: string;
|
|
772
739
|
}
|
|
773
|
-
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown
|
|
740
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>): LedgerFailure;
|
|
774
741
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
775
742
|
/**
|
|
776
743
|
* Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
|
|
@@ -780,7 +747,6 @@ declare function isDeviceLockedError(err: unknown): boolean;
|
|
|
780
747
|
declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
|
|
781
748
|
code: HardwareErrorCode;
|
|
782
749
|
message: string;
|
|
783
|
-
origin?: HwkErrorOrigin;
|
|
784
750
|
appName?: string;
|
|
785
751
|
};
|
|
786
752
|
|
|
@@ -816,4 +782,4 @@ declare function isLedgerDmkBleTransport(transport?: string): boolean;
|
|
|
816
782
|
declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
|
|
817
783
|
declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
|
|
818
784
|
|
|
819
|
-
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,
|
|
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,
|
|
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,34 +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 _pendingPickBindings;
|
|
107
|
-
private readonly _sessionTransports;
|
|
108
|
-
private readonly _selectedBleReconnectTargets;
|
|
109
102
|
private readonly _uiRegistry;
|
|
110
103
|
private _btcHighIndexConfirmedThisSession;
|
|
111
104
|
private readonly _jobQueue;
|
|
112
105
|
private _deviceAuthenticityQueueTail;
|
|
113
106
|
private _doConnectAbortController;
|
|
114
|
-
private _connectingConnectId;
|
|
115
107
|
private readonly _defaultAutoInstallApp;
|
|
116
|
-
private readonly _unsettledConnectorOperations;
|
|
117
|
-
private readonly _connectorIdleWaiters;
|
|
118
|
-
private _resetPromise;
|
|
119
|
-
private _stateGeneration;
|
|
120
|
-
private _connectorTeardownTail;
|
|
121
|
-
private _pendingConnectorTeardowns;
|
|
122
|
-
private _activeConnectionType;
|
|
123
|
-
private _bindingSelectionRequestId;
|
|
124
|
-
private _discardPendingBinding;
|
|
125
|
-
private _finishBleBinding;
|
|
126
|
-
private _isBleConnection;
|
|
127
108
|
constructor(connector: IConnector, options?: {
|
|
128
109
|
autoInstallApp?: boolean;
|
|
129
110
|
});
|
|
@@ -137,41 +118,23 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
137
118
|
* The next operation will re-discover and re-connect automatically.
|
|
138
119
|
*/
|
|
139
120
|
resetState(): void;
|
|
140
|
-
private _resetStateAndDisconnectSessions;
|
|
141
121
|
dispose(): Promise<void>;
|
|
142
122
|
uiResponse(response: UiResponseEvent): void;
|
|
143
123
|
searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
|
|
144
|
-
private _searchDevices;
|
|
145
|
-
searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
|
|
146
124
|
private _evictAllSessions;
|
|
147
125
|
private static readonly MAX_BUSINESS_RETRY_BUDGET;
|
|
148
126
|
private static readonly STUCK_APP_RETRY_DELAY_MS;
|
|
149
127
|
private static readonly MAX_DOCONNECT_CONFIRMS;
|
|
150
128
|
private _lastCancelReason;
|
|
151
|
-
private readonly _activeOperationJobs;
|
|
152
|
-
private readonly _pendingOperationDisconnects;
|
|
153
129
|
private static readonly APP_INSTALL_PROGRESS_MIN_DELTA;
|
|
154
130
|
private _installProgressLastEmittedValue;
|
|
155
131
|
private _installProgressLastKey;
|
|
156
132
|
private static _createDeviceBusyError;
|
|
157
|
-
connectDevice(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
private _createOperation;
|
|
162
|
-
private _connectTarget;
|
|
163
|
-
releaseOperation(operationId: string): Promise<void>;
|
|
164
|
-
/**
|
|
165
|
-
* Ends a released operation's calls and prompts before teardown, which otherwise waits on a call
|
|
166
|
-
* that waits on a prompt nobody will answer. Device I/O already on the wire still drains.
|
|
167
|
-
*/
|
|
168
|
-
private _cancelOperationWork;
|
|
169
|
-
private _releaseOperationConnection;
|
|
170
|
-
private _releaseLostOperationConnection;
|
|
171
|
-
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[];
|
|
172
137
|
allNetworkGetAddress: (connectId: string, _deviceId: string, params: _onekeyfe_hwk_adapter_core.AllNetworkGetAddressParams) => Promise<Response<_onekeyfe_hwk_adapter_core.AllNetworkAddressResponse[]>>;
|
|
173
|
-
/** A bundle's BLE pick that no item got past the wallet check is not kept. */
|
|
174
|
-
private _dropUncheckedBundlePick;
|
|
175
138
|
private callChain;
|
|
176
139
|
private static normalizeCallArgs;
|
|
177
140
|
private static splitCommonParams;
|
|
@@ -194,8 +157,6 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
194
157
|
tronGetAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronGetAddressParams>): Promise<Response<TronAddress>>;
|
|
195
158
|
tronSignTransaction(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignTxParams>): Promise<Response<TronSignedTx>>;
|
|
196
159
|
tronSignMessage(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignMsgParams>): Promise<Response<TronSignature>>;
|
|
197
|
-
zcashGetFullViewingKey(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetFullViewingKeyParams>): Promise<Response<ZcashFullViewingKey>>;
|
|
198
|
-
zcashGetShieldedAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetShieldedAddressParams>): Promise<Response<ZcashShieldedAddress>>;
|
|
199
160
|
installApp(connectId: string, appName: string): Promise<Response<void>>;
|
|
200
161
|
listInstalledApps(connectId: string): Promise<Response<AppMetadata[]>>;
|
|
201
162
|
listInstalledNames(connectId: string): Promise<Response<string[]>>;
|
|
@@ -220,12 +181,11 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
220
181
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
221
182
|
off(event: string, listener: DeviceEventListener): void;
|
|
222
183
|
cancel(connectId?: string): void;
|
|
223
|
-
/** A non-empty deviceId is an expected chain fingerprint, not a transport identifier. */
|
|
224
184
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
225
|
-
/**
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Verify fingerprint using an existing sessionId directly.
|
|
187
|
+
* Safe to call inside connectorCall without causing queue deadlock.
|
|
188
|
+
*/
|
|
229
189
|
private _verifyDeviceFingerprintWithSession;
|
|
230
190
|
/**
|
|
231
191
|
* Compute the chain fingerprint via a caller-supplied call strategy.
|
|
@@ -242,12 +202,14 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
242
202
|
* to avoid queue deadlocks when running inside `connectorCall`.
|
|
243
203
|
*/
|
|
244
204
|
private _computeChainFingerprint;
|
|
245
|
-
private _connectingPromise;
|
|
246
205
|
/**
|
|
247
|
-
*
|
|
248
|
-
*
|
|
206
|
+
* Ensure at least one device is connected and return a valid connectId.
|
|
207
|
+
*
|
|
208
|
+
* - If a session already exists for the given connectId, reuse it.
|
|
209
|
+
* - If ANY session exists (Ledger IDs are ephemeral), reuse it.
|
|
210
|
+
* - Otherwise: search → exactly 1 USB device auto-connects; multiple or none throws.
|
|
249
211
|
*/
|
|
250
|
-
private
|
|
212
|
+
private _connectingPromise;
|
|
251
213
|
private _waitForDeviceConnect;
|
|
252
214
|
/**
|
|
253
215
|
* Decide whether a BTC pubkey call needs `showOnDevice=true` because of
|
|
@@ -258,13 +220,19 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
258
220
|
*/
|
|
259
221
|
private _gateBtcHighIndex;
|
|
260
222
|
private _waitForBtcHighIndexConfirm;
|
|
261
|
-
/** A cancel of the job ends its open prompt, even when no operation names that prompt. */
|
|
262
|
-
private _awaitUiAnswer;
|
|
263
223
|
private _waitForInstallAppConfirm;
|
|
264
224
|
private ensureConnected;
|
|
265
225
|
private _doConnect;
|
|
266
226
|
private _connectFirstOrSelect;
|
|
267
227
|
private _connectDeviceOrThrow;
|
|
228
|
+
/**
|
|
229
|
+
* Call the connector with automatic session resolution and disconnect retry.
|
|
230
|
+
*
|
|
231
|
+
* 1. Resolves a valid connectId via ensureConnected()
|
|
232
|
+
* 2. Looks up sessionId from _sessions
|
|
233
|
+
* 3. Calls connector.call()
|
|
234
|
+
* 4. On disconnect error: clears stale session, re-connects, retries once
|
|
235
|
+
*/
|
|
268
236
|
/**
|
|
269
237
|
* Unwrap a `ConnectorCallResult` back into the throw-based control flow this
|
|
270
238
|
* class relies on. On failure, rehydrate a FLAT Error (lifting `params.*`
|
|
@@ -282,13 +250,7 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
282
250
|
* lives in one place.
|
|
283
251
|
*/
|
|
284
252
|
private _callConnector;
|
|
285
|
-
private _assertConnectorReady;
|
|
286
|
-
private _runConnectorTeardown;
|
|
287
|
-
private _waitForConnectorOperationsToDrain;
|
|
288
|
-
private _retainConnectorOperation;
|
|
289
253
|
private connectorCall;
|
|
290
|
-
/** Hermes/RN polyfills don't always populate signal.reason; fall back. */
|
|
291
|
-
private _abortReason;
|
|
292
254
|
/**
|
|
293
255
|
* Race a promise against an abort signal. On abort, rejects with
|
|
294
256
|
* signal.reason → instance _lastCancelReason → generic Error('Aborted').
|
|
@@ -298,10 +260,35 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
298
260
|
private static _throwIfAborted;
|
|
299
261
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
300
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;
|
|
301
272
|
private _sleepAbortable;
|
|
302
273
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
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;
|
|
281
|
+
/**
|
|
282
|
+
* Ensure OS-level device permission (Bluetooth / USB) before proceeding.
|
|
283
|
+
*
|
|
284
|
+
* Emits `REQUEST_DEVICE_PERMISSION` and awaits the consumer's
|
|
285
|
+
* `RECEIVE_DEVICE_PERMISSION` reply (60s budget covers "probe → system
|
|
286
|
+
* prompt → user tap" plus a generous margin). If the consumer never wires
|
|
287
|
+
* a handler or never replies, the wait times out and the operation fails
|
|
288
|
+
* fast so scanners/callers don't hang silently.
|
|
289
|
+
*
|
|
290
|
+
* - No connectId (searchDevices): environment-level permission
|
|
291
|
+
* - With connectId (business methods): device-level permission
|
|
305
292
|
*/
|
|
306
293
|
private _ensureDevicePermission;
|
|
307
294
|
/**
|
|
@@ -511,7 +498,6 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
511
498
|
private _getSignerManager;
|
|
512
499
|
private _getDeviceAppsManager;
|
|
513
500
|
private _invalidateSession;
|
|
514
|
-
private _teardownSecureChannelSession;
|
|
515
501
|
/**
|
|
516
502
|
* Replace an old session with a new one after app switch.
|
|
517
503
|
* Emits device-connect so the adapter updates its _sessions Map.
|
|
@@ -668,25 +654,6 @@ declare class SignerSol {
|
|
|
668
654
|
}>;
|
|
669
655
|
}
|
|
670
656
|
|
|
671
|
-
/**
|
|
672
|
-
* Wraps Ledger's Zcash SDK signer (Observable-based DeviceActions) into a
|
|
673
|
-
* simple async interface. Only the viewing-key and shielded-address reads are
|
|
674
|
-
* exposed; PCZT signing goes through a different host-side pipeline.
|
|
675
|
-
*/
|
|
676
|
-
declare class SignerZcash {
|
|
677
|
-
private readonly _sdk;
|
|
678
|
-
onInteraction?: (interaction: string) => void;
|
|
679
|
-
onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void;
|
|
680
|
-
constructor(_sdk: SignerZcash$1);
|
|
681
|
-
/** GET_VK: UFVK string (default) or raw 96-byte Orchard FVK. */
|
|
682
|
-
getFullViewingKey(derivationPath: string, options?: FullViewingKeyOptions): Promise<GetFullViewingKeyDAOutput>;
|
|
683
|
-
/** GET_SHIELDED_ADDRESS: single-Orchard-receiver UA for a 5-level transparent path. */
|
|
684
|
-
getShieldedAddress(derivationPath: string, options?: {
|
|
685
|
-
checkOnDevice?: boolean;
|
|
686
|
-
skipOpenApp?: boolean;
|
|
687
|
-
}): Promise<GetShieldedAddressDAOutput>;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
657
|
/**
|
|
691
658
|
* Transport adapter that bridges Ledger's legacy hw-app-* SDKs to DMK's sendApdu.
|
|
692
659
|
*
|
|
@@ -770,7 +737,7 @@ interface WrapErrorOptions {
|
|
|
770
737
|
/** Fallback when err has no `appName` (DMK signer errors don't carry it). */
|
|
771
738
|
defaultAppName?: string;
|
|
772
739
|
}
|
|
773
|
-
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown
|
|
740
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>): LedgerFailure;
|
|
774
741
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
775
742
|
/**
|
|
776
743
|
* Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
|
|
@@ -780,7 +747,6 @@ declare function isDeviceLockedError(err: unknown): boolean;
|
|
|
780
747
|
declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
|
|
781
748
|
code: HardwareErrorCode;
|
|
782
749
|
message: string;
|
|
783
|
-
origin?: HwkErrorOrigin;
|
|
784
750
|
appName?: string;
|
|
785
751
|
};
|
|
786
752
|
|
|
@@ -816,4 +782,4 @@ declare function isLedgerDmkBleTransport(transport?: string): boolean;
|
|
|
816
782
|
declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
|
|
817
783
|
declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
|
|
818
784
|
|
|
819
|
-
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,
|
|
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 };
|