@onekeyfe/hd-transport-electron 1.2.0-alpha.2 → 1.2.0-alpha.20

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-94c42077.js'); });
35
+ const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-16791965.js'); });
36
36
  setupNobleBleHandlers(webContents);
37
37
  });
38
38
  }
package/dist/index.d.ts CHANGED
@@ -26,6 +26,10 @@ interface Logger {
26
26
  error(message: string, ...args: any[]): void;
27
27
  }
28
28
 
29
+ /**
30
+ * Desktop API types for Electron preload script
31
+ * These types define the core interface for Noble BLE communication
32
+ */
29
33
  interface NobleBleAPI {
30
34
  enumerate: () => Promise<{
31
35
  id: string;
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-02fc07fe.js');
5
+ var index = require('./index-55699e30.js');
6
6
 
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-02fc07fe.js');
3
+ var index = require('./index-55699e30.js');
4
4
  var hdShared = require('@onekeyfe/hd-shared');
5
5
  var pRetry = require('p-retry');
6
6
 
@@ -109,11 +109,6 @@ function isOneKeyPeripheral(peripheral) {
109
109
  return hdShared.isOnekeyDevice(deviceName, peripheral.id) || hasOneKeyAdvertisementService(peripheral);
110
110
  }
111
111
  function emitRawNotification(deviceId, data) {
112
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Raw notification', {
113
- deviceId,
114
- dataLength: data.length,
115
- firstBytes: data.subarray(0, 8).toString('hex'),
116
- });
117
112
  const appCb = notificationCallbacks.get(deviceId);
118
113
  if (appCb)
119
114
  appCb(data.toString('hex'));
@@ -415,11 +410,6 @@ function transmitHexDataToDevice(deviceId, hexData) {
415
410
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotFound, `Device ${deviceId} not connected or characteristics not available`);
416
411
  }
417
412
  const toBuffer = Buffer.from(hexData, 'hex');
418
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Writing data:', {
419
- deviceId,
420
- dataLength: toBuffer.length,
421
- firstBytes: toBuffer.subarray(0, 8).toString('hex'),
422
- });
423
413
  const doGetWriteCharacteristic = () => { var _a; return (_a = deviceCharacteristics.get(deviceId)) === null || _a === void 0 ? void 0 : _a.write; };
424
414
  if (!IS_WINDOWS || pairedDevices.has(deviceId)) {
425
415
  const writeCharacteristic = doGetWriteCharacteristic();
@@ -464,18 +454,16 @@ function transmitHexDataToDevice(deviceId, hexData) {
464
454
  }
465
455
  function handleDeviceDiscovered(peripheral) {
466
456
  var _a, _b;
467
- const deviceName = ((_a = peripheral.advertisement) === null || _a === void 0 ? void 0 : _a.localName) || 'Unknown Device';
468
- const serviceUuids = ((_b = peripheral.advertisement) === null || _b === void 0 ? void 0 : _b.serviceUuids) || [];
469
457
  if (!isOneKeyPeripheral(peripheral)) {
470
458
  return;
471
459
  }
472
460
  const isNewDevice = !discoveredDevices.has(peripheral.id);
473
461
  discoveredDevices.set(peripheral.id, peripheral);
474
462
  if (isNewDevice) {
475
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Discovered OneKey BLE device:', {
476
- name: deviceName,
477
- id: peripheral.id,
478
- serviceUUIDs: serviceUuids,
463
+ logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] OneKey BLE device discovered', {
464
+ deviceId: peripheral.id,
465
+ name: ((_a = peripheral.advertisement) === null || _a === void 0 ? void 0 : _a.localName) || 'Unknown Device',
466
+ serviceUUIDs: ((_b = peripheral.advertisement) === null || _b === void 0 ? void 0 : _b.serviceUuids) || [],
479
467
  });
480
468
  }
481
469
  }
@@ -683,10 +671,13 @@ function discoverServicesAndCharacteristics(peripheral) {
683
671
  }
684
672
  });
685
673
  });
686
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] All services:', services === null || services === void 0 ? void 0 : services.map(s => s.uuid));
687
674
  if (!services || services.length === 0) {
688
675
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound, 'No services found');
689
676
  }
677
+ logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] services discovered', {
678
+ deviceId: peripheral.id,
679
+ serviceUUIDs: services.map(service => service.uuid),
680
+ });
690
681
  let service = services.find(s => NORMALIZED_ONEKEY_SERVICE_UUIDS.has(getBleUuidKey(s.uuid)));
