@onekeyfe/hd-transport-electron 1.1.27-alpha.34 → 1.1.27-alpha.4
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.
|
@@ -32,7 +32,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
32
32
|
|
|
33
33
|
function initNobleBleSupport(webContents) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-
|
|
35
|
+
const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-2e41f27c.js'); });
|
|
36
36
|
setupNobleBleHandlers(webContents);
|
|
37
37
|
});
|
|
38
38
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-de36348d.js');
|
|
4
4
|
var hdShared = require('@onekeyfe/hd-shared');
|
|
5
5
|
var hdTransport = require('@onekeyfe/hd-transport');
|
|
6
6
|
var pRetry = require('p-retry');
|
|
@@ -81,8 +81,8 @@ const ONEKEY_SERVICE_UUIDS = [hdShared.ONEKEY_SERVICE_UUID];
|
|
|
81
81
|
const NORMALIZED_WRITE_UUID = '0002';
|
|
82
82
|
const NORMALIZED_NOTIFY_UUID = '0003';
|
|
83
83
|
const BLUETOOTH_INIT_TIMEOUT = 10000;
|
|
84
|
-
const DEVICE_SCAN_TIMEOUT =
|
|
85
|
-
const FAST_SCAN_TIMEOUT =
|
|
84
|
+
const DEVICE_SCAN_TIMEOUT = 5000;
|
|
85
|
+
const FAST_SCAN_TIMEOUT = 1500;
|
|
86
86
|
const DEVICE_CHECK_INTERVAL = 500;
|
|
87
87
|
const CONNECTION_TIMEOUT = 3000;
|
|
88
88
|
const SERVICE_DISCOVERY_TIMEOUT = 10000;
|
|
@@ -506,10 +506,8 @@ function transmitHexDataToDevice(deviceId, hexData) {
|
|
|
506
506
|
});
|
|
507
507
|
}
|
|
508
508
|
function handleDeviceDiscovered(peripheral) {
|
|
509
|
-
var _a
|
|
509
|
+
var _a;
|
|
510
510
|
const deviceName = ((_a = peripheral.advertisement) === null || _a === void 0 ? void 0 : _a.localName) || 'Unknown Device';
|
|
511
|
-
const serviceUuids = ((_b = peripheral.advertisement) === null || _b === void 0 ? void 0 : _b.serviceUuids) || [];
|
|
512
|
-
logger === null || logger === void 0 ? void 0 : logger.info(`[NobleBLE] Scan found: name="${deviceName}" id=${peripheral.id} serviceUUIDs=[${serviceUuids.join(', ')}]`);
|
|
513
511
|
if (!hdShared.isOnekeyDevice(deviceName)) {
|
|
514
512
|
return;
|
|
515
513
|
}
|
|
@@ -559,7 +557,7 @@ function performTargetedScan(targetDeviceId) {
|
|
|
559
557
|
resolve(null);
|
|
560
558
|
}, FAST_SCAN_TIMEOUT);
|
|
561
559
|
nobleInstance.on('discover', onDiscover);
|
|
562
|
-
nobleInstance.startScanning(
|
|
560
|
+
nobleInstance.startScanning(ONEKEY_SERVICE_UUIDS, false, (error) => {
|
|
563
561
|
if (error) {
|
|
564
562
|
clearTimeout(timeoutId);
|
|
565
563
|
nobleInstance.removeListener('discover', onDiscover);
|
|
@@ -609,13 +607,11 @@ function enumerateDevices() {
|
|
|
609
607
|
});
|
|
610
608
|
};
|
|
611
609
|
const timeoutId = setTimeout(() => {
|
|
612
|
-
checkDevices();
|
|
613
610
|
cleanup();
|
|
614
611
|
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Scan completed, found devices:', devices.length);
|
|
615
612
|
resolve(devices);
|
|
616
613
|
}, DEVICE_SCAN_TIMEOUT);
|
|
617
|
-
|
|
618
|
-
nobleInstance.startScanning([], false, (error) => {
|
|
614
|
+
nobleInstance.startScanning(ONEKEY_SERVICE_UUIDS, false, (error) => {
|
|
619
615
|
if (error) {
|
|
620
616
|
cleanup();
|
|
621
617
|
logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Failed to start scanning:', error);
|
|
@@ -710,7 +706,7 @@ function discoverServicesAndCharacteristics(peripheral) {
|
|
|
710
706
|
});
|
|
711
707
|
const discoveryPromise = (() => index.__awaiter(this, void 0, void 0, function* () {
|
|
712
708
|
const services = yield new Promise((resolve, reject) => {
|
|
713
|
-
peripheral.discoverServices(
|
|
709
|
+
peripheral.discoverServices(ONEKEY_SERVICE_UUIDS, (error, svc) => {
|
|
714
710
|
if (error) {
|
|
715
711
|
logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Service discovery failed:', error);
|
|
716
712
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound, error.message));
|
|
@@ -720,21 +716,13 @@ function discoverServicesAndCharacteristics(peripheral) {
|
|
|
720
716
|
}
|
|
721
717
|
});
|
|
722
718
|
});
|
|
723
|
-
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] All services:', services === null || services === void 0 ? void 0 : services.map(s => s.uuid));
|
|
724
719
|
if (!services || services.length === 0) {
|
|
725
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound, 'No services found');
|
|
726
|
-
}
|
|
727
|
-
let service = services.find(s => ONEKEY_SERVICE_UUIDS.includes(s.uuid));
|
|
728
|
-
if (!service) {
|
|
729
|
-
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Known OneKey service UUID not found, trying first non-generic service');
|
|
730
|
-
service = services.find(s => !['1800', '1801', '180a'].includes(s.uuid)) || services[0];
|
|
731
|
-
}
|
|
732
|
-
if (!service) {
|
|
733
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound);
|
|
720
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound, 'No OneKey services found');
|
|
734
721
|
}
|
|
735
|
-
|
|
722
|
+
const service = services[0];
|
|
723
|
+
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Found service:', service.uuid);
|
|
736
724
|
const characteristics = yield new Promise((resolve, reject) => {
|
|
737
|
-
service.discoverCharacteristics([], (error, chars) => {
|
|
725
|
+
service.discoverCharacteristics([hdShared.ONEKEY_WRITE_CHARACTERISTIC_UUID, hdShared.ONEKEY_NOTIFY_CHARACTERISTIC_UUID], (error, chars) => {
|
|
738
726
|
if (error) {
|
|
739
727
|
logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Characteristic discovery failed:', error);
|
|
740
728
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotFound, error.message));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAsB,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAsB,WAAW,EAAE,MAAM,UAAU,CAAC;AAshDhE,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAsKpE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-electron",
|
|
3
|
-
"version": "1.1.27-alpha.
|
|
3
|
+
"version": "1.1.27-alpha.4",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"electron-log": ">=4.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-core": "1.1.27-alpha.
|
|
29
|
-
"@onekeyfe/hd-shared": "1.1.27-alpha.
|
|
30
|
-
"@onekeyfe/hd-transport": "1.1.27-alpha.
|
|
28
|
+
"@onekeyfe/hd-core": "1.1.27-alpha.4",
|
|
29
|
+
"@onekeyfe/hd-shared": "1.1.27-alpha.4",
|
|
30
|
+
"@onekeyfe/hd-transport": "1.1.27-alpha.4",
|
|
31
31
|
"@stoprocent/noble": "2.3.16",
|
|
32
32
|
"p-retry": "^4.6.2"
|
|
33
33
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"electron": "^25.0.0",
|
|
37
37
|
"typescript": "^5.3.3"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "93d0e7734f8c3a6380be10f74de203f0ba785bb8"
|
|
40
40
|
}
|
package/src/noble-ble-handler.ts
CHANGED
|
@@ -79,8 +79,8 @@ const NORMALIZED_NOTIFY_UUID = '0003';
|
|
|
79
79
|
|
|
80
80
|
// Timeout and interval constants
|
|
81
81
|
const BLUETOOTH_INIT_TIMEOUT = 10000; // 10 seconds for Bluetooth initialization
|
|
82
|
-
const DEVICE_SCAN_TIMEOUT =
|
|
83
|
-
const FAST_SCAN_TIMEOUT =
|
|
82
|
+
const DEVICE_SCAN_TIMEOUT = 5000; // 5 seconds for device scanning
|
|
83
|
+
const FAST_SCAN_TIMEOUT = 1500; // 1.5 seconds for fast targeted scanning
|
|
84
84
|
const DEVICE_CHECK_INTERVAL = 500; // 500ms interval for periodic device checks
|
|
85
85
|
const CONNECTION_TIMEOUT = 3000; // 3 seconds for device connection
|
|
86
86
|
const SERVICE_DISCOVERY_TIMEOUT = 10000; // 10 seconds for service discovery
|
|
@@ -686,14 +686,6 @@ async function transmitHexDataToDevice(deviceId: string, hexData: string): Promi
|
|
|
686
686
|
// Handle discovered device (for general enumeration only)
|
|
687
687
|
function handleDeviceDiscovered(peripheral: Peripheral): void {
|
|
688
688
|
const deviceName = peripheral.advertisement?.localName || 'Unknown Device';
|
|
689
|
-
const serviceUuids = peripheral.advertisement?.serviceUuids || [];
|
|
690
|
-
|
|
691
|
-
// Log ALL discovered devices to help identify Pro2 BLE service UUID
|
|
692
|
-
logger?.info(
|
|
693
|
-
`[NobleBLE] Scan found: name="${deviceName}" id=${
|
|
694
|
-
peripheral.id
|
|
695
|
-
} serviceUUIDs=[${serviceUuids.join(', ')}]`
|
|
696
|
-
);
|
|
697
689
|
|
|
698
690
|
// Only process OneKey devices for general discovery
|
|
699
691
|
if (!isOnekeyDevice(deviceName)) {
|
|
@@ -761,8 +753,8 @@ async function performTargetedScan(targetDeviceId: string): Promise<Peripheral |
|
|
|
761
753
|
// Add local listener for this scan
|
|
762
754
|
nobleInstance.on('discover', onDiscover);
|
|
763
755
|
|
|
764
|
-
// Start scanning
|
|
765
|
-
nobleInstance.startScanning(
|
|
756
|
+
// Start scanning
|
|
757
|
+
nobleInstance.startScanning(ONEKEY_SERVICE_UUIDS, false, (error?: Error) => {
|
|
766
758
|
if (error) {
|
|
767
759
|
clearTimeout(timeoutId);
|
|
768
760
|
nobleInstance.removeListener('discover', onDiscover);
|
|
@@ -824,19 +816,15 @@ async function enumerateDevices(): Promise<DeviceInfo[]> {
|
|
|
824
816
|
});
|
|
825
817
|
};
|
|
826
818
|
|
|
827
|
-
// Set timeout for scanning
|
|
819
|
+
// Set timeout for scanning
|
|
828
820
|
const timeoutId = setTimeout(() => {
|
|
829
|
-
// Final collection before resolving — catches devices discovered near the deadline
|
|
830
|
-
checkDevices();
|
|
831
821
|
cleanup();
|
|
832
822
|
logger?.info('[NobleBLE] Scan completed, found devices:', devices.length);
|
|
833
823
|
resolve(devices);
|
|
834
824
|
}, DEVICE_SCAN_TIMEOUT);
|
|
835
825
|
|
|
836
|
-
// Start scanning
|
|
837
|
-
|
|
838
|
-
logger?.info('[NobleBLE] Scanning for ALL BLE devices (no service UUID filter)');
|
|
839
|
-
nobleInstance.startScanning([], false, (error?: Error) => {
|
|
826
|
+
// Start scanning for OneKey service UUIDs
|
|
827
|
+
nobleInstance.startScanning(ONEKEY_SERVICE_UUIDS, false, (error?: Error) => {
|
|
840
828
|
if (error) {
|
|
841
829
|
cleanup();
|
|
842
830
|
logger?.error('[NobleBLE] Failed to start scanning:', error);
|
|
@@ -964,9 +952,9 @@ async function discoverServicesAndCharacteristics(
|
|
|
964
952
|
|
|
965
953
|
// Main discovery logic as async function
|
|
966
954
|
const discoveryPromise = (async (): Promise<CharacteristicPair> => {
|
|
967
|
-
// Step 1: Discover
|
|
955
|
+
// Step 1: Discover services (promisified)
|
|
968
956
|
const services = await new Promise<Service[]>((resolve, reject) => {
|
|
969
|
-
peripheral.discoverServices(
|
|
957
|
+
peripheral.discoverServices(ONEKEY_SERVICE_UUIDS, (error, svc) => {
|
|
970
958
|
if (error) {
|
|
971
959
|
logger?.error('[NobleBLE] Service discovery failed:', error);
|
|
972
960
|
reject(ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound, error.message));
|
|
@@ -976,40 +964,26 @@ async function discoverServicesAndCharacteristics(
|
|
|
976
964
|
});
|
|
977
965
|
});
|
|
978
966
|
|
|
979
|
-
// Log all discovered services
|
|
980
|
-
logger?.info(
|
|
981
|
-
'[NobleBLE] All services:',
|
|
982
|
-
services?.map(s => s.uuid)
|
|
983
|
-
);
|
|
984
|
-
|
|
985
967
|
if (!services || services.length === 0) {
|
|
986
|
-
throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound, 'No services found');
|
|
968
|
+
throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound, 'No OneKey services found');
|
|
987
969
|
}
|
|
988
970
|
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
if (!service) {
|
|
992
|
-
logger?.info(
|
|
993
|
-
'[NobleBLE] Known OneKey service UUID not found, trying first non-generic service'
|
|
994
|
-
);
|
|
995
|
-
// Skip generic BLE services (1800=GAP, 1801=GATT, 180a=DeviceInfo)
|
|
996
|
-
service = services.find(s => !['1800', '1801', '180a'].includes(s.uuid)) || services[0];
|
|
997
|
-
}
|
|
998
|
-
if (!service) {
|
|
999
|
-
throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound);
|
|
1000
|
-
}
|
|
1001
|
-
logger?.info('[NobleBLE] Using service:', service.uuid);
|
|
971
|
+
const service = services[0];
|
|
972
|
+
logger?.info('[NobleBLE] Found service:', service.uuid);
|
|
1002
973
|
|
|
1003
|
-
// Step 2: Discover
|
|
974
|
+
// Step 2: Discover characteristics (promisified)
|
|
1004
975
|
const characteristics = await new Promise<Characteristic[]>((resolve, reject) => {
|
|
1005
|
-
service.discoverCharacteristics(
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
976
|
+
service.discoverCharacteristics(
|
|
977
|
+
[ONEKEY_WRITE_CHARACTERISTIC_UUID, ONEKEY_NOTIFY_CHARACTERISTIC_UUID],
|
|
978
|
+
(error, chars) => {
|
|
979
|
+
if (error) {
|
|
980
|
+
logger?.error('[NobleBLE] Characteristic discovery failed:', error);
|
|
981
|
+
reject(ERRORS.TypedError(HardwareErrorCode.BleCharacteristicNotFound, error.message));
|
|
982
|
+
} else {
|
|
983
|
+
resolve(chars);
|
|
984
|
+
}
|
|
1011
985
|
}
|
|
1012
|
-
|
|
986
|
+
);
|
|
1013
987
|
});
|
|
1014
988
|
|
|
1015
989
|
// Step 3: Find required characteristics
|