@onekeyfe/hd-transport-electron 1.1.26-alpha.12 → 1.1.26-alpha.30

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-2e41f27c.js'); });
35
+ const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-4f7435c3.js'); });
36
36
  setupNobleBleHandlers(webContents);
37
37
  });
38
38
  }
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-de36348d.js');
5
+ var index = require('./index-b01d011d.js');
6
6
 
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-de36348d.js');
3
+ var index = require('./index-b01d011d.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 = 5000;
85
- const FAST_SCAN_TIMEOUT = 1500;
84
+ const DEVICE_SCAN_TIMEOUT = 8000;
85
+ const FAST_SCAN_TIMEOUT = 8000;
86
86
  const DEVICE_CHECK_INTERVAL = 500;
87
87
  const CONNECTION_TIMEOUT = 3000;
88
88
  const SERVICE_DISCOVERY_TIMEOUT = 10000;
@@ -506,8 +506,10 @@ function transmitHexDataToDevice(deviceId, hexData) {
506
506
  });
507
507
  }
508
508
  function handleDeviceDiscovered(peripheral) {
509
- var _a;
509
+ var _a, _b;
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(', ')}]`);
511
513
  if (!hdShared.isOnekeyDevice(deviceName)) {
512
514
  return;
513
515
  }
@@ -557,7 +559,7 @@ function performTargetedScan(targetDeviceId) {
557
559
  resolve(null);
558
560
  }, FAST_SCAN_TIMEOUT);
559
561
  nobleInstance.on('discover', onDiscover);
560
- nobleInstance.startScanning(ONEKEY_SERVICE_UUIDS, false, (error) => {
562
+ nobleInstance.startScanning([], false, (error) => {
561
563
  if (error) {
562
564
  clearTimeout(timeoutId);
563
565
  nobleInstance.removeListener('discover', onDiscover);
@@ -607,11 +609,13 @@ function enumerateDevices() {
607
609
  });
608
610
  };
609
611
  const timeoutId = setTimeout(() => {
612
+ checkDevices();
610
613
  cleanup();
611
614
  logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Scan completed, found devices:', devices.length);
612
615
  resolve(devices);
613
616
  }, DEVICE_SCAN_TIMEOUT);
614
- nobleInstance.startScanning(ONEKEY_SERVICE_UUIDS, false, (error) => {
617
+ logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Scanning for ALL BLE devices (no service UUID filter)');
618
+ nobleInstance.startScanning([], false, (error) => {
615
619
  if (error) {
616
620
  cleanup();
617
621
  logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Failed to start scanning:', error);
@@ -706,7 +710,7 @@ function discoverServicesAndCharacteristics(peripheral) {
706
710
  });
707
711
  const discoveryPromise = (() => index.__awaiter(this, void 0, void 0, function* () {
708
712
  const services = yield new Promise((resolve, reject) => {
709
- peripheral.discoverServices(ONEKEY_SERVICE_UUIDS, (error, svc) => {
713
+ peripheral.discoverServices([], (error, svc) => {
710
714
  if (error) {
711
715
  logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Service discovery failed:', error);
712
716
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound, error.message));
@@ -716,13 +720,21 @@ function discoverServicesAndCharacteristics(peripheral) {
716
720
  }
717
721
  });
718
722
  });
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));
719
724
  if (!services || services.length === 0) {
720
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound, 'No OneKey services found');
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);
721
734
  }
722
- const service = services[0];
723
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Found service:', service.uuid);
735
+ logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Using service:', service.uuid);
724
736
  const characteristics = yield new Promise((resolve, reject) => {
725
- service.discoverCharacteristics([hdShared.ONEKEY_WRITE_CHARACTERISTIC_UUID, hdShared.ONEKEY_NOTIFY_CHARACTERISTIC_UUID], (error, chars) => {
737
+ service.discoverCharacteristics([], (error, chars) => {
726
738
  if (error) {
727
739
  logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Characteristic discovery failed:', error);
728
740
  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;AAshDhE,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAsKpE"}
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;AAgjDhE,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.26-alpha.12",
3
+ "version": "1.1.26-alpha.30",
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.26-alpha.12",
29
- "@onekeyfe/hd-shared": "1.1.26-alpha.12",
30
- "@onekeyfe/hd-transport": "1.1.26-alpha.12",
28
+ "@onekeyfe/hd-core": "1.1.26-alpha.30",
29
+ "@onekeyfe/hd-shared": "1.1.26-alpha.30",
30
+ "@onekeyfe/hd-transport": "1.1.26-alpha.30",
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": "f9e7f7f5bdca2609e817898efd4b54c8c871bb2b"
39
+ "gitHead": "88ec305cb60347e09cf9e0c8e921d414f7fe3656"
40
40
  }
@@ -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 = 5000; // 5 seconds for device scanning
83
- const FAST_SCAN_TIMEOUT = 1500; // 1.5 seconds for fast targeted scanning
82
+ const DEVICE_SCAN_TIMEOUT = 8000; // 8 seconds for device scanning (Pro2 has longer advertising interval)
83
+ const FAST_SCAN_TIMEOUT = 8000; // 8 seconds for targeted scanning (Pro2 has longer advertising interval)
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,6 +686,14 @@ 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
+ );
689
697
 
690
698
  // Only process OneKey devices for general discovery
691
699
  if (!isOnekeyDevice(deviceName)) {
@@ -753,8 +761,8 @@ async function performTargetedScan(targetDeviceId: string): Promise<Peripheral |
753
761
  // Add local listener for this scan
754
762
  nobleInstance.on('discover', onDiscover);
755
763
 
756
- // Start scanning
757
- nobleInstance.startScanning(ONEKEY_SERVICE_UUIDS, false, (error?: Error) => {
764
+ // Start scanning — no service UUID filter (Pro2 may use different service UUID)
765
+ nobleInstance.startScanning([], false, (error?: Error) => {
758
766
  if (error) {
759
767
  clearTimeout(timeoutId);
760
768
  nobleInstance.removeListener('discover', onDiscover);
@@ -816,15 +824,19 @@ async function enumerateDevices(): Promise<DeviceInfo[]> {
816
824
  });
817
825
  };
818
826
 
819
- // Set timeout for scanning
827
+ // Set timeout for scanning — use longer timeout to catch slow-advertising devices like Pro2
820
828
  const timeoutId = setTimeout(() => {
829
+ // Final collection before resolving — catches devices discovered near the deadline
830
+ checkDevices();
821
831
  cleanup();
822
832
  logger?.info('[NobleBLE] Scan completed, found devices:', devices.length);
823
833
  resolve(devices);
824
834
  }, DEVICE_SCAN_TIMEOUT);
825
835
 
826
- // Start scanning for OneKey service UUIDs
827
- nobleInstance.startScanning(ONEKEY_SERVICE_UUIDS, false, (error?: Error) => {
836
+ // Start scanning use empty array to discover ALL BLE devices (Pro2 may use different service UUID)
837
+ // TODO: restore ONEKEY_SERVICE_UUIDS filter once Pro2 BLE service UUID is confirmed
838
+ logger?.info('[NobleBLE] Scanning for ALL BLE devices (no service UUID filter)');
839
+ nobleInstance.startScanning([], false, (error?: Error) => {
828
840
  if (error) {
829
841
  cleanup();
830
842
  logger?.error('[NobleBLE] Failed to start scanning:', error);
@@ -952,9 +964,9 @@ async function discoverServicesAndCharacteristics(
952
964
 
953
965
  // Main discovery logic as async function
954
966
  const discoveryPromise = (async (): Promise<CharacteristicPair> => {
955
- // Step 1: Discover services (promisified)
967
+ // Step 1: Discover ALL services (no filter — Pro2 may use different service UUID)
956
968
  const services = await new Promise<Service[]>((resolve, reject) => {
957
- peripheral.discoverServices(ONEKEY_SERVICE_UUIDS, (error, svc) => {
969
+ peripheral.discoverServices([], (error, svc) => {
958
970
  if (error) {
959
971
  logger?.error('[NobleBLE] Service discovery failed:', error);
960
972
  reject(ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound, error.message));
@@ -964,26 +976,40 @@ async function discoverServicesAndCharacteristics(
964
976
  });
965
977
  });
966
978
 
979
+ // Log all discovered services
980
+ logger?.info(
981
+ '[NobleBLE] All services:',
982
+ services?.map(s => s.uuid)
983
+ );
984
+
967
985
  if (!services || services.length === 0) {
968
- throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound, 'No OneKey services found');
986
+ throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound, 'No services found');
969
987
  }
970
988
 
971
- const service = services[0];
972
- logger?.info('[NobleBLE] Found service:', service.uuid);
989
+ // Find OneKey service try known UUID first, fall back to first service
990
+ let service = services.find(s => ONEKEY_SERVICE_UUIDS.includes(s.uuid));
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);
973
1002
 
974
- // Step 2: Discover characteristics (promisified)
1003
+ // Step 2: Discover ALL characteristics (no filter)
975
1004
  const characteristics = await new Promise<Characteristic[]>((resolve, reject) => {
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
- }
1005
+ service.discoverCharacteristics([], (error, chars) => {
1006
+ if (error) {
1007
+ logger?.error('[NobleBLE] Characteristic discovery failed:', error);
1008
+ reject(ERRORS.TypedError(HardwareErrorCode.BleCharacteristicNotFound, error.message));
1009
+ } else {
1010
+ resolve(chars);
985
1011
  }
986
- );
1012
+ });
987
1013
  });
988
1014
 
989
1015
  // Step 3: Find required characteristics