@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.13 → 1.1.26-alpha.14
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 +29 -21
- package/dist/index.d.ts +29 -21
- package/dist/index.js +108 -143
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -141
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -39,13 +39,12 @@ __export(index_exports, {
|
|
|
39
39
|
SignerEth: () => SignerEth,
|
|
40
40
|
SignerManager: () => SignerManager,
|
|
41
41
|
SignerSol: () => SignerSol,
|
|
42
|
+
debugLog: () => debugLog,
|
|
42
43
|
deviceActionToPromise: () => deviceActionToPromise,
|
|
43
|
-
extractBleHexId: () => extractBleHexId,
|
|
44
44
|
isDeviceLockedError: () => isDeviceLockedError,
|
|
45
45
|
isLedgerBleConnectionType: () => isLedgerBleConnectionType,
|
|
46
46
|
isLedgerBleDescriptor: () => isLedgerBleDescriptor,
|
|
47
47
|
isLedgerDmkBleTransport: () => isLedgerDmkBleTransport,
|
|
48
|
-
isValidLedgerBleConnectId: () => isValidLedgerBleConnectId,
|
|
49
48
|
ledgerFailure: () => ledgerFailure,
|
|
50
49
|
mapLedgerError: () => mapLedgerError,
|
|
51
50
|
offSdkEvent: () => offSdkEvent,
|
|
@@ -160,6 +159,8 @@ var ERROR_TAG = {
|
|
|
160
159
|
// SDK-mint
|
|
161
160
|
DeviceNotAdvertising: "DeviceNotAdvertisingError",
|
|
162
161
|
// BLE scan miss
|
|
162
|
+
DeviceNotInDiscoveryCache: "DeviceNotInDiscoveryCacheError",
|
|
163
|
+
// dm.connect() before enumerate
|
|
163
164
|
BlePairingTimeout: "BlePairingTimeoutError",
|
|
164
165
|
// SMP 30s timeout
|
|
165
166
|
BleGattBondingFailed: "BleGattBondingFailedError",
|
|
@@ -425,9 +426,6 @@ function isLedgerBleConnectionType(connectionType) {
|
|
|
425
426
|
function isLedgerBleDescriptor(connectionType, descriptor) {
|
|
426
427
|
return isLedgerBleConnectionType(connectionType) || isLedgerDmkBleTransport(descriptor.transport);
|
|
427
428
|
}
|
|
428
|
-
function isValidLedgerBleConnectId(connectId) {
|
|
429
|
-
return /^[0-9A-Fa-f]{4}$/.test(connectId ?? "");
|
|
430
|
-
}
|
|
431
429
|
|
|
432
430
|
// src/utils/sdkEventBus.ts
|
|
433
431
|
var listeners = /* @__PURE__ */ new Set();
|
|
@@ -588,21 +586,16 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
588
586
|
// ---------------------------------------------------------------------------
|
|
589
587
|
// Device management
|
|
590
588
|
// ---------------------------------------------------------------------------
|
|
591
|
-
async searchDevices() {
|
|
589
|
+
async searchDevices(options) {
|
|
590
|
+
if (options?.resetSession) {
|
|
591
|
+
this._doConnectAbortController?.abort();
|
|
592
|
+
this._sessions.clear();
|
|
593
|
+
this._connectingPromise = null;
|
|
594
|
+
this._doConnectAbortController = null;
|
|
595
|
+
this._btcHighIndexConfirmedThisSession = false;
|
|
596
|
+
}
|
|
592
597
|
await this._ensureDevicePermission();
|
|
593
|
-
debugLog(`[LedgerAdapter] searchDevices() entry, cacheBefore=${this._discoveredDevices.size}`);
|
|
594
598
|
const devices = await this.connector.searchDevices();
|
|
595
|
-
debugLog(
|
|
596
|
-
"[DMK] adapter.searchDevices raw:",
|
|
597
|
-
devices.map((device) => ({
|
|
598
|
-
id: device?.deviceId,
|
|
599
|
-
deviceId: device?.deviceId,
|
|
600
|
-
connectId: device?.connectId,
|
|
601
|
-
deviceName: device?.name,
|
|
602
|
-
"device.name": device?.name,
|
|
603
|
-
model: device?.model
|
|
604
|
-
}))
|
|
605
|
-
);
|
|
606
599
|
this._discoveredDevices.clear();
|
|
607
600
|
for (const d of devices) {
|
|
608
601
|
if (d.connectId) {
|
|
@@ -632,16 +625,6 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
632
625
|
});
|
|
633
626
|
}
|
|
634
627
|
await this._ensureDevicePermission(connectId);
|
|
635
|
-
if (isLedgerBleConnectionType(this.connector.connectionType)) {
|
|
636
|
-
const fresh = (await this.searchDevices()).some((d) => d.connectId === connectId);
|
|
637
|
-
if (!fresh) {
|
|
638
|
-
const err = new Error(
|
|
639
|
-
"Ledger device is not currently advertising. Wake up and unlock the device, keep it nearby, then try again."
|
|
640
|
-
);
|
|
641
|
-
err._tag = ERROR_TAG.DeviceNotAdvertising;
|
|
642
|
-
throw err;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
628
|
const session = await this.connector.connect(connectId);
|
|
646
629
|
this._sessions.set(connectId, session.sessionId);
|
|
647
630
|
if (session.deviceInfo) {
|
|
@@ -791,21 +774,11 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
791
774
|
// Chain fingerprint
|
|
792
775
|
// ---------------------------------------------------------------------------
|
|
793
776
|
async getChainFingerprint(connectId, deviceId, chain) {
|
|
794
|
-
debugLog(
|
|
795
|
-
"[LedgerAdapter] getChainFingerprint called, chain:",
|
|
796
|
-
chain,
|
|
797
|
-
"connectId:",
|
|
798
|
-
connectId || "(empty)",
|
|
799
|
-
"sessions:",
|
|
800
|
-
this._sessions.size
|
|
801
|
-
);
|
|
802
|
-
debugLog("[LedgerAdapter] getChainFingerprint permission ok, computing fingerprint");
|
|
803
777
|
try {
|
|
804
778
|
const fingerprint = await this._computeChainFingerprint(
|
|
805
779
|
chain,
|
|
806
780
|
(method, params) => this.connectorCall(connectId, method, params, void 0, deviceId)
|
|
807
781
|
);
|
|
808
|
-
debugLog("[LedgerAdapter] getChainFingerprint result:", fingerprint?.substring(0, 20));
|
|
809
782
|
return (0, import_hwk_adapter_core2.success)(fingerprint);
|
|
810
783
|
} catch (err) {
|
|
811
784
|
debugError("[LedgerAdapter] getChainFingerprint error:", chain, err);
|
|
@@ -999,6 +972,22 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
999
972
|
// Bounded by MAX_DOCONNECT_CONFIRMS — after N Confirms with no progress,
|
|
1000
973
|
// throw DeviceNotFound so the user is kicked out of the loop.
|
|
1001
974
|
async _doConnect(internalSignal, targetConnectId) {
|
|
975
|
+
if (isLedgerBleConnectionType(this.connector.connectionType) && targetConnectId) {
|
|
976
|
+
try {
|
|
977
|
+
return await this._connectDeviceOrThrow(targetConnectId);
|
|
978
|
+
} catch (err) {
|
|
979
|
+
if (!isDeviceLockedError(err) && !isDeviceNotAdvertisingError(err) && !isDeviceDisconnectedError(err)) {
|
|
980
|
+
throw err;
|
|
981
|
+
}
|
|
982
|
+
this._discoveredDevices.delete(targetConnectId);
|
|
983
|
+
if (isDeviceDisconnectedError(err)) {
|
|
984
|
+
try {
|
|
985
|
+
this.connector.reset?.();
|
|
986
|
+
} catch {
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
1002
991
|
let confirms = 0;
|
|
1003
992
|
while (!internalSignal.aborted) {
|
|
1004
993
|
this.emitter.emit("ui-event", {
|
|
@@ -1051,9 +1040,13 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1051
1040
|
(d) => d.connectId === targetConnectId || d.deviceId === targetConnectId
|
|
1052
1041
|
);
|
|
1053
1042
|
if (!target) {
|
|
1054
|
-
|
|
1043
|
+
const err = Object.assign(new Error(`Target Ledger unavailable: ${targetConnectId}`), {
|
|
1055
1044
|
code: import_hwk_adapter_core2.HardwareErrorCode.DeviceNotFound
|
|
1056
1045
|
});
|
|
1046
|
+
if (isLedgerBleConnectionType(this.connector.connectionType)) {
|
|
1047
|
+
err._tag = ERROR_TAG.DeviceNotAdvertising;
|
|
1048
|
+
}
|
|
1049
|
+
throw err;
|
|
1057
1050
|
}
|
|
1058
1051
|
return this._connectDeviceOrThrow(target.connectId);
|
|
1059
1052
|
}
|
|
@@ -1194,14 +1187,6 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1194
1187
|
}
|
|
1195
1188
|
const resolvedConnectId = await this.ensureConnected(connectId, signal);
|
|
1196
1189
|
const sessionId = this._sessions.get(resolvedConnectId);
|
|
1197
|
-
debugLog(
|
|
1198
|
-
"[LedgerAdapter] connectorCall resolved:",
|
|
1199
|
-
method,
|
|
1200
|
-
"resolvedConnectId:",
|
|
1201
|
-
resolvedConnectId,
|
|
1202
|
-
"sessionId:",
|
|
1203
|
-
sessionId
|
|
1204
|
-
);
|
|
1205
1190
|
if (!sessionId) {
|
|
1206
1191
|
throw Object.assign(new Error("Auto-connect succeeded but no session found"), {
|
|
1207
1192
|
_tag: ERROR_TAG.DeviceSessionNotFound
|
|
@@ -1559,15 +1544,18 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1559
1544
|
// Device info mapping
|
|
1560
1545
|
// ---------------------------------------------------------------------------
|
|
1561
1546
|
connectorDeviceToDeviceInfo(device) {
|
|
1562
|
-
const isBle = device.connectId && /^[0-9A-Fa-f]{4}$/.test(device.connectId);
|
|
1563
1547
|
return {
|
|
1564
1548
|
vendor: "ledger",
|
|
1565
1549
|
model: device.model ?? "unknown",
|
|
1550
|
+
modelName: device.modelName,
|
|
1566
1551
|
firmwareVersion: "",
|
|
1567
1552
|
deviceId: device.deviceId,
|
|
1568
1553
|
connectId: device.connectId,
|
|
1569
1554
|
label: device.name,
|
|
1570
|
-
connectionType:
|
|
1555
|
+
connectionType: this.connector.connectionType,
|
|
1556
|
+
rssi: device.rssi,
|
|
1557
|
+
isConnectable: device.isConnectable,
|
|
1558
|
+
serialNumber: device.serialNumber,
|
|
1571
1559
|
capabilities: device.capabilities
|
|
1572
1560
|
};
|
|
1573
1561
|
}
|
|
@@ -1625,7 +1613,7 @@ var LedgerDeviceManager = class {
|
|
|
1625
1613
|
resolved = true;
|
|
1626
1614
|
this._discovered.clear();
|
|
1627
1615
|
debugLog(
|
|
1628
|
-
`[DMK] enumerate
|
|
1616
|
+
`[DMK] enumerate count=${devices.length} ids=[${devices.map((d) => d.id).join(",")}]`
|
|
1629
1617
|
);
|
|
1630
1618
|
for (const d of devices) {
|
|
1631
1619
|
this._discovered.set(d.id, d);
|
|
@@ -1636,6 +1624,7 @@ var LedgerDeviceManager = class {
|
|
|
1636
1624
|
devices.map((d) => ({
|
|
1637
1625
|
path: d.id,
|
|
1638
1626
|
type: d.deviceModel.model,
|
|
1627
|
+
modelName: d.deviceModel.name,
|
|
1639
1628
|
name: d.name,
|
|
1640
1629
|
transport: d.transport,
|
|
1641
1630
|
rssi: d.rssi
|
|
@@ -1659,6 +1648,7 @@ var LedgerDeviceManager = class {
|
|
|
1659
1648
|
devices.map((d) => ({
|
|
1660
1649
|
path: d.id,
|
|
1661
1650
|
type: d.deviceModel.model,
|
|
1651
|
+
modelName: d.deviceModel.name,
|
|
1662
1652
|
name: d.name,
|
|
1663
1653
|
transport: d.transport,
|
|
1664
1654
|
rssi: d.rssi
|
|
@@ -1685,6 +1675,7 @@ var LedgerDeviceManager = class {
|
|
|
1685
1675
|
descriptor: {
|
|
1686
1676
|
path: d.id,
|
|
1687
1677
|
type: d.deviceModel.model,
|
|
1678
|
+
modelName: d.deviceModel.name,
|
|
1688
1679
|
name: d.name,
|
|
1689
1680
|
transport: d.transport,
|
|
1690
1681
|
rssi: d.rssi
|
|
@@ -1775,11 +1766,29 @@ var LedgerDeviceManager = class {
|
|
|
1775
1766
|
getDeviceName(deviceId) {
|
|
1776
1767
|
return this._discovered.get(deviceId)?.name;
|
|
1777
1768
|
}
|
|
1769
|
+
/** Lookup minimal model/signal info from a previously-discovered device. */
|
|
1770
|
+
getDiscoveredDeviceInfo(deviceId) {
|
|
1771
|
+
const d = this._discovered.get(deviceId);
|
|
1772
|
+
if (!d) return void 0;
|
|
1773
|
+
return {
|
|
1774
|
+
model: d.deviceModel?.model,
|
|
1775
|
+
modelName: d.deviceModel?.name,
|
|
1776
|
+
name: d.name,
|
|
1777
|
+
rssi: d.rssi
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
hasDiscoveredDevice(deviceId) {
|
|
1781
|
+
return this._discovered.has(deviceId);
|
|
1782
|
+
}
|
|
1778
1783
|
/** Connect to a previously discovered device. Returns sessionId. */
|
|
1779
1784
|
async connect(deviceId) {
|
|
1780
1785
|
const device = this._discovered.get(deviceId);
|
|
1781
1786
|
if (!device) {
|
|
1782
|
-
|
|
1787
|
+
const err = new Error(
|
|
1788
|
+
`Device "${deviceId}" not found in discovery cache. Call enumerate() or listen() first.`
|
|
1789
|
+
);
|
|
1790
|
+
err._tag = ERROR_TAG.DeviceNotInDiscoveryCache;
|
|
1791
|
+
throw err;
|
|
1783
1792
|
}
|
|
1784
1793
|
const sessionId = await this._dmk.connect({ device });
|
|
1785
1794
|
this._sessions.set(deviceId, sessionId);
|
|
@@ -2981,6 +2990,7 @@ var METHOD_PREFIX_TO_APP_NAME = {
|
|
|
2981
2990
|
var HARDWARE_ERROR_CODE_VALUES = new Set(
|
|
2982
2991
|
Object.values(import_hwk_adapter_core12.HardwareErrorCode).filter((value) => typeof value === "number")
|
|
2983
2992
|
);
|
|
2993
|
+
var BLE_CONNECT_SCAN_TIMEOUT_MS = 1500;
|
|
2984
2994
|
async function defaultLedgerKitImporter(pkg) {
|
|
2985
2995
|
switch (pkg) {
|
|
2986
2996
|
case "@ledgerhq/device-management-kit":
|
|
@@ -3004,16 +3014,6 @@ var LedgerConnectorBase = class {
|
|
|
3004
3014
|
this._dmk = null;
|
|
3005
3015
|
this._eventHandlers = /* @__PURE__ */ new Map();
|
|
3006
3016
|
// ---------------------------------------------------------------------------
|
|
3007
|
-
// ConnectId <-> DMK path mapping
|
|
3008
|
-
//
|
|
3009
|
-
// DMK uses internal paths (BLE MAC, USB UUID) that may change across sessions.
|
|
3010
|
-
// _resolveConnectId() maps these to stable external IDs (BLE: "A58F", USB: same).
|
|
3011
|
-
// This bidirectional map is the SINGLE SOURCE OF TRUTH for all connectId usage.
|
|
3012
|
-
// ---------------------------------------------------------------------------
|
|
3013
|
-
this._connectIdToPath = /* @__PURE__ */ new Map();
|
|
3014
|
-
// "A58F" -> "D5:75:7D:4B:51:E8"
|
|
3015
|
-
this._pathToConnectId = /* @__PURE__ */ new Map();
|
|
3016
|
-
// ---------------------------------------------------------------------------
|
|
3017
3017
|
// Per-session DeviceAction cancellers
|
|
3018
3018
|
//
|
|
3019
3019
|
// Each chain handler registers its active DeviceAction's canceller via
|
|
@@ -3038,6 +3038,7 @@ var LedgerConnectorBase = class {
|
|
|
3038
3038
|
this.connectionType = options?.connectionType ?? "usb";
|
|
3039
3039
|
this._providedDmk = options?.dmk;
|
|
3040
3040
|
this._importLedgerKit = options?.importLedgerKit ?? defaultLedgerKitImporter;
|
|
3041
|
+
this._requirePreFlightScan = options?.requirePreFlightScan ?? false;
|
|
3041
3042
|
if (this._providedDmk) {
|
|
3042
3043
|
this._initManagers(this._providedDmk);
|
|
3043
3044
|
}
|
|
@@ -3055,22 +3056,13 @@ var LedgerConnectorBase = class {
|
|
|
3055
3056
|
importLedgerKit: this._importLedgerKit
|
|
3056
3057
|
};
|
|
3057
3058
|
}
|
|
3058
|
-
// "D5:75:7D:4B:51:E8" -> "A58F"
|
|
3059
|
-
/** Get DMK path from external connectId. Falls back to connectId itself. */
|
|
3060
|
-
_getPathForConnectId(connectId) {
|
|
3061
|
-
return this._connectIdToPath.get(connectId) ?? connectId;
|
|
3062
|
-
}
|
|
3063
|
-
/** Get external connectId from DMK path. Falls back to path itself. */
|
|
3064
|
-
_getConnectIdForPath(path) {
|
|
3065
|
-
return this._pathToConnectId.get(path) ?? path;
|
|
3066
|
-
}
|
|
3067
3059
|
// ---------------------------------------------------------------------------
|
|
3068
3060
|
// Protected — hooks for subclasses
|
|
3069
3061
|
// ---------------------------------------------------------------------------
|
|
3070
3062
|
/**
|
|
3071
3063
|
* Resolve the connectId for a discovered device descriptor.
|
|
3072
3064
|
* Default: use the DMK path (ephemeral UUID).
|
|
3073
|
-
* Override in subclasses
|
|
3065
|
+
* Override in subclasses only when the public connectId differs from the transport path.
|
|
3074
3066
|
*/
|
|
3075
3067
|
_resolveConnectId(descriptor) {
|
|
3076
3068
|
return descriptor.path;
|
|
@@ -3095,65 +3087,22 @@ var LedgerConnectorBase = class {
|
|
|
3095
3087
|
// IConnector -- Device discovery
|
|
3096
3088
|
// ---------------------------------------------------------------------------
|
|
3097
3089
|
async searchDevices() {
|
|
3098
|
-
debugLog("[DMK] connector.searchDevices() entry");
|
|
3099
3090
|
const dm = await this._getDeviceManager();
|
|
3100
3091
|
const descriptors = await this._discoverDescriptors(dm);
|
|
3101
3092
|
const resolvedDescriptors = descriptors.map((d) => ({
|
|
3102
3093
|
descriptor: d,
|
|
3103
3094
|
connectId: this._resolveConnectId(d)
|
|
3104
3095
|
}));
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
model: d?.type,
|
|
3116
|
-
transport: d?.transport,
|
|
3117
|
-
rssi: d?.rssi
|
|
3118
|
-
}))
|
|
3119
|
-
);
|
|
3120
|
-
const bleConnectIdCounts = /* @__PURE__ */ new Map();
|
|
3121
|
-
for (const item of resolvedDescriptors) {
|
|
3122
|
-
if (isLedgerBleDescriptor(this.connectionType, item.descriptor)) {
|
|
3123
|
-
if (!isValidLedgerBleConnectId(item.connectId)) {
|
|
3124
|
-
debugLog(`[DMK] connector.searchDevices() invalid BLE connectId=${item.connectId}`);
|
|
3125
|
-
throw Object.assign(
|
|
3126
|
-
new Error("Ledger BLE connectId must be the 4-character BLE identifier"),
|
|
3127
|
-
{ code: import_hwk_adapter_core12.HardwareErrorCode.DeviceNotFound }
|
|
3128
|
-
);
|
|
3129
|
-
}
|
|
3130
|
-
bleConnectIdCounts.set(item.connectId, (bleConnectIdCounts.get(item.connectId) ?? 0) + 1);
|
|
3131
|
-
}
|
|
3132
|
-
}
|
|
3133
|
-
const duplicateBleConnectId = Array.from(bleConnectIdCounts.entries()).find(
|
|
3134
|
-
([, count]) => count > 1
|
|
3135
|
-
)?.[0];
|
|
3136
|
-
if (duplicateBleConnectId) {
|
|
3137
|
-
debugLog(
|
|
3138
|
-
`[DMK] connector.searchDevices() duplicate BLE connectId=${duplicateBleConnectId} counts=${JSON.stringify(
|
|
3139
|
-
Array.from(bleConnectIdCounts.entries())
|
|
3140
|
-
)}`
|
|
3141
|
-
);
|
|
3142
|
-
throw Object.assign(
|
|
3143
|
-
new Error(`Duplicate Ledger BLE connectId detected: ${duplicateBleConnectId}`),
|
|
3144
|
-
{ code: import_hwk_adapter_core12.HardwareErrorCode.DeviceNotFound }
|
|
3145
|
-
);
|
|
3146
|
-
}
|
|
3147
|
-
const result = resolvedDescriptors.map(({ descriptor: d, connectId }) => {
|
|
3148
|
-
this._connectIdToPath.set(connectId, d.path);
|
|
3149
|
-
this._pathToConnectId.set(d.path, connectId);
|
|
3150
|
-
return {
|
|
3151
|
-
connectId,
|
|
3152
|
-
deviceId: d.path,
|
|
3153
|
-
name: d.name || d.type || "Ledger",
|
|
3154
|
-
model: d.type
|
|
3155
|
-
};
|
|
3156
|
-
});
|
|
3096
|
+
const result = resolvedDescriptors.map(({ descriptor: d, connectId }) => ({
|
|
3097
|
+
connectId,
|
|
3098
|
+
deviceId: d.path,
|
|
3099
|
+
name: d.name || d.type || "Ledger",
|
|
3100
|
+
model: d.type,
|
|
3101
|
+
modelName: d.modelName,
|
|
3102
|
+
rssi: d.rssi,
|
|
3103
|
+
isConnectable: d.isConnectable,
|
|
3104
|
+
serialNumber: d.serialNumber
|
|
3105
|
+
}));
|
|
3157
3106
|
debugLog(
|
|
3158
3107
|
`[DMK] connector.searchDevices() return count=${result.length} ids=[${result.map((r) => r.connectId).join(",")}] paths=[${result.map((r) => r.deviceId).join(",")}]`
|
|
3159
3108
|
);
|
|
@@ -3163,7 +3112,8 @@ var LedgerConnectorBase = class {
|
|
|
3163
3112
|
// IConnector -- Connection
|
|
3164
3113
|
// ---------------------------------------------------------------------------
|
|
3165
3114
|
async connect(deviceId) {
|
|
3166
|
-
|
|
3115
|
+
const callerSuppliedConnectId = Boolean(deviceId);
|
|
3116
|
+
let targetPath = deviceId;
|
|
3167
3117
|
if (!targetPath) {
|
|
3168
3118
|
const discovered = await this.searchDevices();
|
|
3169
3119
|
if (discovered.length === 0) {
|
|
@@ -3173,7 +3123,7 @@ var LedgerConnectorBase = class {
|
|
|
3173
3123
|
}
|
|
3174
3124
|
targetPath = discovered[0].deviceId;
|
|
3175
3125
|
}
|
|
3176
|
-
const externalConnectId =
|
|
3126
|
+
const externalConnectId = targetPath;
|
|
3177
3127
|
const HANG_CEILING_MS = 5 * 6e4;
|
|
3178
3128
|
const dmConnectWithObserve = async (dm, path) => {
|
|
3179
3129
|
if (!isLedgerBleConnectionType(this.connectionType)) return dm.connect(path);
|
|
@@ -3214,19 +3164,45 @@ var LedgerConnectorBase = class {
|
|
|
3214
3164
|
if (timeoutId) clearTimeout(timeoutId);
|
|
3215
3165
|
}
|
|
3216
3166
|
};
|
|
3167
|
+
const isBleDirectConnect = isLedgerBleConnectionType(this.connectionType) && callerSuppliedConnectId;
|
|
3168
|
+
const throwNotAdvertising = () => {
|
|
3169
|
+
const err = new Error(
|
|
3170
|
+
"Ledger device is not currently advertising. Wake up and unlock the device, keep it nearby, then try again."
|
|
3171
|
+
);
|
|
3172
|
+
err._tag = ERROR_TAG.DeviceNotAdvertising;
|
|
3173
|
+
err.code = import_hwk_adapter_core12.HardwareErrorCode.DeviceNotFound;
|
|
3174
|
+
throw err;
|
|
3175
|
+
};
|
|
3217
3176
|
const doConnect = async (path) => {
|
|
3218
3177
|
const dm = await this._getDeviceManager();
|
|
3219
|
-
|
|
3178
|
+
if (isBleDirectConnect && !dm.hasDiscoveredDevice(path)) {
|
|
3179
|
+
const live = await dm.getLiveDevices(BLE_CONNECT_SCAN_TIMEOUT_MS);
|
|
3180
|
+
if (this._requirePreFlightScan && !live.some((d) => d.id === path)) {
|
|
3181
|
+
throwNotAdvertising();
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
let sessionId;
|
|
3185
|
+
try {
|
|
3186
|
+
sessionId = await dmConnectWithObserve(dm, path);
|
|
3187
|
+
} catch (err) {
|
|
3188
|
+
if (isBleDirectConnect && err?._tag === ERROR_TAG.DeviceNotInDiscoveryCache) {
|
|
3189
|
+
throwNotAdvertising();
|
|
3190
|
+
}
|
|
3191
|
+
throw err;
|
|
3192
|
+
}
|
|
3220
3193
|
this._watchSessionState(sessionId, externalConnectId);
|
|
3194
|
+
const info = dm.getDiscoveredDeviceInfo(path);
|
|
3221
3195
|
const session = {
|
|
3222
3196
|
sessionId,
|
|
3223
3197
|
deviceInfo: {
|
|
3224
3198
|
vendor: "ledger",
|
|
3225
|
-
model: "unknown",
|
|
3199
|
+
model: info?.model ?? "unknown",
|
|
3200
|
+
modelName: info?.modelName,
|
|
3226
3201
|
firmwareVersion: "unknown",
|
|
3227
3202
|
deviceId: path,
|
|
3228
3203
|
connectId: externalConnectId,
|
|
3229
3204
|
connectionType: this.connectionType,
|
|
3205
|
+
rssi: info?.rssi,
|
|
3230
3206
|
capabilities: { persistentDeviceIdentity: false }
|
|
3231
3207
|
}
|
|
3232
3208
|
};
|
|
@@ -3504,14 +3480,13 @@ var LedgerConnectorBase = class {
|
|
|
3504
3480
|
}
|
|
3505
3481
|
/**
|
|
3506
3482
|
* Replace an old session with a new one after app switch.
|
|
3507
|
-
*
|
|
3508
|
-
* and emits device-connect so the adapter updates its _sessions Map.
|
|
3483
|
+
* Emits device-connect so the adapter updates its _sessions Map.
|
|
3509
3484
|
*/
|
|
3510
3485
|
_replaceSession(oldSessionId, _newSessionId) {
|
|
3511
3486
|
const dm = this._deviceManager;
|
|
3512
3487
|
if (!dm) return;
|
|
3513
3488
|
const oldDeviceId = dm.getDeviceId(oldSessionId);
|
|
3514
|
-
const connectId = oldDeviceId
|
|
3489
|
+
const connectId = oldDeviceId;
|
|
3515
3490
|
this._signerManager?.invalidate(oldSessionId);
|
|
3516
3491
|
if (connectId) {
|
|
3517
3492
|
this._emit("device-connect", {
|
|
@@ -3524,7 +3499,7 @@ var LedgerConnectorBase = class {
|
|
|
3524
3499
|
}
|
|
3525
3500
|
}
|
|
3526
3501
|
/**
|
|
3527
|
-
* Light reset: clear signer/session state but keep DMK
|
|
3502
|
+
* Light reset: clear signer/session state but keep DMK alive.
|
|
3528
3503
|
* Used by connect() retry — we want to re-discover with the same transport.
|
|
3529
3504
|
*
|
|
3530
3505
|
* Note: drops the device manager but tears down its RxJS subs first via
|
|
@@ -3559,8 +3534,6 @@ var LedgerConnectorBase = class {
|
|
|
3559
3534
|
this._deviceManager = null;
|
|
3560
3535
|
this._signerManager = null;
|
|
3561
3536
|
this._dmk = null;
|
|
3562
|
-
this._connectIdToPath.clear();
|
|
3563
|
-
this._pathToConnectId.clear();
|
|
3564
3537
|
}
|
|
3565
3538
|
// ---------------------------------------------------------------------------
|
|
3566
3539
|
// Private -- Events
|
|
@@ -3619,13 +3592,6 @@ var LedgerConnectorBase = class {
|
|
|
3619
3592
|
return error;
|
|
3620
3593
|
}
|
|
3621
3594
|
};
|
|
3622
|
-
|
|
3623
|
-
// src/utils/bleIdentity.ts
|
|
3624
|
-
function extractBleHexId(name) {
|
|
3625
|
-
if (!name) return void 0;
|
|
3626
|
-
const match = name.match(/\b([0-9A-Fa-f]{4})$/);
|
|
3627
|
-
return match ? match[1].toUpperCase() : void 0;
|
|
3628
|
-
}
|
|
3629
3595
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3630
3596
|
0 && (module.exports = {
|
|
3631
3597
|
AppManager,
|
|
@@ -3637,13 +3603,12 @@ function extractBleHexId(name) {
|
|
|
3637
3603
|
SignerEth,
|
|
3638
3604
|
SignerManager,
|
|
3639
3605
|
SignerSol,
|
|
3606
|
+
debugLog,
|
|
3640
3607
|
deviceActionToPromise,
|
|
3641
|
-
extractBleHexId,
|
|
3642
3608
|
isDeviceLockedError,
|
|
3643
3609
|
isLedgerBleConnectionType,
|
|
3644
3610
|
isLedgerBleDescriptor,
|
|
3645
3611
|
isLedgerDmkBleTransport,
|
|
3646
|
-
isValidLedgerBleConnectId,
|
|
3647
3612
|
ledgerFailure,
|
|
3648
3613
|
mapLedgerError,
|
|
3649
3614
|
offSdkEvent,
|