691
682
  if (!service) {
692
683
  logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Known OneKey service UUID not found, trying first vendor service');
@@ -699,7 +690,10 @@ function discoverServicesAndCharacteristics(peripheral) {
699
690
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound);
700
691
  }
701
692
  const selectedService = service;
702
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Using service:', selectedService.uuid);
693
+ logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] service selected', {
694
+ deviceId: peripheral.id,
695
+ serviceUuid: selectedService.uuid,
696
+ });
703
697
  const characteristics = yield new Promise((resolve, reject) => {
704
698
  selectedService.discoverCharacteristics([], (error, chars) => {
705
699
  if (error) {
@@ -711,10 +705,6 @@ function discoverServicesAndCharacteristics(peripheral) {
711
705
  }
712
706
  });
713
707
  });
714
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Discovered characteristics:', {
715
- count: (characteristics === null || characteristics === void 0 ? void 0 : characteristics.length) || 0,
716
- uuids: (characteristics === null || characteristics === void 0 ? void 0 : characteristics.map(c => c.uuid)) || [],
717
- });
718
708
  let writeCharacteristic = null;
719
709
  let notifyCharacteristic = null;
720
710
  for (const characteristic of characteristics) {
@@ -727,14 +717,16 @@ function discoverServicesAndCharacteristics(peripheral) {
727
717
  notifyCharacteristic = characteristic;
728
718
  }
729
719
  }
730
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Characteristic discovery result:', {
731
- writeFound: !!writeCharacteristic,
732
- notifyFound: !!notifyCharacteristic,
733
- });
734
720
  if (!writeCharacteristic || !notifyCharacteristic) {
735
721
  logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Missing characteristics - write:', !!writeCharacteristic, 'notify:', !!notifyCharacteristic);
736
722
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotFound, 'Required characteristics not found');
737
723
  }
724
+ logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] characteristics selected', {
725
+ deviceId: peripheral.id,
726
+ serviceUuid: selectedService.uuid,
727
+ writeUuid: writeCharacteristic.uuid,
728
+ notifyUuid: notifyCharacteristic.uuid,
729
+ });
738
730
  return { write: writeCharacteristic, notify: notifyCharacteristic };
739
731
  }))();
740
732
  try {
@@ -1087,19 +1079,17 @@ function subscribeNotifications(deviceId, callback) {
1087
1079
  });
1088
1080
  }
