@onekeyfe/hwk-ledger-adapter 1.2.8-alpha.9 → 1.2.9
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 +97 -52
- package/dist/index.d.ts +97 -52
- package/dist/index.js +2086 -992
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2034 -914
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -11
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as _onekeyfe_hwk_adapter_core from '@onekeyfe/hwk-adapter-core';
|
|
2
|
-
import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, Response,
|
|
2
|
+
import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, DeviceSearchTarget, 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';
|
|
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';
|
|
8
9
|
import Transport from '@ledgerhq/hw-transport';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -95,16 +96,34 @@ type LedgerCallParams<T> = NullableCallArg<IHardwareCallParams<T>>;
|
|
|
95
96
|
type LedgerCommonParams = NullableCallArg<IHardwareCommonCallParams>;
|
|
96
97
|
declare class LedgerAdapter implements IHardwareWallet {
|
|
97
98
|
readonly vendor: "ledger";
|
|
99
|
+
readonly cancelCapability: "stops-waiting";
|
|
98
100
|
private readonly connector;
|
|
99
101
|
private readonly emitter;
|
|
102
|
+
private readonly _operations;
|
|
100
103
|
private _discoveredDevices;
|
|
101
104
|
private _sessions;
|
|
105
|
+
private readonly _pendingOperationBindings;
|
|
106
|
+
private readonly _pendingPickBindings;
|
|
107
|
+
private readonly _sessionTransports;
|
|
108
|
+
private readonly _selectedBleReconnectTargets;
|
|
102
109
|
private readonly _uiRegistry;
|
|
103
110
|
private _btcHighIndexConfirmedThisSession;
|
|
104
111
|
private readonly _jobQueue;
|
|
105
112
|
private _deviceAuthenticityQueueTail;
|
|
106
113
|
private _doConnectAbortController;
|
|
114
|
+
private _connectingConnectId;
|
|
107
115
|
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;
|
|
108
127
|
constructor(connector: IConnector, options?: {
|
|
109
128
|
autoInstallApp?: boolean;
|
|
110
129
|
});
|
|
@@ -118,23 +137,47 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
118
137
|
* The next operation will re-discover and re-connect automatically.
|
|
119
138
|
*/
|
|
120
139
|
resetState(): void;
|
|
140
|
+
private _resetStateAndDisconnectSessions;
|
|
121
141
|
dispose(): Promise<void>;
|
|
122
142
|
uiResponse(response: UiResponseEvent): void;
|
|
123
143
|
searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
|
|
144
|
+
private _searchDevices;
|
|
145
|
+
searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
|
|
124
146
|
private _evictAllSessions;
|
|
125
147
|
private static readonly MAX_BUSINESS_RETRY_BUDGET;
|
|
126
148
|
private static readonly STUCK_APP_RETRY_DELAY_MS;
|
|
127
149
|
private static readonly MAX_DOCONNECT_CONFIRMS;
|
|
128
150
|
private _lastCancelReason;
|
|
151
|
+
private readonly _activeOperationJobs;
|
|
152
|
+
private readonly _pendingOperationDisconnects;
|
|
129
153
|
private static readonly APP_INSTALL_PROGRESS_MIN_DELTA;
|
|
130
154
|
private _installProgressLastEmittedValue;
|
|
131
155
|
private _installProgressLastKey;
|
|
132
156
|
private static _createDeviceBusyError;
|
|
133
|
-
connectDevice(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
157
|
+
connectDevice(searchTargetId: string): Promise<Response<string>>;
|
|
158
|
+
/** Binds the picked BLE device; with a recorded wallet identity it must match first. */
|
|
159
|
+
bindBleDevice(params: BindBleDeviceParams): Promise<Response<string>>;
|
|
160
|
+
acquireOperation(connectId: string, context: IHardwareConnectionContext): Promise<Response<string>>;
|
|
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
|
+
/**
|
|
170
|
+
* A running call by bare connectId (or still resolving its device by identity) may be on this
|
|
171
|
+
* connection, e.g. waiting for an unlock; its later stages need it, so it stays cached for that
|
|
172
|
+
* caller like any bare call's session. A lost connection is torn down regardless.
|
|
173
|
+
*/
|
|
174
|
+
private _bareCallMayUseConnection;
|
|
175
|
+
private _releaseOperationConnection;
|
|
176
|
+
private _releaseLostOperationConnection;
|
|
177
|
+
getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
137
178
|
allNetworkGetAddress: (connectId: string, _deviceId: string, params: _onekeyfe_hwk_adapter_core.AllNetworkGetAddressParams) => Promise<Response<_onekeyfe_hwk_adapter_core.AllNetworkAddressResponse[]>>;
|
|
179
|
+
/** A bundle's BLE pick that no item got past the wallet check is not kept. */
|
|
180
|
+
private _dropUncheckedBundlePick;
|
|
138
181
|
private callChain;
|
|
139
182
|
private static normalizeCallArgs;
|
|
140
183
|
private static splitCommonParams;
|
|
@@ -157,6 +200,8 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
157
200
|
tronGetAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronGetAddressParams>): Promise<Response<TronAddress>>;
|
|
158
201
|
tronSignTransaction(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignTxParams>): Promise<Response<TronSignedTx>>;
|
|
159
202
|
tronSignMessage(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignMsgParams>): Promise<Response<TronSignature>>;
|
|
203
|
+
zcashGetFullViewingKey(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetFullViewingKeyParams>): Promise<Response<ZcashFullViewingKey>>;
|
|
204
|
+
zcashGetShieldedAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetShieldedAddressParams>): Promise<Response<ZcashShieldedAddress>>;
|
|
160
205
|
installApp(connectId: string, appName: string): Promise<Response<void>>;
|
|
161
206
|
listInstalledApps(connectId: string): Promise<Response<AppMetadata[]>>;
|
|
162
207
|
listInstalledNames(connectId: string): Promise<Response<string[]>>;
|
|
@@ -181,11 +226,17 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
181
226
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
182
227
|
off(event: string, listener: DeviceEventListener): void;
|
|
183
228
|
cancel(connectId?: string): void;
|
|
229
|
+
/** A non-empty deviceId is an expected chain fingerprint, not a transport identifier. */
|
|
184
230
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
185
231
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
232
|
+
* Fingerprints the first recorded chain whose app the device can open. Only a missing app
|
|
233
|
+
* moves on to the next chain; when every app is missing, the first chain offers its install.
|
|
188
234
|
*/
|
|
235
|
+
private _fingerprintFirstOpenableChain;
|
|
236
|
+
/** Saves a picked BLE endpoint; `identity` is set when its wallet was just checked. */
|
|
237
|
+
private _saveSelectedBleBinding;
|
|
238
|
+
private _dropSession;
|
|
239
|
+
/** Verify on the acquired session without re-entering the job queue. */
|
|
189
240
|
private _verifyDeviceFingerprintWithSession;
|
|
190
241
|
/**
|
|
191
242
|
* Compute the chain fingerprint via a caller-supplied call strategy.
|
|
@@ -202,14 +253,12 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
202
253
|
* to avoid queue deadlocks when running inside `connectorCall`.
|
|
203
254
|
*/
|
|
204
255
|
private _computeChainFingerprint;
|
|
256
|
+
private _connectingPromise;
|
|
205
257
|
/**
|
|
206
|
-
*
|
|
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.
|
|
258
|
+
* Operation owning the running job, so a mid-call UI request can name it.
|
|
259
|
+
* Undefined at cold start when no operation owns the job.
|
|
211
260
|
*/
|
|
212
|
-
private
|
|
261
|
+
private _activeOperationId;
|
|
213
262
|
private _waitForDeviceConnect;
|
|
214
263
|
/**
|
|
215
264
|
* Decide whether a BTC pubkey call needs `showOnDevice=true` because of
|
|
@@ -220,19 +269,13 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
220
269
|
*/
|
|
221
270
|
private _gateBtcHighIndex;
|
|
222
271
|
private _waitForBtcHighIndexConfirm;
|
|
272
|
+
/** A cancel of the job ends its open prompt, even when no operation names that prompt. */
|
|
273
|
+
private _awaitUiAnswer;
|
|
223
274
|
private _waitForInstallAppConfirm;
|
|
224
275
|
private ensureConnected;
|
|
225
276
|
private _doConnect;
|
|
226
277
|
private _connectFirstOrSelect;
|
|
227
278
|
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
|
-
*/
|
|
236
279
|
/**
|
|
237
280
|
* Unwrap a `ConnectorCallResult` back into the throw-based control flow this
|
|
238
281
|
* class relies on. On failure, rehydrate a FLAT Error (lifting `params.*`
|
|
@@ -250,7 +293,13 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
250
293
|
* lives in one place.
|
|
251
294
|
*/
|
|
252
295
|
private _callConnector;
|
|
296
|
+
private _assertConnectorReady;
|
|
297
|
+
private _runConnectorTeardown;
|
|
298
|
+
private _waitForConnectorOperationsToDrain;
|
|
299
|
+
private _retainConnectorOperation;
|
|
253
300
|
private connectorCall;
|
|
301
|
+
/** Hermes/RN polyfills don't always populate signal.reason; fall back. */
|
|
302
|
+
private _abortReason;
|
|
254
303
|
/**
|
|
255
304
|
* Race a promise against an abort signal. On abort, rejects with
|
|
256
305
|
* signal.reason → instance _lastCancelReason → generic Error('Aborted').
|
|
@@ -260,35 +309,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
260
309
|
private static _throwIfAborted;
|
|
261
310
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
262
311
|
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;
|
|
272
312
|
private _sleepAbortable;
|
|
273
313
|
/**
|
|
274
|
-
*
|
|
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
|
|
314
|
+
* Ensure OS-level Bluetooth/USB permission; times out after 60s if the host never
|
|
315
|
+
* replies. Without connectId the request is environment-level, else device-level.
|
|
292
316
|
*/
|
|
293
317
|
private _ensureDevicePermission;
|
|
294
318
|
/**
|
|
@@ -498,6 +522,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
498
522
|
private _getSignerManager;
|
|
499
523
|
private _getDeviceAppsManager;
|
|
500
524
|
private _invalidateSession;
|
|
525
|
+
private _teardownSecureChannelSession;
|
|
501
526
|
/**
|
|
502
527
|
* Replace an old session with a new one after app switch.
|
|
503
528
|
* Emits device-connect so the adapter updates its _sessions Map.
|
|
@@ -516,8 +541,8 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
516
541
|
protected _emit<K extends ConnectorEventType>(event: K, data: ConnectorEventMap[K]): void;
|
|
517
542
|
/**
|
|
518
543
|
* Return a per-call ctx with the chain's Ledger app name pre-bound to
|
|
519
|
-
* wrapError, so chain handlers don't need to repeat
|
|
520
|
-
*
|
|
544
|
+
* UI prompts and wrapError, so chain handlers don't need to repeat the name.
|
|
545
|
+
* Falls through unchanged for unknown methods.
|
|
521
546
|
*/
|
|
522
547
|
private _ctxForMethod;
|
|
523
548
|
private _wrapError;
|
|
@@ -654,6 +679,25 @@ declare class SignerSol {
|
|
|
654
679
|
}>;
|
|
655
680
|
}
|
|
656
681
|
|
|
682
|
+
/**
|
|
683
|
+
* Wraps Ledger's Zcash SDK signer (Observable-based DeviceActions) into a
|
|
684
|
+
* simple async interface. Only the viewing-key and shielded-address reads are
|
|
685
|
+
* exposed; PCZT signing goes through a different host-side pipeline.
|
|
686
|
+
*/
|
|
687
|
+
declare class SignerZcash {
|
|
688
|
+
private readonly _sdk;
|
|
689
|
+
onInteraction?: (interaction: string) => void;
|
|
690
|
+
onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void;
|
|
691
|
+
constructor(_sdk: SignerZcash$1);
|
|
692
|
+
/** GET_VK: UFVK string (default) or raw 96-byte Orchard FVK. */
|
|
693
|
+
getFullViewingKey(derivationPath: string, options?: FullViewingKeyOptions): Promise<GetFullViewingKeyDAOutput>;
|
|
694
|
+
/** GET_SHIELDED_ADDRESS: single-Orchard-receiver UA for a 5-level transparent path. */
|
|
695
|
+
getShieldedAddress(derivationPath: string, options?: {
|
|
696
|
+
checkOnDevice?: boolean;
|
|
697
|
+
skipOpenApp?: boolean;
|
|
698
|
+
}): Promise<GetShieldedAddressDAOutput>;
|
|
699
|
+
}
|
|
700
|
+
|
|
657
701
|
/**
|
|
658
702
|
* Transport adapter that bridges Ledger's legacy hw-app-* SDKs to DMK's sendApdu.
|
|
659
703
|
*
|
|
@@ -737,7 +781,7 @@ interface WrapErrorOptions {
|
|
|
737
781
|
/** Fallback when err has no `appName` (DMK signer errors don't carry it). */
|
|
738
782
|
defaultAppName?: string;
|
|
739
783
|
}
|
|
740
|
-
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown
|
|
784
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>, origin?: HwkErrorOrigin, recovery?: HwkRecoveryHint): LedgerFailure;
|
|
741
785
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
742
786
|
/**
|
|
743
787
|
* Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
|
|
@@ -747,6 +791,7 @@ declare function isDeviceLockedError(err: unknown): boolean;
|
|
|
747
791
|
declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
|
|
748
792
|
code: HardwareErrorCode;
|
|
749
793
|
message: string;
|
|
794
|
+
origin?: HwkErrorOrigin;
|
|
750
795
|
appName?: string;
|
|
751
796
|
};
|
|
752
797
|
|
|
@@ -782,4 +827,4 @@ declare function isLedgerDmkBleTransport(transport?: string): boolean;
|
|
|
782
827
|
declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
|
|
783
828
|
declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
|
|
784
829
|
|
|
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 };
|
|
830
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as _onekeyfe_hwk_adapter_core from '@onekeyfe/hwk-adapter-core';
|
|
2
|
-
import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, Response,
|
|
2
|
+
import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, SearchDevicesOptions, DeviceInfo, DeviceSearchTarget, 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';
|
|
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';
|
|
8
9
|
import Transport from '@ledgerhq/hw-transport';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -95,16 +96,34 @@ type LedgerCallParams<T> = NullableCallArg<IHardwareCallParams<T>>;
|
|
|
95
96
|
type LedgerCommonParams = NullableCallArg<IHardwareCommonCallParams>;
|
|
96
97
|
declare class LedgerAdapter implements IHardwareWallet {
|
|
97
98
|
readonly vendor: "ledger";
|
|
99
|
+
readonly cancelCapability: "stops-waiting";
|
|
98
100
|
private readonly connector;
|
|
99
101
|
private readonly emitter;
|
|
102
|
+
private readonly _operations;
|
|
100
103
|
private _discoveredDevices;
|
|
101
104
|
private _sessions;
|
|
105
|
+
private readonly _pendingOperationBindings;
|
|
106
|
+
private readonly _pendingPickBindings;
|
|
107
|
+
private readonly _sessionTransports;
|
|
108
|
+
private readonly _selectedBleReconnectTargets;
|
|
102
109
|
private readonly _uiRegistry;
|
|
103
110
|
private _btcHighIndexConfirmedThisSession;
|
|
104
111
|
private readonly _jobQueue;
|
|
105
112
|
private _deviceAuthenticityQueueTail;
|
|
106
113
|
private _doConnectAbortController;
|
|
114
|
+
private _connectingConnectId;
|
|
107
115
|
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;
|
|
108
127
|
constructor(connector: IConnector, options?: {
|
|
109
128
|
autoInstallApp?: boolean;
|
|
110
129
|
});
|
|
@@ -118,23 +137,47 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
118
137
|
* The next operation will re-discover and re-connect automatically.
|
|
119
138
|
*/
|
|
120
139
|
resetState(): void;
|
|
140
|
+
private _resetStateAndDisconnectSessions;
|
|
121
141
|
dispose(): Promise<void>;
|
|
122
142
|
uiResponse(response: UiResponseEvent): void;
|
|
123
143
|
searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
|
|
144
|
+
private _searchDevices;
|
|
145
|
+
searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
|
|
124
146
|
private _evictAllSessions;
|
|
125
147
|
private static readonly MAX_BUSINESS_RETRY_BUDGET;
|
|
126
148
|
private static readonly STUCK_APP_RETRY_DELAY_MS;
|
|
127
149
|
private static readonly MAX_DOCONNECT_CONFIRMS;
|
|
128
150
|
private _lastCancelReason;
|
|
151
|
+
private readonly _activeOperationJobs;
|
|
152
|
+
private readonly _pendingOperationDisconnects;
|
|
129
153
|
private static readonly APP_INSTALL_PROGRESS_MIN_DELTA;
|
|
130
154
|
private _installProgressLastEmittedValue;
|
|
131
155
|
private _installProgressLastKey;
|
|
132
156
|
private static _createDeviceBusyError;
|
|
133
|
-
connectDevice(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
157
|
+
connectDevice(searchTargetId: string): Promise<Response<string>>;
|
|
158
|
+
/** Binds the picked BLE device; with a recorded wallet identity it must match first. */
|
|
159
|
+
bindBleDevice(params: BindBleDeviceParams): Promise<Response<string>>;
|
|
160
|
+
acquireOperation(connectId: string, context: IHardwareConnectionContext): Promise<Response<string>>;
|
|
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
|
+
/**
|
|
170
|
+
* A running call by bare connectId (or still resolving its device by identity) may be on this
|
|
171
|
+
* connection, e.g. waiting for an unlock; its later stages need it, so it stays cached for that
|
|
172
|
+
* caller like any bare call's session. A lost connection is torn down regardless.
|
|
173
|
+
*/
|
|
174
|
+
private _bareCallMayUseConnection;
|
|
175
|
+
private _releaseOperationConnection;
|
|
176
|
+
private _releaseLostOperationConnection;
|
|
177
|
+
getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
137
178
|
allNetworkGetAddress: (connectId: string, _deviceId: string, params: _onekeyfe_hwk_adapter_core.AllNetworkGetAddressParams) => Promise<Response<_onekeyfe_hwk_adapter_core.AllNetworkAddressResponse[]>>;
|
|
179
|
+
/** A bundle's BLE pick that no item got past the wallet check is not kept. */
|
|
180
|
+
private _dropUncheckedBundlePick;
|
|
138
181
|
private callChain;
|
|
139
182
|
private static normalizeCallArgs;
|
|
140
183
|
private static splitCommonParams;
|
|
@@ -157,6 +200,8 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
157
200
|
tronGetAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronGetAddressParams>): Promise<Response<TronAddress>>;
|
|
158
201
|
tronSignTransaction(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignTxParams>): Promise<Response<TronSignedTx>>;
|
|
159
202
|
tronSignMessage(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignMsgParams>): Promise<Response<TronSignature>>;
|
|
203
|
+
zcashGetFullViewingKey(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetFullViewingKeyParams>): Promise<Response<ZcashFullViewingKey>>;
|
|
204
|
+
zcashGetShieldedAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetShieldedAddressParams>): Promise<Response<ZcashShieldedAddress>>;
|
|
160
205
|
installApp(connectId: string, appName: string): Promise<Response<void>>;
|
|
161
206
|
listInstalledApps(connectId: string): Promise<Response<AppMetadata[]>>;
|
|
162
207
|
listInstalledNames(connectId: string): Promise<Response<string[]>>;
|
|
@@ -181,11 +226,17 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
181
226
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
182
227
|
off(event: string, listener: DeviceEventListener): void;
|
|
183
228
|
cancel(connectId?: string): void;
|
|
229
|
+
/** A non-empty deviceId is an expected chain fingerprint, not a transport identifier. */
|
|
184
230
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
185
231
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
232
|
+
* Fingerprints the first recorded chain whose app the device can open. Only a missing app
|
|
233
|
+
* moves on to the next chain; when every app is missing, the first chain offers its install.
|
|
188
234
|
*/
|
|
235
|
+
private _fingerprintFirstOpenableChain;
|
|
236
|
+
/** Saves a picked BLE endpoint; `identity` is set when its wallet was just checked. */
|
|
237
|
+
private _saveSelectedBleBinding;
|
|
238
|
+
private _dropSession;
|
|
239
|
+
/** Verify on the acquired session without re-entering the job queue. */
|
|
189
240
|
private _verifyDeviceFingerprintWithSession;
|
|
190
241
|
/**
|
|
191
242
|
* Compute the chain fingerprint via a caller-supplied call strategy.
|
|
@@ -202,14 +253,12 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
202
253
|
* to avoid queue deadlocks when running inside `connectorCall`.
|
|
203
254
|
*/
|
|
204
255
|
private _computeChainFingerprint;
|
|
256
|
+
private _connectingPromise;
|
|
205
257
|
/**
|
|
206
|
-
*
|
|
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.
|
|
258
|
+
* Operation owning the running job, so a mid-call UI request can name it.
|
|
259
|
+
* Undefined at cold start when no operation owns the job.
|
|
211
260
|
*/
|
|
212
|
-
private
|
|
261
|
+
private _activeOperationId;
|
|
213
262
|
private _waitForDeviceConnect;
|
|
214
263
|
/**
|
|
215
264
|
* Decide whether a BTC pubkey call needs `showOnDevice=true` because of
|
|
@@ -220,19 +269,13 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
220
269
|
*/
|
|
221
270
|
private _gateBtcHighIndex;
|
|
222
271
|
private _waitForBtcHighIndexConfirm;
|
|
272
|
+
/** A cancel of the job ends its open prompt, even when no operation names that prompt. */
|
|
273
|
+
private _awaitUiAnswer;
|
|
223
274
|
private _waitForInstallAppConfirm;
|
|
224
275
|
private ensureConnected;
|
|
225
276
|
private _doConnect;
|
|
226
277
|
private _connectFirstOrSelect;
|
|
227
278
|
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
|
-
*/
|
|
236
279
|
/**
|
|
237
280
|
* Unwrap a `ConnectorCallResult` back into the throw-based control flow this
|
|
238
281
|
* class relies on. On failure, rehydrate a FLAT Error (lifting `params.*`
|
|
@@ -250,7 +293,13 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
250
293
|
* lives in one place.
|
|
251
294
|
*/
|
|
252
295
|
private _callConnector;
|
|
296
|
+
private _assertConnectorReady;
|
|
297
|
+
private _runConnectorTeardown;
|
|
298
|
+
private _waitForConnectorOperationsToDrain;
|
|
299
|
+
private _retainConnectorOperation;
|
|
253
300
|
private connectorCall;
|
|
301
|
+
/** Hermes/RN polyfills don't always populate signal.reason; fall back. */
|
|
302
|
+
private _abortReason;
|
|
254
303
|
/**
|
|
255
304
|
* Race a promise against an abort signal. On abort, rejects with
|
|
256
305
|
* signal.reason → instance _lastCancelReason → generic Error('Aborted').
|
|
@@ -260,35 +309,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
260
309
|
private static _throwIfAborted;
|
|
261
310
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
262
311
|
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;
|
|
272
312
|
private _sleepAbortable;
|
|
273
313
|
/**
|
|
274
|
-
*
|
|
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
|
|
314
|
+
* Ensure OS-level Bluetooth/USB permission; times out after 60s if the host never
|
|
315
|
+
* replies. Without connectId the request is environment-level, else device-level.
|
|
292
316
|
*/
|
|
293
317
|
private _ensureDevicePermission;
|
|
294
318
|
/**
|
|
@@ -498,6 +522,7 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
498
522
|
private _getSignerManager;
|
|
499
523
|
private _getDeviceAppsManager;
|
|
500
524
|
private _invalidateSession;
|
|
525
|
+
private _teardownSecureChannelSession;
|
|
501
526
|
/**
|
|
502
527
|
* Replace an old session with a new one after app switch.
|
|
503
528
|
* Emits device-connect so the adapter updates its _sessions Map.
|
|
@@ -516,8 +541,8 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
516
541
|
protected _emit<K extends ConnectorEventType>(event: K, data: ConnectorEventMap[K]): void;
|
|
517
542
|
/**
|
|
518
543
|
* Return a per-call ctx with the chain's Ledger app name pre-bound to
|
|
519
|
-
* wrapError, so chain handlers don't need to repeat
|
|
520
|
-
*
|
|
544
|
+
* UI prompts and wrapError, so chain handlers don't need to repeat the name.
|
|
545
|
+
* Falls through unchanged for unknown methods.
|
|
521
546
|
*/
|
|
522
547
|
private _ctxForMethod;
|
|
523
548
|
private _wrapError;
|
|
@@ -654,6 +679,25 @@ declare class SignerSol {
|
|
|
654
679
|
}>;
|
|
655
680
|
}
|
|
656
681
|
|
|
682
|
+
/**
|
|
683
|
+
* Wraps Ledger's Zcash SDK signer (Observable-based DeviceActions) into a
|
|
684
|
+
* simple async interface. Only the viewing-key and shielded-address reads are
|
|
685
|
+
* exposed; PCZT signing goes through a different host-side pipeline.
|
|
686
|
+
*/
|
|
687
|
+
declare class SignerZcash {
|
|
688
|
+
private readonly _sdk;
|
|
689
|
+
onInteraction?: (interaction: string) => void;
|
|
690
|
+
onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void;
|
|
691
|
+
constructor(_sdk: SignerZcash$1);
|
|
692
|
+
/** GET_VK: UFVK string (default) or raw 96-byte Orchard FVK. */
|
|
693
|
+
getFullViewingKey(derivationPath: string, options?: FullViewingKeyOptions): Promise<GetFullViewingKeyDAOutput>;
|
|
694
|
+
/** GET_SHIELDED_ADDRESS: single-Orchard-receiver UA for a 5-level transparent path. */
|
|
695
|
+
getShieldedAddress(derivationPath: string, options?: {
|
|
696
|
+
checkOnDevice?: boolean;
|
|
697
|
+
skipOpenApp?: boolean;
|
|
698
|
+
}): Promise<GetShieldedAddressDAOutput>;
|
|
699
|
+
}
|
|
700
|
+
|
|
657
701
|
/**
|
|
658
702
|
* Transport adapter that bridges Ledger's legacy hw-app-* SDKs to DMK's sendApdu.
|
|
659
703
|
*
|
|
@@ -737,7 +781,7 @@ interface WrapErrorOptions {
|
|
|
737
781
|
/** Fallback when err has no `appName` (DMK signer errors don't carry it). */
|
|
738
782
|
defaultAppName?: string;
|
|
739
783
|
}
|
|
740
|
-
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown
|
|
784
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>, origin?: HwkErrorOrigin, recovery?: HwkRecoveryHint): LedgerFailure;
|
|
741
785
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
742
786
|
/**
|
|
743
787
|
* Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
|
|
@@ -747,6 +791,7 @@ declare function isDeviceLockedError(err: unknown): boolean;
|
|
|
747
791
|
declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
|
|
748
792
|
code: HardwareErrorCode;
|
|
749
793
|
message: string;
|
|
794
|
+
origin?: HwkErrorOrigin;
|
|
750
795
|
appName?: string;
|
|
751
796
|
};
|
|
752
797
|
|
|
@@ -782,4 +827,4 @@ declare function isLedgerDmkBleTransport(transport?: string): boolean;
|
|
|
782
827
|
declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
|
|
783
828
|
declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
|
|
784
829
|
|
|
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 };
|
|
830
|
+
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 };
|