@onekeyfe/hd-transport-electron 1.2.0-alpha.122 → 1.2.0-alpha.124

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-ce551d9a.js'); });
35
+ const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-c88e98df.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-6da32f94.js');
5
+ var index = require('./index-fe6d3919.js');
6
6
 
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-6da32f94.js');
3
+ var index = require('./index-fe6d3919.js');
4
4
  var hdShared = require('@onekeyfe/hd-shared');
5
5
  var pRetry = require('p-retry');
6
6
 
@@ -135,7 +135,7 @@ function isOneKeyPeripheral(peripheral) {
135
135
  var _a, _b;
136
136
  const serviceUuids = (_a = peripheral.advertisement) === null || _a === void 0 ? void 0 : _a.serviceUuids;
137
137
  const localName = (_b = peripheral.advertisement) === null || _b === void 0 ? void 0 : _b.localName;
138
- if (!(localName === null || localName === void 0 ? void 0 : localName.trim()) || hdShared.isPro2FindMyAdvertisementName(localName)) {
138
+ if (!(localName === null || localName === void 0 ? void 0 : localName.trim())) {
139
139
  return false;
140
140
  }
141
141
  return (hdShared.hasOnekeyCommunicationService(serviceUuids) &&
@@ -667,7 +667,7 @@ function performTargetedScan(targetDeviceId) {
667
667
  finish(null).catch(reject);
668
668
  }, NOBLE_BLE_TARGETED_SCAN_TIMEOUT_MS);
669
669
  nobleInstance.on('discover', onDiscover);
670
- nobleInstance.startScanning([], false, (error) => {
670
+ nobleInstance.startScanning([], true, (error) => {
671
671
  if (error) {
672
672
  finish(null, error).catch(reject);
673
673
  return;
@@ -720,7 +720,7 @@ function enumerateDevices() {
720
720
  resolve(devices);
721
721
  }), DEVICE_SCAN_TIMEOUT);
722
722
  logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Scanning for OneKey BLE devices');
723
- nobleInstance.startScanning([], false, (error) => index.__awaiter(this, void 0, void 0, function* () {
723
+ nobleInstance.startScanning([], true, (error) => index.__awaiter(this, void 0, void 0, function* () {
724
724
  if (error) {
725
725
  yield cleanup();
726
726
  logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Failed to start scanning:', error);
@@ -1 +1 @@
1
- {"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AA0EhE,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;AA8lDD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAgMpE"}
1
+ {"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AA0EhE,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;AA8lDD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAgMpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-electron",
3
- "version": "1.2.0-alpha.122",
3
+ "version": "1.2.0-alpha.124",
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.122",
29
- "@onekeyfe/hd-shared": "1.2.0-alpha.122",
30
- "@onekeyfe/hd-transport": "1.2.0-alpha.122",
28
+ "@onekeyfe/hd-core": "1.2.0-alpha.124",
29
+ "@onekeyfe/hd-shared": "1.2.0-alpha.124",
30
+ "@onekeyfe/hd-transport": "1.2.0-alpha.124",
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": "f0a85119fe7f8607768bc77b0ac4eb527d55e1cc"
39
+ "gitHead": "939229b4fe0dd7939b6fa3b2f6801f4e6b055c3b"
40
40
  }
@@ -10,12 +10,12 @@ import type { WebContents } from 'electron';
10
10
 
11
11
  type IpcHandler = (...args: unknown[]) => Promise<unknown> | unknown;
12
12
 
13
- const createPeripheral = (id: string, localName?: string) => ({
13
+ const createPeripheral = (id: string, localName?: string, serviceUuids = ['0001', 'fffd']) => ({
14
14
  id,
15
15
  state: 'disconnected',
16
16
  advertisement: {
17
17
  localName,
18
- serviceUuids: ['0001', 'fffd'],
18
+ serviceUuids,
19
19
  },
20
20
  });
21
21
 
@@ -171,6 +171,7 @@ describe('Electron Noble BLE device discovery', () => {
171
171
  const connectPromise = Promise.resolve(connect(undefined, 'target-device'));
172
172
  await scanStarted;
173
173
 
174
+ expect(noble.startScanning).toHaveBeenCalledWith([], true, expect.any(Function));
174
175
  expect(noble.stopScanning).toHaveBeenCalledTimes(1);
175
176
  expect(peripheral.connect).not.toHaveBeenCalled();
176
177
 
@@ -250,7 +251,7 @@ describe('Electron Noble BLE device discovery', () => {
250
251
  expect(peripheral.disconnect).toHaveBeenCalledTimes(1);
251
252
  });
252
253
 
253
- test('does not enumerate a Pro2 Find My advertisement with the communication service', async () => {
254
+ test('enumerates a Pro2 communication advertisement after Find My changes its name', async () => {
254
255
  jest.useFakeTimers({ doNotFake: ['performance'] });
255
256
 
256
257
  const handlers = new Map<string, IpcHandler>();
@@ -274,8 +275,8 @@ describe('Electron Noble BLE device discovery', () => {
274
275
  noble.state = 'poweredOn';
275
276
  noble.startScanning = jest.fn((_services, _duplicates, callback) => {
276
277
  callback?.();
277
- noble.emit('discover', createPeripheral('find-my-device', 'Pro2 A1B2 - Find My'));
278
- noble.emit('discover', createPeripheral('onekey-device', 'Pro2 A1B2'));
278
+ noble.emit('discover', createPeripheral('find-my-device', 'Pro2 A1B2 - Find My', ['fffd']));
279
+ noble.emit('discover', createPeripheral('onekey-device', 'Pro2 A1B2 - Find My'));
279
280
  resolveScanStarted();
280
281
  });
281
282
  noble.stopScanning = jest.fn(callback => callback?.());
@@ -301,17 +302,18 @@ describe('Electron Noble BLE device discovery', () => {
301
302
 
302
303
  const devicesPromise = Promise.resolve(enumerate());
303
304
  await scanStarted;
305
+ expect(noble.startScanning).toHaveBeenCalledWith([], true, expect.any(Function));
304
306
  jest.advanceTimersByTime(5000);
305
307
 
306
308
  await expect(devicesPromise).resolves.toEqual([
307
309
  expect.objectContaining({
308
310
  id: 'onekey-device',
309
- name: 'Pro2 A1B2',
311
+ name: 'Pro2 A1B2 - Find My',
310
312
  }),
311
313
  ]);
312
314
  });
313
315
 
314
- test('does not enumerate a Find My peripheral first discovered without a name', async () => {
316
+ test('accepts a communication peripheral after its scan response gains a name', async () => {
315
317
  jest.useFakeTimers({ doNotFake: ['performance'] });
316
318
 
317
319
  const handlers = new Map<string, IpcHandler>();
@@ -368,6 +370,10 @@ describe('Electron Noble BLE device discovery', () => {
368
370
  jest.advanceTimersByTime(5000);
369
371
 
370
372
  await expect(devicesPromise).resolves.toEqual([
373
+ expect.objectContaining({
374
+ id: 'find-my-device',
375
+ name: 'Pro2 A1B2 - Find My',
376
+ }),
371
377
  expect.objectContaining({
372
378
  id: 'onekey-device',
373
379
  name: 'Pro2 A1B2',
@@ -15,7 +15,6 @@ import {
15
15
  createKnownBleUuidAliases,
16
16
  hasOnekeyCommunicationService,
17
17
  isOnekeyBluetoothDevice,
18
- isPro2FindMyAdvertisementName,
19
18
  matchesKnownBleUuid,
20
19
  wait,
21
20
  } from '@onekeyfe/hd-shared';
@@ -115,9 +114,7 @@ function isOneKeyPeripheral(peripheral: Peripheral) {
115
114
  const serviceUuids = peripheral.advertisement?.serviceUuids;
116
115
  const localName = peripheral.advertisement?.localName;
117
116
 
118
- // Noble localName is the current advertisement name, so reject the Pro2
119
- // Find My endpoint before the communication-service fast path accepts it.
120
- if (!localName?.trim() || isPro2FindMyAdvertisementName(localName)) {
117
+ if (!localName?.trim()) {
121
118
  return false;
122
119
  }
123
120
 
@@ -843,8 +840,9 @@ async function performTargetedScan(targetDeviceId: string): Promise<Peripheral |
843
840
  // Add local listener for this scan
844
841
  nobleInstance.on('discover', onDiscover);
845
842
 
846
- // Start scanning no service UUID filter (Pro2 may use different service UUID)
847
- nobleInstance.startScanning([], false, (error?: Error) => {
843
+ // Allow repeated advertisements so a service-only packet can be followed by
844
+ // the named scan response needed to validate the target peripheral.
845
+ nobleInstance.startScanning([], true, (error?: Error) => {
848
846
  if (error) {
849
847
  finish(null, error).catch(reject);
850
848
  return;
@@ -915,9 +913,10 @@ async function enumerateDevices(): Promise<DeviceInfo[]> {
915
913
  }, DEVICE_SCAN_TIMEOUT);
916
914
 
917
915
  // Start scanning without a service UUID filter so Pro2 advertisements with
918
- // short vendor UUIDs can be found, but only OneKey candidates are logged/returned.
916
+ // short vendor UUIDs can be found. Repeated advertisements are required when
917
+ // the local name arrives in a later scan response; discoveredDevices handles deduplication.
919
918
  logger?.info('[NobleBLE] Scanning for OneKey BLE devices');
920
- nobleInstance.startScanning([], false, async (error?: Error) => {
919
+ nobleInstance.startScanning([], true, async (error?: Error) => {
921
920
  if (error) {
922
921
  await cleanup();
923
922
  logger?.error('[NobleBLE] Failed to start scanning:', error);