@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.6 → 1.1.26-alpha.8
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 +12 -8
- package/dist/index.d.ts +12 -8
- package/dist/index.js +35 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IHardwareWallet, IConnector, TransportType,
|
|
1
|
+
import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, Failure, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
|
|
2
2
|
import { DeviceManagementKit, DeviceActionState as DeviceActionState$1, DiscoveredDevice, ExecuteDeviceActionReturnType } from '@ledgerhq/device-management-kit';
|
|
3
3
|
import { Address, Signature, SignerEth as SignerEth$1, TypedData } from '@ledgerhq/device-signer-kit-ethereum';
|
|
4
4
|
import { SignerBtc as SignerBtc$1 } from '@ledgerhq/device-signer-kit-bitcoin';
|
|
@@ -21,13 +21,12 @@ interface LedgerAdapterOptions {
|
|
|
21
21
|
* - Translates IHardwareWallet method calls to connector.call() invocations
|
|
22
22
|
* - Maps connector results/errors to our Response<T> format with enriched error messages
|
|
23
23
|
* - Translates connector events to HardwareEventMap events
|
|
24
|
-
* -
|
|
24
|
+
* - Emits `REQUEST_DEVICE_PERMISSION` for OS-level permission checks
|
|
25
25
|
*/
|
|
26
26
|
declare class LedgerAdapter implements IHardwareWallet {
|
|
27
27
|
readonly vendor: "ledger";
|
|
28
28
|
private readonly connector;
|
|
29
29
|
private readonly emitter;
|
|
30
|
-
private _uiHandler;
|
|
31
30
|
private readonly _handleSelectDevice;
|
|
32
31
|
private _discoveredDevices;
|
|
33
32
|
private _sessions;
|
|
@@ -44,7 +43,6 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
44
43
|
get activeTransport(): TransportType | null;
|
|
45
44
|
getAvailableTransports(): TransportType[];
|
|
46
45
|
switchTransport(_type: TransportType): Promise<void>;
|
|
47
|
-
setUiHandler(handler: Partial<IUiHandler>): void;
|
|
48
46
|
init(_config?: unknown): Promise<void>;
|
|
49
47
|
/**
|
|
50
48
|
* Clear cached device/session state without tearing down the adapter.
|
|
@@ -149,10 +147,16 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
149
147
|
/** Clear stale session, reconnect, and retry the call. */
|
|
150
148
|
private _retryWithFreshConnection;
|
|
151
149
|
/**
|
|
152
|
-
* Ensure device permission before proceeding.
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
150
|
+
* Ensure OS-level device permission (Bluetooth / USB) before proceeding.
|
|
151
|
+
*
|
|
152
|
+
* Emits `REQUEST_DEVICE_PERMISSION` and awaits the consumer's
|
|
153
|
+
* `RECEIVE_DEVICE_PERMISSION` reply (60s budget covers "probe → system
|
|
154
|
+
* prompt → user tap" plus a generous margin). If the consumer never wires
|
|
155
|
+
* a handler or never replies, the wait times out and the operation fails
|
|
156
|
+
* fast so scanners/callers don't hang silently.
|
|
157
|
+
*
|
|
158
|
+
* - No connectId (searchDevices): environment-level permission
|
|
159
|
+
* - With connectId (business methods): device-level permission
|
|
156
160
|
*/
|
|
157
161
|
private _ensureDevicePermission;
|
|
158
162
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IHardwareWallet, IConnector, TransportType,
|
|
1
|
+
import { IHardwareWallet, IConnector, TransportType, UiResponseEvent, DeviceInfo, Response, ChainCapability, EvmGetAddressParams, EvmAddress, ProgressCallback, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature, HardwareEventMap, DeviceEventListener, ChainForFingerprint, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, Failure, HardwareErrorCode } from '@onekeyfe/hwk-adapter-core';
|
|
2
2
|
import { DeviceManagementKit, DeviceActionState as DeviceActionState$1, DiscoveredDevice, ExecuteDeviceActionReturnType } from '@ledgerhq/device-management-kit';
|
|
3
3
|
import { Address, Signature, SignerEth as SignerEth$1, TypedData } from '@ledgerhq/device-signer-kit-ethereum';
|
|
4
4
|
import { SignerBtc as SignerBtc$1 } from '@ledgerhq/device-signer-kit-bitcoin';
|
|
@@ -21,13 +21,12 @@ interface LedgerAdapterOptions {
|
|
|
21
21
|
* - Translates IHardwareWallet method calls to connector.call() invocations
|
|
22
22
|
* - Maps connector results/errors to our Response<T> format with enriched error messages
|
|
23
23
|
* - Translates connector events to HardwareEventMap events
|
|
24
|
-
* -
|
|
24
|
+
* - Emits `REQUEST_DEVICE_PERMISSION` for OS-level permission checks
|
|
25
25
|
*/
|
|
26
26
|
declare class LedgerAdapter implements IHardwareWallet {
|
|
27
27
|
readonly vendor: "ledger";
|
|
28
28
|
private readonly connector;
|
|
29
29
|
private readonly emitter;
|
|
30
|
-
private _uiHandler;
|
|
31
30
|
private readonly _handleSelectDevice;
|
|
32
31
|
private _discoveredDevices;
|
|
33
32
|
private _sessions;
|
|
@@ -44,7 +43,6 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
44
43
|
get activeTransport(): TransportType | null;
|
|
45
44
|
getAvailableTransports(): TransportType[];
|
|
46
45
|
switchTransport(_type: TransportType): Promise<void>;
|
|
47
|
-
setUiHandler(handler: Partial<IUiHandler>): void;
|
|
48
46
|
init(_config?: unknown): Promise<void>;
|
|
49
47
|
/**
|
|
50
48
|
* Clear cached device/session state without tearing down the adapter.
|
|
@@ -149,10 +147,16 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
149
147
|
/** Clear stale session, reconnect, and retry the call. */
|
|
150
148
|
private _retryWithFreshConnection;
|
|
151
149
|
/**
|
|
152
|
-
* Ensure device permission before proceeding.
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
150
|
+
* Ensure OS-level device permission (Bluetooth / USB) before proceeding.
|
|
151
|
+
*
|
|
152
|
+
* Emits `REQUEST_DEVICE_PERMISSION` and awaits the consumer's
|
|
153
|
+
* `RECEIVE_DEVICE_PERMISSION` reply (60s budget covers "probe → system
|
|
154
|
+
* prompt → user tap" plus a generous margin). If the consumer never wires
|
|
155
|
+
* a handler or never replies, the wait times out and the operation fails
|
|
156
|
+
* fast so scanners/callers don't hang silently.
|
|
157
|
+
*
|
|
158
|
+
* - No connectId (searchDevices): environment-level permission
|
|
159
|
+
* - With connectId (business methods): device-level permission
|
|
156
160
|
*/
|
|
157
161
|
private _ensureDevicePermission;
|
|
158
162
|
/**
|
package/dist/index.js
CHANGED
|
@@ -279,7 +279,6 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
279
279
|
constructor(connector, options) {
|
|
280
280
|
this.vendor = "ledger";
|
|
281
281
|
this.emitter = new import_hwk_adapter_core2.TypedEventEmitter();
|
|
282
|
-
this._uiHandler = null;
|
|
283
282
|
// Device cache: tracks discovered devices from connector events
|
|
284
283
|
this._discoveredDevices = /* @__PURE__ */ new Map();
|
|
285
284
|
// Session tracking: maps connectId -> sessionId
|
|
@@ -345,12 +344,6 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
345
344
|
async switchTransport(_type) {
|
|
346
345
|
}
|
|
347
346
|
// ---------------------------------------------------------------------------
|
|
348
|
-
// UI handler
|
|
349
|
-
// ---------------------------------------------------------------------------
|
|
350
|
-
setUiHandler(handler) {
|
|
351
|
-
this._uiHandler = handler;
|
|
352
|
-
}
|
|
353
|
-
// ---------------------------------------------------------------------------
|
|
354
347
|
// Lifecycle
|
|
355
348
|
// ---------------------------------------------------------------------------
|
|
356
349
|
async init(_config) {
|
|
@@ -372,7 +365,6 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
372
365
|
this._jobQueue.clear();
|
|
373
366
|
this.unregisterEventListeners();
|
|
374
367
|
this.connector.reset();
|
|
375
|
-
this._uiHandler = null;
|
|
376
368
|
this._discoveredDevices.clear();
|
|
377
369
|
this._sessions.clear();
|
|
378
370
|
this.emitter.removeAllListeners();
|
|
@@ -918,33 +910,32 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
918
910
|
return _LedgerAdapter._abortable(signal, this.connector.call(retrySessionId, method, params));
|
|
919
911
|
}
|
|
920
912
|
/**
|
|
921
|
-
* Ensure device permission before proceeding.
|
|
922
|
-
*
|
|
923
|
-
*
|
|
924
|
-
*
|
|
913
|
+
* Ensure OS-level device permission (Bluetooth / USB) before proceeding.
|
|
914
|
+
*
|
|
915
|
+
* Emits `REQUEST_DEVICE_PERMISSION` and awaits the consumer's
|
|
916
|
+
* `RECEIVE_DEVICE_PERMISSION` reply (60s budget covers "probe → system
|
|
917
|
+
* prompt → user tap" plus a generous margin). If the consumer never wires
|
|
918
|
+
* a handler or never replies, the wait times out and the operation fails
|
|
919
|
+
* fast so scanners/callers don't hang silently.
|
|
920
|
+
*
|
|
921
|
+
* - No connectId (searchDevices): environment-level permission
|
|
922
|
+
* - With connectId (business methods): device-level permission
|
|
925
923
|
*/
|
|
926
924
|
async _ensureDevicePermission(connectId, deviceId) {
|
|
927
925
|
const transportType = this.activeTransport ?? "hid";
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
granted = result.granted;
|
|
938
|
-
context = result.context;
|
|
939
|
-
} catch {
|
|
940
|
-
granted = false;
|
|
941
|
-
}
|
|
942
|
-
}
|
|
926
|
+
const waitPromise = this._uiRegistry.wait(
|
|
927
|
+
import_hwk_adapter_core2.UI_REQUEST.REQUEST_DEVICE_PERMISSION,
|
|
928
|
+
{ timeoutMs: 6e4 }
|
|
929
|
+
);
|
|
930
|
+
this.emitter.emit(import_hwk_adapter_core2.UI_REQUEST.REQUEST_DEVICE_PERMISSION, {
|
|
931
|
+
type: import_hwk_adapter_core2.UI_REQUEST.REQUEST_DEVICE_PERMISSION,
|
|
932
|
+
payload: { transportType, connectId, deviceId }
|
|
933
|
+
});
|
|
934
|
+
const { granted } = await waitPromise;
|
|
943
935
|
if (!granted) {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
}
|
|
947
|
-
}
|
|
936
|
+
throw Object.assign(new Error("Device permission denied"), {
|
|
937
|
+
code: import_hwk_adapter_core2.HardwareErrorCode.DevicePermissionDenied
|
|
938
|
+
});
|
|
948
939
|
}
|
|
949
940
|
}
|
|
950
941
|
/**
|
|
@@ -2149,6 +2140,7 @@ var DmkTransport = class extends import_hw_transport.default {
|
|
|
2149
2140
|
// src/connector/chains/tron.ts
|
|
2150
2141
|
async function tronGetAddress(ctx, sessionId, params) {
|
|
2151
2142
|
const path = normalizePath(params.path);
|
|
2143
|
+
await _ensureTronAppOpen(ctx, sessionId);
|
|
2152
2144
|
return withLegacyAppRetry(ctx, sessionId, "Tron", async (sid) => {
|
|
2153
2145
|
const trx = await _createTrx(ctx, sid);
|
|
2154
2146
|
if (params.showOnDevice) {
|
|
@@ -2173,6 +2165,7 @@ async function tronSignTransaction(ctx, sessionId, params) {
|
|
|
2173
2165
|
);
|
|
2174
2166
|
}
|
|
2175
2167
|
const path = normalizePath(params.path);
|
|
2168
|
+
await _ensureTronAppOpen(ctx, sessionId);
|
|
2176
2169
|
return withLegacyAppRetry(ctx, sessionId, "Tron", async (sid) => {
|
|
2177
2170
|
const trx = await _createTrx(ctx, sid);
|
|
2178
2171
|
ctx.emit("ui-event", {
|
|
@@ -2193,6 +2186,7 @@ async function tronSignTransaction(ctx, sessionId, params) {
|
|
|
2193
2186
|
}
|
|
2194
2187
|
async function tronSignMessage(ctx, sessionId, params) {
|
|
2195
2188
|
const path = normalizePath(params.path);
|
|
2189
|
+
await _ensureTronAppOpen(ctx, sessionId);
|
|
2196
2190
|
return withLegacyAppRetry(ctx, sessionId, "Tron", async (sid) => {
|
|
2197
2191
|
const trx = await _createTrx(ctx, sid);
|
|
2198
2192
|
ctx.emit("ui-event", {
|
|
@@ -2211,6 +2205,16 @@ async function _createTrx(ctx, sessionId) {
|
|
|
2211
2205
|
const dmk = await ctx.getOrCreateDmk();
|
|
2212
2206
|
return new import_hw_app_trx.default(new DmkTransport(dmk, sessionId));
|
|
2213
2207
|
}
|
|
2208
|
+
async function _ensureTronAppOpen(ctx, sessionId) {
|
|
2209
|
+
const dmk = await ctx.getOrCreateDmk();
|
|
2210
|
+
const appManager = new AppManager(dmk);
|
|
2211
|
+
await appManager.ensureAppOpen(sessionId, "Tron", () => {
|
|
2212
|
+
ctx.emit("ui-event", {
|
|
2213
|
+
type: import_hwk_adapter_core10.EConnectorInteraction.ConfirmOpenApp,
|
|
2214
|
+
payload: { sessionId }
|
|
2215
|
+
});
|
|
2216
|
+
});
|
|
2217
|
+
}
|
|
2214
2218
|
|
|
2215
2219
|
// src/connector/LedgerConnectorBase.ts
|
|
2216
2220
|
async function defaultLedgerKitImporter(pkg) {
|