1089
1081
  function setupNobleBleHandlers(webContents) {
1090
- console.log('[NobleBLE] Attempting to set up Noble BLE handlers.');
1091
1082
  try {
1092
- console.log('[NobleBLE] NOBLE_VERSION_771');
1093
1083
  logger = require('electron-log');
1094
- console.log('[NobleBLE] electron-log loaded successfully.');
1095
1084
  const { ipcMain } = require('electron');
1096
- console.log('[NobleBLE] electron.ipcMain loaded successfully.');
1097
1085
  safeLog(logger, 'info', 'Setting up Noble BLE IPC handlers');
1098
- console.log(`[NobleBLE] Registering handler for: ${hdShared.EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE}`);
1099
1086
  ipcMain.handle(hdShared.EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE, () => index.__awaiter(this, void 0, void 0, function* () {
1100
1087
  try {
1101
1088
  const devices = yield enumerateDevices();
1102
- safeLog(logger, 'info', 'Enumeration completed, devices:', devices);
1089
+ safeLog(logger, 'debug', 'Enumeration completed', {
1090
+ count: devices.length,
1091
+ devices: devices.map(device => ({ id: device.id, name: device.name })),
1092
+ });
1103
1093
  return devices;
1104
1094
  }
1105
1095
  catch (error) {
@@ -1124,7 +1114,6 @@ function setupNobleBleHandlers(webContents) {
1124
1114
  yield disconnectDevice(deviceId);
1125
1115
  }));
1126
1116
  ipcMain.handle(hdShared.EOneKeyBleMessageKeys.NOBLE_BLE_WRITE, (_event, deviceId, hexData) => index.__awaiter(this, void 0, void 0, function* () {
1127
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] IPC WRITE', { deviceId, len: hexData.length });
1128
1117
  yield transmitHexDataToDevice(deviceId, hexData);
1129
1118
  }));
1130
1119
  ipcMain.handle(hdShared.EOneKeyBleMessageKeys.NOBLE_BLE_SUBSCRIBE, (_event, deviceId) => index.__awaiter(this, void 0, void 0, function* () {
@@ -1 +1 @@
1
- {"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAsB,WAAW,EAAE,MAAM,UAAU,CAAC;AAy9ChE,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":"AAoBA,OAAO,KAAK,EAAsB,WAAW,EAAE,MAAM,UAAU,CAAC;AAw8ChE,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAiKpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-electron",
3
- "version": "1.2.0-alpha.2",
3
+ "version": "1.2.0-alpha.20",
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.2.0-alpha.2",
29
- "@onekeyfe/hd-shared": "1.2.0-alpha.2",
30
- "@onekeyfe/hd-transport": "1.2.0-alpha.2",
28
+ "@onekeyfe/hd-core": "1.2.0-alpha.20",
29
+ "@onekeyfe/hd-shared": "1.2.0-alpha.20",
30
+ "@onekeyfe/hd-transport": "1.2.0-alpha.20",
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": "6c183b7f7027f4b4d3db4f427f6360351a6c6680"
39
+ "gitHead": "5fbc1ada90fd3cfda7e5ef08be368cb452018733"
40
40
  }
@@ -117,12 +117,6 @@ function isOneKeyPeripheral(peripheral: Peripheral) {
117
117
  * renderer-side transport. Packet reassembly is handled by ElectronBleTransport.
118
118
  */
119
119
  function emitRawNotification(deviceId: string, data: Buffer): void {
120
- logger?.info('[NobleBLE] Raw notification', {
121
- deviceId,
122
- dataLength: data.length,
123
- firstBytes: data.subarray(0, 8).toString('hex'),
124
- });
125
-
126
120
  const appCb = notificationCallbacks.get(deviceId);
127
121
  if (appCb) appCb(data.toString('hex'));
128
122
  }
@@ -551,12 +545,6 @@ async function transmitHexDataToDevice(deviceId: string, hexData: string): Promi
551
545
  }
552
546
 
553
547
  const toBuffer = Buffer.from(hexData, 'hex');
554
- logger?.info('[NobleBLE] Writing data:', {
555
- deviceId,
556
- dataLength: toBuffer.length,
557
- firstBytes: toBuffer.subarray(0, 8).toString('hex'),
558
- });
559
-
560
548
  const doGetWriteCharacteristic = () => deviceCharacteristics.get(deviceId)?.write;
561
549
 
562
550
  if (!IS_WINDOWS || pairedDevices.has(deviceId)) {
@@ -618,9 +606,6 @@ async function transmitHexDataToDevice(deviceId: string, hexData: string): Promi
618
606
 
619
607
  // Handle discovered device (for general enumeration only)
620
608
  function handleDeviceDiscovered(peripheral: Peripheral): void {
621
- const deviceName = peripheral.advertisement?.localName || 'Unknown Device';
622
- const serviceUuids = peripheral.advertisement?.serviceUuids || [];
623
-
624
609
  // Only process OneKey candidates for general discovery. Avoid logging every
625
610
  // ambient BLE peripheral; it makes Pro2 debugging hard to read.
626
611
  if (!isOneKeyPeripheral(peripheral)) {
@@ -630,10 +615,10 @@ function handleDeviceDiscovered(peripheral: Peripheral): void {
630
615
  const isNewDevice = !discoveredDevices.has(peripheral.id);
631
616
  discoveredDevices.set(peripheral.id, peripheral);
632
617
  if (isNewDevice) {
633
- logger?.info('[NobleBLE] Discovered OneKey BLE device:', {
634
- name: deviceName,
635
- id: peripheral.id,
636
- serviceUUIDs: serviceUuids,
618
+ logger?.debug('[NobleBLE] OneKey BLE device discovered', {
619
+ deviceId: peripheral.id,
620
+ name: peripheral.advertisement?.localName || 'Unknown Device',
621
+ serviceUUIDs: peripheral.advertisement?.serviceUuids || [],
637
622
  });
638
623
  }
639
624
  }
@@ -910,16 +895,15 @@ async function discoverServicesAndCharacteristics(
910
895
  });
911
896
  });
912
897
 
913
- // Log all discovered services
914
- logger?.info(
915
- '[NobleBLE] All services:',
916
- services?.map(s => s.uuid)
917
- );
918
-
919
898
  if (!services || services.length === 0) {
920
899
  throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound, 'No services found');
921
900
  }
922
901
 
902
+ logger?.debug('[NobleBLE] services discovered', {
903
+ deviceId: peripheral.id,
904
+ serviceUUIDs: services.map(service => service.uuid),
905
+ });
906
+
923
907
  // Find OneKey service — Noble may expose 128-bit UUIDs as short UUID keys.
924
908
  let service = services.find(s => NORMALIZED_ONEKEY_SERVICE_UUIDS.has(getBleUuidKey(s.uuid)));
925
909
  if (!service) {
@@ -933,8 +917,10 @@ async function discoverServicesAndCharacteristics(
933
917
  throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound);
934
918
  }
935
919
  const selectedService = service;
936
- logger?.info('[NobleBLE] Using service:', selectedService.uuid);
937
-
920
+ logger?.debug('[NobleBLE] service selected', {
921
+ deviceId: peripheral.id,
922
+ serviceUuid: selectedService.uuid,
923
+ });
938
924
  // Step 2: Discover ALL characteristics (no filter)
939
925
  const characteristics = await new Promise<Characteristic[]>((resolve, reject) => {
940
926
  selectedService.discoverCharacteristics([], (error, chars) => {
@@ -948,11 +934,6 @@ async function discoverServicesAndCharacteristics(
948
934
  });
949
935
 
950
936
  // Step 3: Find required characteristics
951
- logger?.info('[NobleBLE] Discovered characteristics:', {
952
- count: characteristics?.length || 0,
953
- uuids: characteristics?.map(c => c.uuid) || [],
954
- });
955
-
956
937
  let writeCharacteristic: Characteristic | null = null;
957
938
  let notifyCharacteristic: Characteristic | null = null;
958
939
 
@@ -967,11 +948,6 @@ async function discoverServicesAndCharacteristics(
967
948
  }
968
949
  }
969
950
 
970
- logger?.info('[NobleBLE] Characteristic discovery result:', {
971
- writeFound: !!writeCharacteristic,
972
- notifyFound: !!notifyCharacteristic,
973
- });
974
-
975
951
  if (!writeCharacteristic || !notifyCharacteristic) {
976
952
  logger?.error(
977
953
  '[NobleBLE] Missing characteristics - write:',
@@ -985,6 +961,13 @@ async function discoverServicesAndCharacteristics(
985
961
  );
986
962
  }
987
963
 
964
+ logger?.debug('[NobleBLE] characteristics selected', {
965
+ deviceId: peripheral.id,
966
+ serviceUuid: selectedService.uuid,
967
+ writeUuid: writeCharacteristic.uuid,
968
+ notifyUuid: notifyCharacteristic.uuid,
969
+ });
970
+
988
971
  return { write: writeCharacteristic, notify: notifyCharacteristic };
989
972
  })();
990
973
 
@@ -1516,29 +1499,25 @@ async function subscribeNotifications(
1516
1499
 
1517
1500
  // Setup IPC handlers
1518
1501
  export function setupNobleBleHandlers(webContents: WebContents): void {
1519
- // Use console.log for initial logging as electron-log might not be available yet.
1520
- console.log('[NobleBLE] Attempting to set up Noble BLE handlers.');
1521
1502
  try {
1522
- console.log('[NobleBLE] NOBLE_VERSION_771');
1523
-
1524
1503
  // @ts-ignore – electron-log is only available at runtime
1525
1504
  // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
1526
1505
  logger = require('electron-log') as Logger;
1527
- console.log('[NobleBLE] electron-log loaded successfully.');
1528
1506
 
1529
1507
  // @ts-ignore – electron is only available at runtime
1530
1508
  // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
1531
1509
  const { ipcMain } = require('electron');
1532
- console.log('[NobleBLE] electron.ipcMain loaded successfully.');
1533
1510
 
1534
1511
  safeLog(logger, 'info', 'Setting up Noble BLE IPC handlers');
1535
1512
 
1536
1513
  // Handle enumerate request
1537
- console.log(`[NobleBLE] Registering handler for: ${EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE}`);
1538
1514
  ipcMain.handle(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE, async () => {
1539
1515
  try {
1540
1516
  const devices = await enumerateDevices();
1541
- safeLog(logger, 'info', 'Enumeration completed, devices:', devices);
1517
+ safeLog(logger, 'debug', 'Enumeration completed', {
1518
+ count: devices.length,
1519
+ devices: devices.map(device => ({ id: device.id, name: device.name })),
1520
+ });
1542
1521
  return devices;
1543
1522
  } catch (error) {
1544
1523
  safeLog(logger, 'error', 'Enumeration failed:', error);
@@ -1583,7 +1562,6 @@ export function setupNobleBleHandlers(webContents: WebContents): void {
1583
1562
  ipcMain.handle(
1584
1563
  EOneKeyBleMessageKeys.NOBLE_BLE_WRITE,
1585
1564
  async (_event: IpcMainInvokeEvent, deviceId: string, hexData: string) => {
1586
- logger?.info('[NobleBLE] IPC WRITE', { deviceId, len: hexData.length });
1587
1565
  await transmitHexDataToDevice(deviceId, hexData);
1588
1566
  }
1589
1567
  );