@onekeyfe/hd-transport-electron 1.2.0-alpha.56 → 1.2.0-alpha.62
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.
- package/dist/{index-c1642d47.js → index-5f728113.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/{noble-ble-handler-e98d7b00.js → noble-ble-handler-d58af248.js} +5 -9
- package/dist/noble-ble-handler.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/noble-ble-handler.ts +4 -13
- package/src/__tests__/noble-ble-handler.test.ts +0 -142
|
@@ -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-d58af248.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-5f728113.js');
|
|
4
4
|
var hdShared = require('@onekeyfe/hd-shared');
|
|
5
5
|
var pRetry = require('p-retry');
|
|
6
6
|
|
|
@@ -100,10 +100,10 @@ const ONEKEY_SERVICE_UUID_ALIASES = hdShared.createKnownBleUuidAliases(hdShared.
|
|
|
100
100
|
const ONEKEY_WRITE_UUID_ALIASES = hdShared.createKnownBleUuidAliases(hdShared.ONEKEY_WRITE_CHARACTERISTIC_UUID);
|
|
101
101
|
const ONEKEY_NOTIFY_UUID_ALIASES = hdShared.createKnownBleUuidAliases(hdShared.ONEKEY_NOTIFY_CHARACTERISTIC_UUID);
|
|
102
102
|
const BLUETOOTH_INIT_TIMEOUT = 10000;
|
|
103
|
-
const DEVICE_SCAN_TIMEOUT =
|
|
104
|
-
const FAST_SCAN_TIMEOUT =
|
|
103
|
+
const DEVICE_SCAN_TIMEOUT = 8000;
|
|
104
|
+
const FAST_SCAN_TIMEOUT = 8000;
|
|
105
105
|
const DEVICE_CHECK_INTERVAL = 500;
|
|
106
|
-
const CONNECTION_TIMEOUT =
|
|
106
|
+
const CONNECTION_TIMEOUT = 8000;
|
|
107
107
|
const SERVICE_DISCOVERY_TIMEOUT = 10000;
|
|
108
108
|
const BLE_CLEANUP_TIMEOUT = 250;
|
|
109
109
|
const BLE_PACKET_SIZE = 192;
|
|
@@ -116,14 +116,10 @@ const ABORTABLE_WRITE_ERROR_PATTERNS = [
|
|
|
116
116
|
function isOneKeyPeripheral(peripheral) {
|
|
117
117
|
var _a, _b;
|
|
118
118
|
const serviceUuids = (_a = peripheral.advertisement) === null || _a === void 0 ? void 0 : _a.serviceUuids;
|
|
119
|
-
const localName = (_b = peripheral.advertisement) === null || _b === void 0 ? void 0 : _b.localName;
|
|
120
|
-
if (!(localName === null || localName === void 0 ? void 0 : localName.trim()) || hdShared.isPro2FindMyAdvertisementName(localName)) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
119
|
return (hdShared.hasOnekeyCommunicationService(serviceUuids) &&
|
|
124
120
|
hdShared.isOnekeyBluetoothDevice({
|
|
125
121
|
id: peripheral.id,
|
|
126
|
-
localName,
|
|
122
|
+
localName: (_b = peripheral.advertisement) === null || _b === void 0 ? void 0 : _b.localName,
|
|
127
123
|
serviceUuids,
|
|
128
124
|
}));
|
|
129
125
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAsB,WAAW,EAAE,MAAM,UAAU,CAAC;AA46ChE,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAyJpE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-electron",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.62",
|
|
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.
|
|
29
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
30
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.62",
|
|
29
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.62",
|
|
30
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.62",
|
|
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": "f38f4fc8bf05aea42a4da5b2bd633544597ad958"
|
|
40
40
|
}
|
package/src/noble-ble-handler.ts
CHANGED
|
@@ -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';
|
|
@@ -76,10 +75,10 @@ const ONEKEY_NOTIFY_UUID_ALIASES = createKnownBleUuidAliases(ONEKEY_NOTIFY_CHARA
|
|
|
76
75
|
|
|
77
76
|
// Timeout and interval constants
|
|
78
77
|
const BLUETOOTH_INIT_TIMEOUT = 10000; // 10 seconds for Bluetooth initialization
|
|
79
|
-
const DEVICE_SCAN_TIMEOUT =
|
|
80
|
-
const FAST_SCAN_TIMEOUT =
|
|
78
|
+
const DEVICE_SCAN_TIMEOUT = 8000; // 8 seconds for device scanning (Pro2 has longer advertising interval)
|
|
79
|
+
const FAST_SCAN_TIMEOUT = 8000; // 8 seconds for targeted scanning (Pro2 has longer advertising interval)
|
|
81
80
|
const DEVICE_CHECK_INTERVAL = 500; // 500ms interval for periodic device checks
|
|
82
|
-
const CONNECTION_TIMEOUT =
|
|
81
|
+
const CONNECTION_TIMEOUT = 8000; // 8 seconds for device connection (BLE reconnect after release can be slow)
|
|
83
82
|
const SERVICE_DISCOVERY_TIMEOUT = 10000; // 10 seconds for service discovery
|
|
84
83
|
const BLE_CLEANUP_TIMEOUT = 250;
|
|
85
84
|
|
|
@@ -94,19 +93,11 @@ const ABORTABLE_WRITE_ERROR_PATTERNS = [
|
|
|
94
93
|
|
|
95
94
|
function isOneKeyPeripheral(peripheral: Peripheral) {
|
|
96
95
|
const serviceUuids = peripheral.advertisement?.serviceUuids;
|
|
97
|
-
const localName = peripheral.advertisement?.localName;
|
|
98
|
-
|
|
99
|
-
// Noble localName is the current advertisement name, so reject the Pro2
|
|
100
|
-
// Find My endpoint before the communication-service fast path accepts it.
|
|
101
|
-
if (!localName?.trim() || isPro2FindMyAdvertisementName(localName)) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
96
|
return (
|
|
106
97
|
hasOnekeyCommunicationService(serviceUuids) &&
|
|
107
98
|
isOnekeyBluetoothDevice({
|
|
108
99
|
id: peripheral.id,
|
|
109
|
-
localName,
|
|
100
|
+
localName: peripheral.advertisement?.localName,
|
|
110
101
|
serviceUuids,
|
|
111
102
|
})
|
|
112
103
|
);
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { EOneKeyBleMessageKeys } from '@onekeyfe/hd-shared';
|
|
3
|
-
|
|
4
|
-
import type { WebContents } from 'electron';
|
|
5
|
-
|
|
6
|
-
type IpcHandler = (...args: unknown[]) => Promise<unknown> | unknown;
|
|
7
|
-
|
|
8
|
-
const createPeripheral = (id: string, localName?: string) => ({
|
|
9
|
-
id,
|
|
10
|
-
state: 'disconnected',
|
|
11
|
-
advertisement: {
|
|
12
|
-
localName,
|
|
13
|
-
serviceUuids: ['0001', 'fffd'],
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('Electron Noble BLE device discovery', () => {
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
jest.useRealTimers();
|
|
20
|
-
jest.resetModules();
|
|
21
|
-
jest.clearAllMocks();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('does not enumerate a Pro2 Find My advertisement with the communication service', async () => {
|
|
25
|
-
jest.useFakeTimers({ doNotFake: ['performance'] });
|
|
26
|
-
|
|
27
|
-
const handlers = new Map<string, IpcHandler>();
|
|
28
|
-
const ipcMain = {
|
|
29
|
-
handle: jest.fn((channel: string, handler: IpcHandler) => {
|
|
30
|
-
handlers.set(channel, handler);
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
const noble = new EventEmitter() as EventEmitter & {
|
|
34
|
-
state: string;
|
|
35
|
-
startScanning: jest.Mock;
|
|
36
|
-
stopScanning: jest.Mock;
|
|
37
|
-
};
|
|
38
|
-
let resolveScanStarted = () => undefined;
|
|
39
|
-
const scanStarted = new Promise<void>(resolve => {
|
|
40
|
-
resolveScanStarted = resolve;
|
|
41
|
-
});
|
|
42
|
-
noble.state = 'poweredOn';
|
|
43
|
-
noble.startScanning = jest.fn((_services, _duplicates, callback) => {
|
|
44
|
-
callback?.();
|
|
45
|
-
noble.emit('discover', createPeripheral('find-my-device', 'Pro2 A1B2 - Find My'));
|
|
46
|
-
noble.emit('discover', createPeripheral('onekey-device', 'Pro2 A1B2'));
|
|
47
|
-
resolveScanStarted();
|
|
48
|
-
});
|
|
49
|
-
noble.stopScanning = jest.fn(callback => callback?.());
|
|
50
|
-
|
|
51
|
-
jest.doMock('@stoprocent/noble', () => noble);
|
|
52
|
-
jest.doMock('electron', () => ({ ipcMain }));
|
|
53
|
-
jest.doMock('electron-log', () => ({
|
|
54
|
-
info: jest.fn(),
|
|
55
|
-
debug: jest.fn(),
|
|
56
|
-
error: jest.fn(),
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
const { setupNobleBleHandlers } = await import('../noble-ble-handler');
|
|
60
|
-
setupNobleBleHandlers({
|
|
61
|
-
on: jest.fn(),
|
|
62
|
-
send: jest.fn(),
|
|
63
|
-
} as unknown as WebContents);
|
|
64
|
-
|
|
65
|
-
const enumerate = handlers.get(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE);
|
|
66
|
-
if (!enumerate) {
|
|
67
|
-
throw new Error('Electron Noble BLE enumerate handler was not registered');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const devicesPromise = Promise.resolve(enumerate());
|
|
71
|
-
await scanStarted;
|
|
72
|
-
jest.advanceTimersByTime(5000);
|
|
73
|
-
|
|
74
|
-
await expect(devicesPromise).resolves.toEqual([
|
|
75
|
-
expect.objectContaining({
|
|
76
|
-
id: 'onekey-device',
|
|
77
|
-
name: 'Pro2 A1B2',
|
|
78
|
-
}),
|
|
79
|
-
]);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('does not enumerate a Find My peripheral first discovered without a name', async () => {
|
|
83
|
-
jest.useFakeTimers({ doNotFake: ['performance'] });
|
|
84
|
-
|
|
85
|
-
const handlers = new Map<string, IpcHandler>();
|
|
86
|
-
const ipcMain = {
|
|
87
|
-
handle: jest.fn((channel: string, handler: IpcHandler) => {
|
|
88
|
-
handlers.set(channel, handler);
|
|
89
|
-
}),
|
|
90
|
-
};
|
|
91
|
-
const noble = new EventEmitter() as EventEmitter & {
|
|
92
|
-
state: string;
|
|
93
|
-
startScanning: jest.Mock;
|
|
94
|
-
stopScanning: jest.Mock;
|
|
95
|
-
};
|
|
96
|
-
let resolveScanStarted = () => undefined;
|
|
97
|
-
const scanStarted = new Promise<void>(resolve => {
|
|
98
|
-
resolveScanStarted = resolve;
|
|
99
|
-
});
|
|
100
|
-
const findMyPeripheral = createPeripheral('find-my-device');
|
|
101
|
-
noble.state = 'poweredOn';
|
|
102
|
-
noble.startScanning = jest.fn((_services, _duplicates, callback) => {
|
|
103
|
-
callback?.();
|
|
104
|
-
noble.emit('discover', findMyPeripheral);
|
|
105
|
-
findMyPeripheral.advertisement.localName = 'Pro2 A1B2 - Find My';
|
|
106
|
-
noble.emit('discover', findMyPeripheral);
|
|
107
|
-
noble.emit('discover', createPeripheral('onekey-device', 'Pro2 A1B2'));
|
|
108
|
-
resolveScanStarted();
|
|
109
|
-
});
|
|
110
|
-
noble.stopScanning = jest.fn(callback => callback?.());
|
|
111
|
-
|
|
112
|
-
jest.doMock('@stoprocent/noble', () => noble);
|
|
113
|
-
jest.doMock('electron', () => ({ ipcMain }));
|
|
114
|
-
jest.doMock('electron-log', () => ({
|
|
115
|
-
info: jest.fn(),
|
|
116
|
-
debug: jest.fn(),
|
|
117
|
-
error: jest.fn(),
|
|
118
|
-
}));
|
|
119
|
-
|
|
120
|
-
const { setupNobleBleHandlers } = await import('../noble-ble-handler');
|
|
121
|
-
setupNobleBleHandlers({
|
|
122
|
-
on: jest.fn(),
|
|
123
|
-
send: jest.fn(),
|
|
124
|
-
} as unknown as WebContents);
|
|
125
|
-
|
|
126
|
-
const enumerate = handlers.get(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE);
|
|
127
|
-
if (!enumerate) {
|
|
128
|
-
throw new Error('Electron Noble BLE enumerate handler was not registered');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const devicesPromise = Promise.resolve(enumerate());
|
|
132
|
-
await scanStarted;
|
|
133
|
-
jest.advanceTimersByTime(5000);
|
|
134
|
-
|
|
135
|
-
await expect(devicesPromise).resolves.toEqual([
|
|
136
|
-
expect.objectContaining({
|
|
137
|
-
id: 'onekey-device',
|
|
138
|
-
name: 'Pro2 A1B2',
|
|
139
|
-
}),
|
|
140
|
-
]);
|
|
141
|
-
});
|
|
142
|
-
});
|