@onekeyfe/hd-transport-electron 1.2.0-alpha.53 → 1.2.0-alpha.55

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-16076f96.js'); });
35
+ const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-e98d7b00.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-3a48215e.js');
5
+ var index = require('./index-c1642d47.js');
6
6
 
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-3a48215e.js');
3
+ var index = require('./index-c1642d47.js');
4
4
  var hdShared = require('@onekeyfe/hd-shared');
5
5
  var pRetry = require('p-retry');
6
6
 
@@ -117,7 +117,7 @@ function isOneKeyPeripheral(peripheral) {
117
117
  var _a, _b;
118
118
  const serviceUuids = (_a = peripheral.advertisement) === null || _a === void 0 ? void 0 : _a.serviceUuids;
119
119
  const localName = (_b = peripheral.advertisement) === null || _b === void 0 ? void 0 : _b.localName;
120
- if (hdShared.isPro2FindMyAdvertisementName(localName)) {
120
+ if (!(localName === null || localName === void 0 ? void 0 : localName.trim()) || hdShared.isPro2FindMyAdvertisementName(localName)) {
121
121
  return false;
122
122
  }
123
123
  return (hdShared.hasOnekeyCommunicationService(serviceUuids) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-electron",
3
- "version": "1.2.0-alpha.53",
3
+ "version": "1.2.0-alpha.55",
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.53",
29
- "@onekeyfe/hd-shared": "1.2.0-alpha.53",
30
- "@onekeyfe/hd-transport": "1.2.0-alpha.53",
28
+ "@onekeyfe/hd-core": "1.2.0-alpha.55",
29
+ "@onekeyfe/hd-shared": "1.2.0-alpha.55",
30
+ "@onekeyfe/hd-transport": "1.2.0-alpha.55",
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": "196b7301f81d730460045c65c90d22706434b04d"
39
+ "gitHead": "0a99a180062ec32fac0c5e14be3366fbfb7bc01a"
40
40
  }
@@ -6,7 +6,7 @@ import type { WebContents } from 'electron';
6
6
 
7
7
  type IpcHandler = (...args: unknown[]) => Promise<unknown> | unknown;
8
8
 
9
- const createPeripheral = (id: string, localName: string) => ({
9
+ const createPeripheral = (id: string, localName?: string) => ({
10
10
  id,
11
11
  state: 'disconnected',
12
12
  advertisement: {
@@ -79,4 +79,65 @@ describe('Electron Noble BLE device discovery', () => {
79
79
  }),
80
80
  ]);
81
81
  });
82
+
83
+ test('does not enumerate a Find My peripheral first discovered without a name', async () => {
84
+ jest.useFakeTimers({ doNotFake: ['performance'] });
85
+
86
+ const handlers = new Map<string, IpcHandler>();
87
+ const ipcMain = {
88
+ handle: jest.fn((channel: string, handler: IpcHandler) => {
89
+ handlers.set(channel, handler);
90
+ }),
91
+ };
92
+ const noble = new EventEmitter() as EventEmitter & {
93
+ state: string;
94
+ startScanning: jest.Mock;
95
+ stopScanning: jest.Mock;
96
+ };
97
+ let resolveScanStarted = () => undefined;
98
+ const scanStarted = new Promise<void>(resolve => {
99
+ resolveScanStarted = resolve;
100
+ });
101
+ const findMyPeripheral = createPeripheral('find-my-device');
102
+ noble.state = 'poweredOn';
103
+ noble.startScanning = jest.fn((_services, _duplicates, callback) => {
104
+ callback?.();
105
+ noble.emit('discover', findMyPeripheral);
106
+ findMyPeripheral.advertisement.localName = 'Pro2 A1B2 - Find My';
107
+ noble.emit('discover', findMyPeripheral);
108
+ noble.emit('discover', createPeripheral('onekey-device', 'Pro2 A1B2'));
109
+ resolveScanStarted();
110
+ });
111
+ noble.stopScanning = jest.fn(callback => callback?.());
112
+
113
+ jest.doMock('@stoprocent/noble', () => noble);
114
+ jest.doMock('electron', () => ({ ipcMain }));
115
+ jest.doMock('electron-log', () => ({
116
+ info: jest.fn(),
117
+ debug: jest.fn(),
118
+ error: jest.fn(),
119
+ }));
120
+
121
+ const { setupNobleBleHandlers } = await import('../noble-ble-handler');
122
+ setupNobleBleHandlers({
123
+ on: jest.fn(),
124
+ send: jest.fn(),
125
+ } as unknown as WebContents);
126
+
127
+ const enumerate = handlers.get(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE);
128
+ if (!enumerate) {
129
+ throw new Error('Electron Noble BLE enumerate handler was not registered');
130
+ }
131
+
132
+ const devicesPromise = Promise.resolve(enumerate());
133
+ await scanStarted;
134
+ jest.advanceTimersByTime(5000);
135
+
136
+ await expect(devicesPromise).resolves.toEqual([
137
+ expect.objectContaining({
138
+ id: 'onekey-device',
139
+ name: 'Pro2 A1B2',
140
+ }),
141
+ ]);
142
+ });
82
143
  });
@@ -98,7 +98,7 @@ function isOneKeyPeripheral(peripheral: Peripheral) {
98
98
 
99
99
  // Noble localName is the current advertisement name, so reject the Pro2
100
100
  // Find My endpoint before the communication-service fast path accepts it.
101
- if (isPro2FindMyAdvertisementName(localName)) {
101
+ if (!localName?.trim() || isPro2FindMyAdvertisementName(localName)) {
102
102
  return false;
103
103
  }
104
104