@onekeyfe/hwk-ledger-adapter 1.2.4 → 1.2.5-alpha.0
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 +79 -39
- package/dist/index.d.ts +79 -39
- package/dist/index.js +1742 -843
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1758 -839
- 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, 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';
|
|
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,31 @@ 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 _verifiedBleReconnectTargets;
|
|
102
107
|
private readonly _uiRegistry;
|
|
103
108
|
private _btcHighIndexConfirmedThisSession;
|
|
104
109
|
private readonly _jobQueue;
|
|
105
110
|
private _deviceAuthenticityQueueTail;
|
|
106
111
|
private _doConnectAbortController;
|
|
112
|
+
private _connectingConnectId;
|
|
107
113
|
private readonly _defaultAutoInstallApp;
|
|
114
|
+
private readonly _unsettledConnectorOperations;
|
|
115
|
+
private readonly _connectorIdleWaiters;
|
|
116
|
+
private _resetPromise;
|
|
117
|
+
private _stateGeneration;
|
|
118
|
+
private _connectorTeardownTail;
|
|
119
|
+
private _pendingConnectorTeardowns;
|
|
120
|
+
private _activeConnectionType;
|
|
121
|
+
private _bindingSelectionRequestId;
|
|
122
|
+
private _finishBleBinding;
|
|
123
|
+
private _isBleConnection;
|
|
108
124
|
constructor(connector: IConnector, options?: {
|
|
109
125
|
autoInstallApp?: boolean;
|
|
110
126
|
});
|
|
@@ -118,22 +134,33 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
118
134
|
* The next operation will re-discover and re-connect automatically.
|
|
119
135
|
*/
|
|
120
136
|
resetState(): void;
|
|
137
|
+
private _resetStateAndDisconnectSessions;
|
|
121
138
|
dispose(): Promise<void>;
|
|
122
139
|
uiResponse(response: UiResponseEvent): void;
|
|
123
140
|
searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
|
|
141
|
+
private _searchDevices;
|
|
142
|
+
searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
|
|
143
|
+
listConnectionTargets(options?: SearchDevicesOptions): Promise<ConnectionTarget[]>;
|
|
124
144
|
private _evictAllSessions;
|
|
125
145
|
private static readonly MAX_BUSINESS_RETRY_BUDGET;
|
|
126
146
|
private static readonly STUCK_APP_RETRY_DELAY_MS;
|
|
127
147
|
private static readonly MAX_DOCONNECT_CONFIRMS;
|
|
128
148
|
private _lastCancelReason;
|
|
149
|
+
private readonly _activeOperationJobs;
|
|
150
|
+
private readonly _pendingOperationDisconnects;
|
|
129
151
|
private static readonly APP_INSTALL_PROGRESS_MIN_DELTA;
|
|
130
152
|
private _installProgressLastEmittedValue;
|
|
131
153
|
private _installProgressLastKey;
|
|
132
154
|
private static _createDeviceBusyError;
|
|
133
|
-
connectDevice(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
155
|
+
connectDevice(searchTargetId: string): Promise<Response<string>>;
|
|
156
|
+
bindBleDevice(params: BindBleDeviceParams): Promise<Response<string>>;
|
|
157
|
+
acquireOperation(connectId: string, context: IHardwareConnectionContext): Promise<Response<string>>;
|
|
158
|
+
private _createOperation;
|
|
159
|
+
private _connectTarget;
|
|
160
|
+
releaseOperation(operationId: string): Promise<void>;
|
|
161
|
+
private _releaseOperationConnection;
|
|
162
|
+
private _releaseLostOperationConnection;
|
|
163
|
+
getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
137
164
|
allNetworkGetAddress: (connectId: string, _deviceId: string, params: _onekeyfe_hwk_adapter_core.AllNetworkGetAddressParams) => Promise<Response<_onekeyfe_hwk_adapter_core.AllNetworkAddressResponse[]>>;
|
|
138
165
|
private callChain;
|
|
139
166
|
private static normalizeCallArgs;
|
|
@@ -157,6 +184,8 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
157
184
|
tronGetAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronGetAddressParams>): Promise<Response<TronAddress>>;
|
|
158
185
|
tronSignTransaction(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignTxParams>): Promise<Response<TronSignedTx>>;
|
|
159
186
|
tronSignMessage(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignMsgParams>): Promise<Response<TronSignature>>;
|
|
187
|
+
zcashGetFullViewingKey(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetFullViewingKeyParams>): Promise<Response<ZcashFullViewingKey>>;
|
|
188
|
+
zcashGetShieldedAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetShieldedAddressParams>): Promise<Response<ZcashShieldedAddress>>;
|
|
160
189
|
installApp(connectId: string, appName: string): Promise<Response<void>>;
|
|
161
190
|
listInstalledApps(connectId: string): Promise<Response<AppMetadata[]>>;
|
|
162
191
|
listInstalledNames(connectId: string): Promise<Response<string[]>>;
|
|
@@ -181,11 +210,11 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
181
210
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
182
211
|
off(event: string, listener: DeviceEventListener): void;
|
|
183
212
|
cancel(connectId?: string): void;
|
|
213
|
+
/** A non-empty deviceId is an expected chain fingerprint, not a transport identifier. */
|
|
184
214
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
185
|
-
/**
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
*/
|
|
215
|
+
/** Discovery may select a BLE target before a later call verifies its wallet. */
|
|
216
|
+
private _publishVerifiedBleBinding;
|
|
217
|
+
/** Verify on the acquired session without re-entering the job queue. */
|
|
189
218
|
private _verifyDeviceFingerprintWithSession;
|
|
190
219
|
/**
|
|
191
220
|
* Compute the chain fingerprint via a caller-supplied call strategy.
|
|
@@ -207,9 +236,14 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
207
236
|
*
|
|
208
237
|
* - If a session already exists for the given connectId, reuse it.
|
|
209
238
|
* - If ANY session exists (Ledger IDs are ephemeral), reuse it.
|
|
210
|
-
* - Otherwise: search →
|
|
239
|
+
* - Otherwise: search → one USB device auto-connects; multiple asks the host to choose.
|
|
211
240
|
*/
|
|
212
241
|
private _connectingPromise;
|
|
242
|
+
/**
|
|
243
|
+
* Operation owning the running job, so a mid-call UI request can name it.
|
|
244
|
+
* Undefined at cold start when no operation owns the job.
|
|
245
|
+
*/
|
|
246
|
+
private _activeOperationId;
|
|
213
247
|
private _waitForDeviceConnect;
|
|
214
248
|
/**
|
|
215
249
|
* Decide whether a BTC pubkey call needs `showOnDevice=true` because of
|
|
@@ -250,7 +284,13 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
250
284
|
* lives in one place.
|
|
251
285
|
*/
|
|
252
286
|
private _callConnector;
|
|
287
|
+
private _assertConnectorReady;
|
|
288
|
+
private _runConnectorTeardown;
|
|
289
|
+
private _waitForConnectorOperationsToDrain;
|
|
290
|
+
private _retainConnectorOperation;
|
|
253
291
|
private connectorCall;
|
|
292
|
+
/** Hermes/RN polyfills don't always populate signal.reason; fall back. */
|
|
293
|
+
private _abortReason;
|
|
254
294
|
/**
|
|
255
295
|
* Race a promise against an abort signal. On abort, rejects with
|
|
256
296
|
* signal.reason → instance _lastCancelReason → generic Error('Aborted').
|
|
@@ -260,35 +300,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
260
300
|
private static _throwIfAborted;
|
|
261
301
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
262
302
|
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
303
|
private _sleepAbortable;
|
|
273
304
|
/**
|
|
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
|
|
305
|
+
* Ensure OS-level Bluetooth/USB permission; times out after 60s if the host never
|
|
306
|
+
* replies. Without connectId the request is environment-level, else device-level.
|
|
292
307
|
*/
|
|
293
308
|
private _ensureDevicePermission;
|
|
294
309
|
/**
|
|
@@ -498,6 +513,11 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
498
513
|
private _getSignerManager;
|
|
499
514
|
private _getDeviceAppsManager;
|
|
500
515
|
private _invalidateSession;
|
|
516
|
+
/**
|
|
517
|
+
* Fire the canceller so DMK closes the secure-channel WebSocket. The DMK device
|
|
518
|
+
* session is kept: unlock/retry recovery reuses it.
|
|
519
|
+
*/
|
|
520
|
+
private _teardownSecureChannelSession;
|
|
501
521
|
/**
|
|
502
522
|
* Replace an old session with a new one after app switch.
|
|
503
523
|
* Emits device-connect so the adapter updates its _sessions Map.
|
|
@@ -654,6 +674,25 @@ declare class SignerSol {
|
|
|
654
674
|
}>;
|
|
655
675
|
}
|
|
656
676
|
|
|
677
|
+
/**
|
|
678
|
+
* Wraps Ledger's Zcash SDK signer (Observable-based DeviceActions) into a
|
|
679
|
+
* simple async interface. Only the viewing-key and shielded-address reads are
|
|
680
|
+
* exposed; PCZT signing goes through a different host-side pipeline.
|
|
681
|
+
*/
|
|
682
|
+
declare class SignerZcash {
|
|
683
|
+
private readonly _sdk;
|
|
684
|
+
onInteraction?: (interaction: string) => void;
|
|
685
|
+
onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void;
|
|
686
|
+
constructor(_sdk: SignerZcash$1);
|
|
687
|
+
/** GET_VK: UFVK string (default) or raw 96-byte Orchard FVK. */
|
|
688
|
+
getFullViewingKey(derivationPath: string, options?: FullViewingKeyOptions): Promise<GetFullViewingKeyDAOutput>;
|
|
689
|
+
/** GET_SHIELDED_ADDRESS: single-Orchard-receiver UA for a 5-level transparent path. */
|
|
690
|
+
getShieldedAddress(derivationPath: string, options?: {
|
|
691
|
+
checkOnDevice?: boolean;
|
|
692
|
+
skipOpenApp?: boolean;
|
|
693
|
+
}): Promise<GetShieldedAddressDAOutput>;
|
|
694
|
+
}
|
|
695
|
+
|
|
657
696
|
/**
|
|
658
697
|
* Transport adapter that bridges Ledger's legacy hw-app-* SDKs to DMK's sendApdu.
|
|
659
698
|
*
|
|
@@ -737,7 +776,7 @@ interface WrapErrorOptions {
|
|
|
737
776
|
/** Fallback when err has no `appName` (DMK signer errors don't carry it). */
|
|
738
777
|
defaultAppName?: string;
|
|
739
778
|
}
|
|
740
|
-
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown
|
|
779
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>, origin?: HwkErrorOrigin, recovery?: HwkRecoveryHint): LedgerFailure;
|
|
741
780
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
742
781
|
/**
|
|
743
782
|
* Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
|
|
@@ -747,6 +786,7 @@ declare function isDeviceLockedError(err: unknown): boolean;
|
|
|
747
786
|
declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
|
|
748
787
|
code: HardwareErrorCode;
|
|
749
788
|
message: string;
|
|
789
|
+
origin?: HwkErrorOrigin;
|
|
750
790
|
appName?: string;
|
|
751
791
|
};
|
|
752
792
|
|
|
@@ -782,4 +822,4 @@ declare function isLedgerDmkBleTransport(transport?: string): boolean;
|
|
|
782
822
|
declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
|
|
783
823
|
declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
|
|
784
824
|
|
|
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 };
|
|
825
|
+
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, 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';
|
|
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,31 @@ 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 _verifiedBleReconnectTargets;
|
|
102
107
|
private readonly _uiRegistry;
|
|
103
108
|
private _btcHighIndexConfirmedThisSession;
|
|
104
109
|
private readonly _jobQueue;
|
|
105
110
|
private _deviceAuthenticityQueueTail;
|
|
106
111
|
private _doConnectAbortController;
|
|
112
|
+
private _connectingConnectId;
|
|
107
113
|
private readonly _defaultAutoInstallApp;
|
|
114
|
+
private readonly _unsettledConnectorOperations;
|
|
115
|
+
private readonly _connectorIdleWaiters;
|
|
116
|
+
private _resetPromise;
|
|
117
|
+
private _stateGeneration;
|
|
118
|
+
private _connectorTeardownTail;
|
|
119
|
+
private _pendingConnectorTeardowns;
|
|
120
|
+
private _activeConnectionType;
|
|
121
|
+
private _bindingSelectionRequestId;
|
|
122
|
+
private _finishBleBinding;
|
|
123
|
+
private _isBleConnection;
|
|
108
124
|
constructor(connector: IConnector, options?: {
|
|
109
125
|
autoInstallApp?: boolean;
|
|
110
126
|
});
|
|
@@ -118,22 +134,33 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
118
134
|
* The next operation will re-discover and re-connect automatically.
|
|
119
135
|
*/
|
|
120
136
|
resetState(): void;
|
|
137
|
+
private _resetStateAndDisconnectSessions;
|
|
121
138
|
dispose(): Promise<void>;
|
|
122
139
|
uiResponse(response: UiResponseEvent): void;
|
|
123
140
|
searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
|
|
141
|
+
private _searchDevices;
|
|
142
|
+
searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
|
|
143
|
+
listConnectionTargets(options?: SearchDevicesOptions): Promise<ConnectionTarget[]>;
|
|
124
144
|
private _evictAllSessions;
|
|
125
145
|
private static readonly MAX_BUSINESS_RETRY_BUDGET;
|
|
126
146
|
private static readonly STUCK_APP_RETRY_DELAY_MS;
|
|
127
147
|
private static readonly MAX_DOCONNECT_CONFIRMS;
|
|
128
148
|
private _lastCancelReason;
|
|
149
|
+
private readonly _activeOperationJobs;
|
|
150
|
+
private readonly _pendingOperationDisconnects;
|
|
129
151
|
private static readonly APP_INSTALL_PROGRESS_MIN_DELTA;
|
|
130
152
|
private _installProgressLastEmittedValue;
|
|
131
153
|
private _installProgressLastKey;
|
|
132
154
|
private static _createDeviceBusyError;
|
|
133
|
-
connectDevice(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
155
|
+
connectDevice(searchTargetId: string): Promise<Response<string>>;
|
|
156
|
+
bindBleDevice(params: BindBleDeviceParams): Promise<Response<string>>;
|
|
157
|
+
acquireOperation(connectId: string, context: IHardwareConnectionContext): Promise<Response<string>>;
|
|
158
|
+
private _createOperation;
|
|
159
|
+
private _connectTarget;
|
|
160
|
+
releaseOperation(operationId: string): Promise<void>;
|
|
161
|
+
private _releaseOperationConnection;
|
|
162
|
+
private _releaseLostOperationConnection;
|
|
163
|
+
getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
137
164
|
allNetworkGetAddress: (connectId: string, _deviceId: string, params: _onekeyfe_hwk_adapter_core.AllNetworkGetAddressParams) => Promise<Response<_onekeyfe_hwk_adapter_core.AllNetworkAddressResponse[]>>;
|
|
138
165
|
private callChain;
|
|
139
166
|
private static normalizeCallArgs;
|
|
@@ -157,6 +184,8 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
157
184
|
tronGetAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronGetAddressParams>): Promise<Response<TronAddress>>;
|
|
158
185
|
tronSignTransaction(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignTxParams>): Promise<Response<TronSignedTx>>;
|
|
159
186
|
tronSignMessage(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<TronSignMsgParams>): Promise<Response<TronSignature>>;
|
|
187
|
+
zcashGetFullViewingKey(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetFullViewingKeyParams>): Promise<Response<ZcashFullViewingKey>>;
|
|
188
|
+
zcashGetShieldedAddress(connectId?: string | null, deviceId?: string | null, params?: LedgerCallParams<ZcashGetShieldedAddressParams>): Promise<Response<ZcashShieldedAddress>>;
|
|
160
189
|
installApp(connectId: string, appName: string): Promise<Response<void>>;
|
|
161
190
|
listInstalledApps(connectId: string): Promise<Response<AppMetadata[]>>;
|
|
162
191
|
listInstalledNames(connectId: string): Promise<Response<string[]>>;
|
|
@@ -181,11 +210,11 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
181
210
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
182
211
|
off(event: string, listener: DeviceEventListener): void;
|
|
183
212
|
cancel(connectId?: string): void;
|
|
213
|
+
/** A non-empty deviceId is an expected chain fingerprint, not a transport identifier. */
|
|
184
214
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
185
|
-
/**
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
*/
|
|
215
|
+
/** Discovery may select a BLE target before a later call verifies its wallet. */
|
|
216
|
+
private _publishVerifiedBleBinding;
|
|
217
|
+
/** Verify on the acquired session without re-entering the job queue. */
|
|
189
218
|
private _verifyDeviceFingerprintWithSession;
|
|
190
219
|
/**
|
|
191
220
|
* Compute the chain fingerprint via a caller-supplied call strategy.
|
|
@@ -207,9 +236,14 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
207
236
|
*
|
|
208
237
|
* - If a session already exists for the given connectId, reuse it.
|
|
209
238
|
* - If ANY session exists (Ledger IDs are ephemeral), reuse it.
|
|
210
|
-
* - Otherwise: search →
|
|
239
|
+
* - Otherwise: search → one USB device auto-connects; multiple asks the host to choose.
|
|
211
240
|
*/
|
|
212
241
|
private _connectingPromise;
|
|
242
|
+
/**
|
|
243
|
+
* Operation owning the running job, so a mid-call UI request can name it.
|
|
244
|
+
* Undefined at cold start when no operation owns the job.
|
|
245
|
+
*/
|
|
246
|
+
private _activeOperationId;
|
|
213
247
|
private _waitForDeviceConnect;
|
|
214
248
|
/**
|
|
215
249
|
* Decide whether a BTC pubkey call needs `showOnDevice=true` because of
|
|
@@ -250,7 +284,13 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
250
284
|
* lives in one place.
|
|
251
285
|
*/
|
|
252
286
|
private _callConnector;
|
|
287
|
+
private _assertConnectorReady;
|
|
288
|
+
private _runConnectorTeardown;
|
|
289
|
+
private _waitForConnectorOperationsToDrain;
|
|
290
|
+
private _retainConnectorOperation;
|
|
253
291
|
private connectorCall;
|
|
292
|
+
/** Hermes/RN polyfills don't always populate signal.reason; fall back. */
|
|
293
|
+
private _abortReason;
|
|
254
294
|
/**
|
|
255
295
|
* Race a promise against an abort signal. On abort, rejects with
|
|
256
296
|
* signal.reason → instance _lastCancelReason → generic Error('Aborted').
|
|
@@ -260,35 +300,10 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
260
300
|
private static _throwIfAborted;
|
|
261
301
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
262
302
|
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
303
|
private _sleepAbortable;
|
|
273
304
|
/**
|
|
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
|
|
305
|
+
* Ensure OS-level Bluetooth/USB permission; times out after 60s if the host never
|
|
306
|
+
* replies. Without connectId the request is environment-level, else device-level.
|
|
292
307
|
*/
|
|
293
308
|
private _ensureDevicePermission;
|
|
294
309
|
/**
|
|
@@ -498,6 +513,11 @@ declare class LedgerConnectorBase implements IConnector {
|
|
|
498
513
|
private _getSignerManager;
|
|
499
514
|
private _getDeviceAppsManager;
|
|
500
515
|
private _invalidateSession;
|
|
516
|
+
/**
|
|
517
|
+
* Fire the canceller so DMK closes the secure-channel WebSocket. The DMK device
|
|
518
|
+
* session is kept: unlock/retry recovery reuses it.
|
|
519
|
+
*/
|
|
520
|
+
private _teardownSecureChannelSession;
|
|
501
521
|
/**
|
|
502
522
|
* Replace an old session with a new one after app switch.
|
|
503
523
|
* Emits device-connect so the adapter updates its _sessions Map.
|
|
@@ -654,6 +674,25 @@ declare class SignerSol {
|
|
|
654
674
|
}>;
|
|
655
675
|
}
|
|
656
676
|
|
|
677
|
+
/**
|
|
678
|
+
* Wraps Ledger's Zcash SDK signer (Observable-based DeviceActions) into a
|
|
679
|
+
* simple async interface. Only the viewing-key and shielded-address reads are
|
|
680
|
+
* exposed; PCZT signing goes through a different host-side pipeline.
|
|
681
|
+
*/
|
|
682
|
+
declare class SignerZcash {
|
|
683
|
+
private readonly _sdk;
|
|
684
|
+
onInteraction?: (interaction: string) => void;
|
|
685
|
+
onRegisterCanceller?: (cancel: (reason?: CancelReason) => void) => void;
|
|
686
|
+
constructor(_sdk: SignerZcash$1);
|
|
687
|
+
/** GET_VK: UFVK string (default) or raw 96-byte Orchard FVK. */
|
|
688
|
+
getFullViewingKey(derivationPath: string, options?: FullViewingKeyOptions): Promise<GetFullViewingKeyDAOutput>;
|
|
689
|
+
/** GET_SHIELDED_ADDRESS: single-Orchard-receiver UA for a 5-level transparent path. */
|
|
690
|
+
getShieldedAddress(derivationPath: string, options?: {
|
|
691
|
+
checkOnDevice?: boolean;
|
|
692
|
+
skipOpenApp?: boolean;
|
|
693
|
+
}): Promise<GetShieldedAddressDAOutput>;
|
|
694
|
+
}
|
|
695
|
+
|
|
657
696
|
/**
|
|
658
697
|
* Transport adapter that bridges Ledger's legacy hw-app-* SDKs to DMK's sendApdu.
|
|
659
698
|
*
|
|
@@ -737,7 +776,7 @@ interface WrapErrorOptions {
|
|
|
737
776
|
/** Fallback when err has no `appName` (DMK signer errors don't carry it). */
|
|
738
777
|
defaultAppName?: string;
|
|
739
778
|
}
|
|
740
|
-
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown
|
|
779
|
+
declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?: string, tag?: string, params?: Record<string, unknown>, origin?: HwkErrorOrigin, recovery?: HwkRecoveryHint): LedgerFailure;
|
|
741
780
|
declare function isDeviceLockedError(err: unknown): boolean;
|
|
742
781
|
/**
|
|
743
782
|
* Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
|
|
@@ -747,6 +786,7 @@ declare function isDeviceLockedError(err: unknown): boolean;
|
|
|
747
786
|
declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
|
|
748
787
|
code: HardwareErrorCode;
|
|
749
788
|
message: string;
|
|
789
|
+
origin?: HwkErrorOrigin;
|
|
750
790
|
appName?: string;
|
|
751
791
|
};
|
|
752
792
|
|
|
@@ -782,4 +822,4 @@ declare function isLedgerDmkBleTransport(transport?: string): boolean;
|
|
|
782
822
|
declare function isLedgerBleConnectionType(connectionType?: ConnectionType): boolean;
|
|
783
823
|
declare function isLedgerBleDescriptor(connectionType: ConnectionType, descriptor: DeviceDescriptor): boolean;
|
|
784
824
|
|
|
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 };
|
|
825
|
+
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 };
|