@onekeyfe/hd-transport-web-device 1.2.0-alpha.146 → 1.2.0-alpha.147
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/__tests__/electron-ble-transport.test.ts +8 -65
- package/__tests__/webusb-protocol-cache.test.ts +1 -1
- package/__tests__/webusb-protocol-v2-timeout.test.ts +3 -9
- package/dist/electron-ble-transport.d.ts +0 -1
- package/dist/electron-ble-transport.d.ts.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +37 -37
- package/dist/webusb.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/electron-ble-transport.ts +15 -15
- package/src/webusb.ts +19 -20
|
@@ -440,64 +440,7 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
440
440
|
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
441
441
|
});
|
|
442
442
|
|
|
443
|
-
test('
|
|
444
|
-
const device = { id: 'first-v2-id', name: 'OneKey Pro 2' };
|
|
445
|
-
const nobleBle = createNobleBle(device);
|
|
446
|
-
const transport = configureTransport(nobleBle);
|
|
447
|
-
jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
|
|
448
|
-
|
|
449
|
-
await expect(
|
|
450
|
-
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
451
|
-
).rejects.toMatchObject({
|
|
452
|
-
errorCode: HardwareErrorCode.RuntimeError,
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
expect(nobleBle.connect).toHaveBeenCalledTimes(1);
|
|
456
|
-
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
test('keeps a second expected Protocol V2 probe miss retryable', async () => {
|
|
460
|
-
const device = { id: 'retry-pro2-id', name: 'OneKey Pro 2' };
|
|
461
|
-
const nobleBle = createNobleBle(device);
|
|
462
|
-
const transport = configureTransport(nobleBle);
|
|
463
|
-
jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
|
|
464
|
-
|
|
465
|
-
await expect(
|
|
466
|
-
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
467
|
-
).rejects.toMatchObject({
|
|
468
|
-
errorCode: HardwareErrorCode.RuntimeError,
|
|
469
|
-
});
|
|
470
|
-
await expect(
|
|
471
|
-
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
472
|
-
).rejects.toMatchObject({
|
|
473
|
-
errorCode: HardwareErrorCode.RuntimeError,
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
test('reports a stale bond when a previously confirmed Protocol V2 device stops responding', async () => {
|
|
480
|
-
const device = { id: 'reset-pro2-id', name: 'OneKey Pro 2' };
|
|
481
|
-
const nobleBle = createNobleBle(device);
|
|
482
|
-
const transport = configureTransport(nobleBle);
|
|
483
|
-
const probe = jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(true);
|
|
484
|
-
|
|
485
|
-
await transport.acquire({ uuid: device.id, expectedProtocol: 'V2' });
|
|
486
|
-
await transport.release(device.id);
|
|
487
|
-
probe.mockResolvedValue(false);
|
|
488
|
-
|
|
489
|
-
await expect(
|
|
490
|
-
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
491
|
-
).rejects.toMatchObject({
|
|
492
|
-
errorCode: HardwareErrorCode.BleDeviceBondError,
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
expect(nobleBle.unsubscribe).toHaveBeenCalledWith(device.id);
|
|
496
|
-
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|
|
497
|
-
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
test('does not take a Protocol V2 hint from the BLE name', async () => {
|
|
443
|
+
test('probes Protocol V2 instead of trusting the Pro2 name hint', async () => {
|
|
501
444
|
const device = { id: 'named-pro2-id', name: 'OneKey Pro 2' };
|
|
502
445
|
const nobleBle = createNobleBle(device);
|
|
503
446
|
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
@@ -527,15 +470,15 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
527
470
|
protocolType: 'V2',
|
|
528
471
|
})
|
|
529
472
|
);
|
|
530
|
-
expect(nobleBle.write
|
|
473
|
+
expect(nobleBle.write).toHaveBeenCalledTimes(1);
|
|
531
474
|
expect(transport.getProtocolType(device.id)).toBe('V2');
|
|
532
475
|
await expect(transport.call(device.id, 'Ping', { message: 'after-probe' })).resolves.toEqual({
|
|
533
476
|
type: 'Success',
|
|
534
477
|
message: { message: 'ok' },
|
|
535
478
|
});
|
|
536
|
-
const sentSeqs = nobleBle.write.mock.calls
|
|
537
|
-
|
|
538
|
-
|
|
479
|
+
const sentSeqs = nobleBle.write.mock.calls.map(([, hex]) =>
|
|
480
|
+
Number.parseInt(hex.slice(12, 14), 16)
|
|
481
|
+
);
|
|
539
482
|
expect(sentSeqs).toEqual([1, 2]);
|
|
540
483
|
} finally {
|
|
541
484
|
await transport.release(device.id);
|
|
@@ -615,9 +558,9 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
615
558
|
message: { message: 'ok' },
|
|
616
559
|
});
|
|
617
560
|
|
|
618
|
-
const sentSeqs = nobleBle.write.mock.calls
|
|
619
|
-
|
|
620
|
-
|
|
561
|
+
const sentSeqs = nobleBle.write.mock.calls.map(([, hex]) =>
|
|
562
|
+
Number.parseInt(hex.slice(12, 14), 16)
|
|
563
|
+
);
|
|
621
564
|
expect(sentSeqs).toEqual([1, 2, 3]);
|
|
622
565
|
} finally {
|
|
623
566
|
await transport.release(device.id);
|
|
@@ -230,7 +230,7 @@ describe('WebUsbTransport protocol probe cache', () => {
|
|
|
230
230
|
expect(second.deviceProtocol.get(path)).toBe('V1');
|
|
231
231
|
expect(first.staleProtocolPaths.has(path)).toBe(false);
|
|
232
232
|
|
|
233
|
-
// Events without a
|
|
233
|
+
// Events without a usable serial are ignored.
|
|
234
234
|
handler({ device: { serialNumber: null } });
|
|
235
235
|
handler({});
|
|
236
236
|
expect(second.staleProtocolPaths.size).toBe(1);
|
|
@@ -21,9 +21,8 @@ const schema = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
describe('WebUsbTransport Protocol V2 timeout recovery', () => {
|
|
24
|
-
test('enumerates
|
|
25
|
-
const filter =
|
|
26
|
-
ONEKEY_WEBUSB_FILTER.find(item => item.productId === 0x4f4c) ?? ONEKEY_WEBUSB_FILTER[0];
|
|
24
|
+
test('only enumerates devices with real USB serial numbers', async () => {
|
|
25
|
+
const filter = ONEKEY_WEBUSB_FILTER[0];
|
|
27
26
|
const deviceWithSerial = {
|
|
28
27
|
...filter,
|
|
29
28
|
manufacturerName: 'OneKey',
|
|
@@ -33,7 +32,7 @@ describe('WebUsbTransport Protocol V2 timeout recovery', () => {
|
|
|
33
32
|
const deviceWithoutSerial = {
|
|
34
33
|
...filter,
|
|
35
34
|
manufacturerName: 'OneKey',
|
|
36
|
-
productName: 'OneKey
|
|
35
|
+
productName: 'OneKey Pro 2',
|
|
37
36
|
serialNumber: null,
|
|
38
37
|
} as USBDevice;
|
|
39
38
|
const webusb = new WebUsbTransport();
|
|
@@ -47,11 +46,6 @@ describe('WebUsbTransport Protocol V2 timeout recovery', () => {
|
|
|
47
46
|
device: deviceWithSerial,
|
|
48
47
|
commType: 'webusb',
|
|
49
48
|
},
|
|
50
|
-
{
|
|
51
|
-
path: 'usb-1209-4f4c-onekey-neo',
|
|
52
|
-
device: deviceWithoutSerial,
|
|
53
|
-
commType: 'webusb',
|
|
54
|
-
},
|
|
55
49
|
]);
|
|
56
50
|
});
|
|
57
51
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AAsBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qB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IAwB5B,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;IAgD5B,OAAO,CAAC,8BAA8B;YAgBxB,iCAAiC;YAwBjC,eAAe;YAkBf,eAAe;YAuBf,SAAS;YAST,wBAAwB;IAKtC,OAAO,CAAC,uBAAuB;IAc/B,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,oBAAoB;IAqB5B,OAAO,CAAC,kBAAkB;IAwB1B,OAAO,CAAC,4BAA4B;IAkBpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;IAiBjC,OAAO,CAAC,4BAA4B;IAqB9B,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;IAuB1B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;YAatD,cAAc;YAqFd,cAAc;IA0B5B,OAAO,CAAC,uBAAuB;IAyC/B,OAAO,CAAC,6BAA6B;IA4CrC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -210,8 +210,6 @@ declare class ElectronBleTransport {
|
|
|
210
210
|
private connectedDevices;
|
|
211
211
|
private deviceProtocol;
|
|
212
212
|
private deviceProtocolHints;
|
|
213
|
-
/** Endpoints that answered a V2 probe in this transport lifetime. Survives disconnect. */
|
|
214
|
-
private confirmedProtocolV2;
|
|
215
213
|
private deviceMtus;
|
|
216
214
|
private devicePacketCapacities;
|
|
217
215
|
private v1Buffers;
|
package/dist/index.js
CHANGED
|
@@ -54,6 +54,9 @@ const PACKET_IO_RETRY_DELAY = 300;
|
|
|
54
54
|
const PROTOCOL_V1_PROBE_TIMEOUT = 5000;
|
|
55
55
|
const PROTOCOL_V2_PROBE_TIMEOUT = 1000;
|
|
56
56
|
const EXPECTED_PROTOCOL_V2_PROBE_ATTEMPTS = 2;
|
|
57
|
+
function inferProtocolHintFromDeviceName$1(name) {
|
|
58
|
+
return /\bpro\s*2\b/i.test(name !== null && name !== void 0 ? name : '') ? 'V2' : undefined;
|
|
59
|
+
}
|
|
57
60
|
let activeWebUsbTransport;
|
|
58
61
|
let usbDisconnectListenerAttached = false;
|
|
59
62
|
function registerActiveWebUsbTransport(instance, usb) {
|
|
@@ -62,12 +65,11 @@ function registerActiveWebUsbTransport(instance, usb) {
|
|
|
62
65
|
return;
|
|
63
66
|
usbDisconnectListenerAttached = true;
|
|
64
67
|
usb.addEventListener('disconnect', event => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (!path)
|
|
68
|
+
var _a;
|
|
69
|
+
const serial = (_a = event.device) === null || _a === void 0 ? void 0 : _a.serialNumber;
|
|
70
|
+
if (typeof serial !== 'string' || serial.length === 0)
|
|
69
71
|
return;
|
|
70
|
-
activeWebUsbTransport === null || activeWebUsbTransport === void 0 ? void 0 : activeWebUsbTransport.markProtocolStale(
|
|
72
|
+
activeWebUsbTransport === null || activeWebUsbTransport === void 0 ? void 0 : activeWebUsbTransport.markProtocolStale(serial);
|
|
71
73
|
});
|
|
72
74
|
}
|
|
73
75
|
class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
@@ -150,23 +152,20 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
150
152
|
const devices = yield this.usb.getDevices();
|
|
151
153
|
const onekeyDevices = devices.filter(dev => {
|
|
152
154
|
const isOneKey = hdShared.ONEKEY_WEBUSB_FILTER.some((desc) => dev.vendorId === desc.vendorId && dev.productId === desc.productId);
|
|
153
|
-
|
|
155
|
+
const hasSerialNumber = typeof dev.serialNumber === 'string' && dev.serialNumber.length > 0;
|
|
156
|
+
return isOneKey && hasSerialNumber && !hdShared.isKnownTrezorWebUsbDevice(dev);
|
|
154
157
|
});
|
|
155
|
-
this.deviceList = onekeyDevices.
|
|
156
|
-
const path =
|
|
157
|
-
|
|
158
|
-
return [];
|
|
159
|
-
const protocolHint = hdShared.inferProtocolHintFromUsbId(device.vendorId, device.productId);
|
|
158
|
+
this.deviceList = onekeyDevices.map(device => {
|
|
159
|
+
const path = device.serialNumber;
|
|
160
|
+
const protocolHint = inferProtocolHintFromDeviceName$1(device.productName);
|
|
160
161
|
if (protocolHint) {
|
|
161
162
|
this.deviceProtocolHints.set(path, protocolHint);
|
|
162
163
|
}
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
},
|
|
169
|
-
];
|
|
164
|
+
return {
|
|
165
|
+
path,
|
|
166
|
+
device,
|
|
167
|
+
commType: 'webusb',
|
|
168
|
+
};
|
|
170
169
|
});
|
|
171
170
|
return this.deviceList;
|
|
172
171
|
});
|
|
@@ -200,10 +199,10 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
200
199
|
this.deviceProtocol.delete(input.path);
|
|
201
200
|
}
|
|
202
201
|
if (!this.deviceProtocol.has(input.path)) {
|
|
203
|
-
const
|
|
202
|
+
const deviceName = (_c = this.deviceList.find(device => device.path === input.path)) === null || _c === void 0 ? void 0 : _c.device.productName;
|
|
204
203
|
const protocolHint = input.expectedProtocol
|
|
205
204
|
? undefined
|
|
206
|
-
: (_e = (_d = input.protocolHint) !== null && _d !== void 0 ? _d : this.deviceProtocolHints.get(input.path)) !== null && _e !== void 0 ? _e :
|
|
205
|
+
: (_e = (_d = input.protocolHint) !== null && _d !== void 0 ? _d : this.deviceProtocolHints.get(input.path)) !== null && _e !== void 0 ? _e : inferProtocolHintFromDeviceName$1(deviceName);
|
|
207
206
|
if (protocolHint) {
|
|
208
207
|
this.deviceProtocolHints.set(input.path, protocolHint);
|
|
209
208
|
}
|
|
@@ -793,6 +792,9 @@ function resolveBlePacketCapacity(mtu, maximumPacketCapacity, fallbackPacketCapa
|
|
|
793
792
|
}
|
|
794
793
|
|
|
795
794
|
const { parseConfigure, ProtocolV1, check } = transport__default["default"];
|
|
795
|
+
function inferProtocolHintFromDeviceName(name) {
|
|
796
|
+
return /\bpro\s*2\b/i.test(name !== null && name !== void 0 ? name : '') ? 'V2' : undefined;
|
|
797
|
+
}
|
|
796
798
|
const toBleDescriptor = (device, protocolType) => (Object.assign({ id: device.id, name: device.name, path: device.id, debug: false, commType: 'electron-ble' }, (protocolType ? { protocolType } : {})));
|
|
797
799
|
const BLE_PACKET_SIZE_FALLBACK = 192;
|
|
798
800
|
const BLE_PACKET_SIZE_MAXIMUM = 244;
|
|
@@ -808,7 +810,6 @@ class ElectronBleTransport {
|
|
|
808
810
|
this.connectedDevices = new Set();
|
|
809
811
|
this.deviceProtocol = new Map();
|
|
810
812
|
this.deviceProtocolHints = new Map();
|
|
811
|
-
this.confirmedProtocolV2 = new Set();
|
|
812
813
|
this.deviceMtus = new Map();
|
|
813
814
|
this.devicePacketCapacities = new Map();
|
|
814
815
|
this.v1Buffers = new Map();
|
|
@@ -948,6 +949,10 @@ class ElectronBleTransport {
|
|
|
948
949
|
(_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug(`[Electron BLE] enumerate found ${devices.length} device(s):`);
|
|
949
950
|
for (const dev of devices) {
|
|
950
951
|
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[Electron BLE] id="${dev.id}" name="${dev.name}"`);
|
|
952
|
+
const protocolHint = inferProtocolHintFromDeviceName(dev.name);
|
|
953
|
+
if (protocolHint) {
|
|
954
|
+
this.deviceProtocolHints.set(dev.id, protocolHint);
|
|
955
|
+
}
|
|
951
956
|
}
|
|
952
957
|
return devices.map(device => toBleDescriptor(device));
|
|
953
958
|
}
|
|
@@ -958,7 +963,7 @@ class ElectronBleTransport {
|
|
|
958
963
|
});
|
|
959
964
|
}
|
|
960
965
|
acquire(input) {
|
|
961
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
966
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
962
967
|
return __awaiter(this, void 0, void 0, function* () {
|
|
963
968
|
const { uuid, forceCleanRunPromise, expectedProtocol } = input;
|
|
964
969
|
if (!uuid) {
|
|
@@ -983,7 +988,7 @@ class ElectronBleTransport {
|
|
|
983
988
|
}
|
|
984
989
|
const protocolHint = expectedProtocol
|
|
985
990
|
? undefined
|
|
986
|
-
: (_b = input.protocolHint) !== null && _b !== void 0 ? _b : this.deviceProtocolHints.get(uuid);
|
|
991
|
+
: (_c = (_b = input.protocolHint) !== null && _b !== void 0 ? _b : this.deviceProtocolHints.get(uuid)) !== null && _c !== void 0 ? _c : inferProtocolHintFromDeviceName(device.name);
|
|
987
992
|
if (protocolHint) {
|
|
988
993
|
this.deviceProtocolHints.set(uuid, protocolHint);
|
|
989
994
|
}
|
|
@@ -1007,10 +1012,10 @@ class ElectronBleTransport {
|
|
|
1007
1012
|
const connectionToken = this.notificationTokens.get(uuid);
|
|
1008
1013
|
const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint);
|
|
1009
1014
|
if (protocolType === 'V2') {
|
|
1010
|
-
(
|
|
1015
|
+
(_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug('[Electron BLE] Protocol V2 write configured', {
|
|
1011
1016
|
writeMode: 'withoutResponse',
|
|
1012
1017
|
negotiatedMtu: this.deviceMtus.get(uuid),
|
|
1013
|
-
packetCapacity: (
|
|
1018
|
+
packetCapacity: (_e = this.devicePacketCapacities.get(uuid)) !== null && _e !== void 0 ? _e : BLE_PACKET_SIZE_FALLBACK,
|
|
1014
1019
|
});
|
|
1015
1020
|
}
|
|
1016
1021
|
const disconnectCleanup = window.desktopApi.nobleBle.onDeviceDisconnected((disconnectedDevice) => {
|
|
@@ -1029,15 +1034,15 @@ class ElectronBleTransport {
|
|
|
1029
1034
|
return Object.assign(Object.assign({}, toBleDescriptor({ id: device.id, name: device.name }, protocolType)), { uuid });
|
|
1030
1035
|
}
|
|
1031
1036
|
catch (error) {
|
|
1032
|
-
(
|
|
1037
|
+
(_f = this.Log) === null || _f === void 0 ? void 0 : _f.error('[Electron BLE] acquire failed:', error);
|
|
1033
1038
|
try {
|
|
1034
|
-
if (((
|
|
1039
|
+
if (((_g = window.desktopApi) === null || _g === void 0 ? void 0 : _g.nobleBle) && this.connectedDevices.has(uuid)) {
|
|
1035
1040
|
yield window.desktopApi.nobleBle.unsubscribe(uuid);
|
|
1036
1041
|
yield window.desktopApi.nobleBle.disconnect(uuid);
|
|
1037
1042
|
}
|
|
1038
1043
|
}
|
|
1039
1044
|
catch (cleanupError) {
|
|
1040
|
-
(
|
|
1045
|
+
(_h = this.Log) === null || _h === void 0 ? void 0 : _h.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
|
|
1041
1046
|
}
|
|
1042
1047
|
this.cleanupDeviceState(uuid);
|
|
1043
1048
|
throw error;
|
|
@@ -1104,9 +1109,8 @@ class ElectronBleTransport {
|
|
|
1104
1109
|
}
|
|
1105
1110
|
});
|
|
1106
1111
|
}
|
|
1107
|
-
createProtocolMismatchError(expected
|
|
1108
|
-
|
|
1109
|
-
return hdShared.ERRORS.TypedError(isStaleV2Bond ? hdShared.HardwareErrorCode.BleDeviceBondError : hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
|
|
1112
|
+
createProtocolMismatchError(expected) {
|
|
1113
|
+
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
|
|
1110
1114
|
}
|
|
1111
1115
|
createProtocolDetectionError() {
|
|
1112
1116
|
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'Unable to detect BLE protocol: device did not respond to Protocol V1 GetFeatures or Protocol V2 Ping');
|
|
@@ -1125,16 +1129,15 @@ class ElectronBleTransport {
|
|
|
1125
1129
|
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V1 (expected)`);
|
|
1126
1130
|
return 'V1';
|
|
1127
1131
|
}
|
|
1128
|
-
throw this.createProtocolMismatchError(expectedProtocol
|
|
1132
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
1129
1133
|
}
|
|
1130
1134
|
if (expectedProtocol === 'V2') {
|
|
1131
1135
|
if (yield this.probeProtocolV2(uuid)) {
|
|
1132
1136
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1133
|
-
this.confirmedProtocolV2.add(uuid);
|
|
1134
1137
|
(_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V2 (expected)`);
|
|
1135
1138
|
return 'V2';
|
|
1136
1139
|
}
|
|
1137
|
-
throw this.createProtocolMismatchError(expectedProtocol
|
|
1140
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
1138
1141
|
}
|
|
1139
1142
|
const probeOrder = protocolHint === 'V2' || this.deviceProtocol.get(uuid) === 'V2' ? ['V2', 'V1'] : ['V1', 'V2'];
|
|
1140
1143
|
for (let i = 0; i < probeOrder.length; i += 1) {
|
|
@@ -1145,9 +1148,6 @@ class ElectronBleTransport {
|
|
|
1145
1148
|
const detected = protocol === 'V1' ? yield this.probeProtocolV1(uuid) : yield this.probeProtocolV2(uuid);
|
|
1146
1149
|
if (detected) {
|
|
1147
1150
|
this.deviceProtocol.set(uuid, protocol);
|
|
1148
|
-
if (protocol === 'V2') {
|
|
1149
|
-
this.confirmedProtocolV2.add(uuid);
|
|
1150
|
-
}
|
|
1151
1151
|
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> ${protocol}`);
|
|
1152
1152
|
return protocol;
|
|
1153
1153
|
}
|
package/dist/webusb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webusb.d.ts","sourceRoot":"","sources":["../src/webusb.ts"],"names":[],"mappings":";AACA,OAAO,SAAS,EAAE,EAQhB,0BAA0B,EAE3B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"webusb.d.ts","sourceRoot":"","sources":["../src/webusb.ts"],"names":[],"mappings":";AACA,OAAO,SAAS,EAAE,EAQhB,0BAA0B,EAE3B,MAAM,wBAAwB,CAAC;AAUhC,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AA0BhC,MAAM,WAAW,UAAW,SAAQ,oBAAoB;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,CAAC;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAkCD,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,0BAA0B,CAAC,MAAM,CAAC;IAC7E,QAAQ,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAGlE,UAAU,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEpE,OAAO,CAAC,sBAAsB,CAAqB;IAGnD,OAAO,CAAC,cAAc,CAAwC;IAE9D,OAAO,CAAC,mBAAmB,CAAwC;IAMnE,OAAO,CAAC,kBAAkB,CAA0B;IAGpD,OAAO,CAAC,aAAa,CAA0B;IAS/C,OAAO,CAAC,mBAAmB,CAAqC;IAGhE,OAAO,CAAC,eAAe,CAA2C;IAElE,IAAI,SAAqB;IAEzB,OAAO,UAAS;IAEhB,UAAU,UAAS;IAEnB,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,GAAG,CAAC,EAAE,GAAG,CAAC;IAMV,UAAU,EAAE,KAAK,CAAC,UA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AE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IAgD5C,OAAO,CAAC,IAAI,EAAE,MAAM;IAY1B,SAAS,CAAC,uBAAuB,IAAI,iBAAiB;IAUtD,SAAS,CAAC,sBAAsB;cAIhB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,IAAI,CAAC;cAIA,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,UAAU,CAAC;cASN,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1F,SAAS,CAAC,8BAA8B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKrE,SAAS,CAAC,+BAA+B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK;IAWjF,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-web-device",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.147",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"lint:fix": "eslint . --fix"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.147",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.147"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.147",
|
|
29
29
|
"@types/w3c-web-usb": "^1.0.6",
|
|
30
30
|
"@types/web-bluetooth": "^0.0.17"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "a34e98865e6be227cf3e00d486146e6592761db0"
|
|
33
33
|
}
|
|
@@ -51,6 +51,10 @@ interface PacketProcessResult {
|
|
|
51
51
|
error?: string;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
function inferProtocolHintFromDeviceName(name?: string | null): ProtocolType | undefined {
|
|
55
|
+
return /\bpro\s*2\b/i.test(name ?? '') ? 'V2' : undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
54
58
|
const toBleDescriptor = (
|
|
55
59
|
device: { id: string; name: string | null },
|
|
56
60
|
protocolType?: ProtocolType
|
|
@@ -101,9 +105,6 @@ export default class ElectronBleTransport {
|
|
|
101
105
|
|
|
102
106
|
private deviceProtocolHints: Map<string, ProtocolType> = new Map();
|
|
103
107
|
|
|
104
|
-
/** Endpoints that answered a V2 probe in this transport lifetime. Survives disconnect. */
|
|
105
|
-
private confirmedProtocolV2 = new Set<string>();
|
|
106
|
-
|
|
107
108
|
private deviceMtus: Map<string, number> = new Map();
|
|
108
109
|
|
|
109
110
|
private devicePacketCapacities: Map<string, number> = new Map();
|
|
@@ -268,6 +269,10 @@ export default class ElectronBleTransport {
|
|
|
268
269
|
this.Log?.debug(`[Electron BLE] enumerate found ${devices.length} device(s):`);
|
|
269
270
|
for (const dev of devices) {
|
|
270
271
|
this.Log?.debug(`[Electron BLE] id="${dev.id}" name="${dev.name}"`);
|
|
272
|
+
const protocolHint = inferProtocolHintFromDeviceName(dev.name);
|
|
273
|
+
if (protocolHint) {
|
|
274
|
+
this.deviceProtocolHints.set(dev.id, protocolHint);
|
|
275
|
+
}
|
|
271
276
|
}
|
|
272
277
|
return devices.map(device => toBleDescriptor(device));
|
|
273
278
|
} catch (error) {
|
|
@@ -305,7 +310,9 @@ export default class ElectronBleTransport {
|
|
|
305
310
|
}
|
|
306
311
|
const protocolHint = expectedProtocol
|
|
307
312
|
? undefined
|
|
308
|
-
: input.protocolHint ??
|
|
313
|
+
: input.protocolHint ??
|
|
314
|
+
this.deviceProtocolHints.get(uuid) ??
|
|
315
|
+
inferProtocolHintFromDeviceName(device.name);
|
|
309
316
|
if (protocolHint) {
|
|
310
317
|
this.deviceProtocolHints.set(uuid, protocolHint);
|
|
311
318
|
}
|
|
@@ -435,12 +442,9 @@ export default class ElectronBleTransport {
|
|
|
435
442
|
}
|
|
436
443
|
}
|
|
437
444
|
|
|
438
|
-
private createProtocolMismatchError(expected: ProtocolType
|
|
439
|
-
// A generic Ping miss is not a bond failure. Only a later miss after this
|
|
440
|
-
// endpoint already answered V2, or a native encryption/pairing error, is.
|
|
441
|
-
const isStaleV2Bond = expected === 'V2' && this.confirmedProtocolV2.has(uuid);
|
|
445
|
+
private createProtocolMismatchError(expected: ProtocolType) {
|
|
442
446
|
return ERRORS.TypedError(
|
|
443
|
-
|
|
447
|
+
HardwareErrorCode.RuntimeError,
|
|
444
448
|
`Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`
|
|
445
449
|
);
|
|
446
450
|
}
|
|
@@ -469,17 +473,16 @@ export default class ElectronBleTransport {
|
|
|
469
473
|
this.Log?.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V1 (expected)`);
|
|
470
474
|
return 'V1';
|
|
471
475
|
}
|
|
472
|
-
throw this.createProtocolMismatchError(expectedProtocol
|
|
476
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
473
477
|
}
|
|
474
478
|
|
|
475
479
|
if (expectedProtocol === 'V2') {
|
|
476
480
|
if (await this.probeProtocolV2(uuid)) {
|
|
477
481
|
this.deviceProtocol.set(uuid, 'V2');
|
|
478
|
-
this.confirmedProtocolV2.add(uuid);
|
|
479
482
|
this.Log?.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V2 (expected)`);
|
|
480
483
|
return 'V2';
|
|
481
484
|
}
|
|
482
|
-
throw this.createProtocolMismatchError(expectedProtocol
|
|
485
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
483
486
|
}
|
|
484
487
|
|
|
485
488
|
// Protocol must be actively probed after connection. Name, PID, and descriptors only
|
|
@@ -498,9 +501,6 @@ export default class ElectronBleTransport {
|
|
|
498
501
|
protocol === 'V1' ? await this.probeProtocolV1(uuid) : await this.probeProtocolV2(uuid);
|
|
499
502
|
if (detected) {
|
|
500
503
|
this.deviceProtocol.set(uuid, protocol);
|
|
501
|
-
if (protocol === 'V2') {
|
|
502
|
-
this.confirmedProtocolV2.add(uuid);
|
|
503
|
-
}
|
|
504
504
|
this.Log?.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> ${protocol}`);
|
|
505
505
|
return protocol;
|
|
506
506
|
}
|
package/src/webusb.ts
CHANGED
|
@@ -14,9 +14,7 @@ import {
|
|
|
14
14
|
ERRORS,
|
|
15
15
|
HardwareErrorCode,
|
|
16
16
|
ONEKEY_WEBUSB_FILTER,
|
|
17
|
-
inferProtocolHintFromUsbId,
|
|
18
17
|
isKnownTrezorWebUsbDevice,
|
|
19
|
-
resolveOneKeyUsbDevicePath,
|
|
20
18
|
wait,
|
|
21
19
|
} from '@onekeyfe/hd-shared';
|
|
22
20
|
import ByteBuffer from 'bytebuffer';
|
|
@@ -47,6 +45,9 @@ const PACKET_IO_RETRY_DELAY = 300;
|
|
|
47
45
|
const PROTOCOL_V1_PROBE_TIMEOUT = 5000;
|
|
48
46
|
const PROTOCOL_V2_PROBE_TIMEOUT = 1000;
|
|
49
47
|
const EXPECTED_PROTOCOL_V2_PROBE_ATTEMPTS = 2;
|
|
48
|
+
function inferProtocolHintFromDeviceName(name?: string | null): ProtocolType | undefined {
|
|
49
|
+
return /\bpro\s*2\b/i.test(name ?? '') ? 'V2' : undefined;
|
|
50
|
+
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
53
|
* Device information with path and WebUSB device instance
|
|
@@ -83,10 +84,9 @@ function registerActiveWebUsbTransport(instance: WebUsbTransport, usb: USB) {
|
|
|
83
84
|
if (usbDisconnectListenerAttached) return;
|
|
84
85
|
usbDisconnectListenerAttached = true;
|
|
85
86
|
usb.addEventListener('disconnect', event => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
activeWebUsbTransport?.markProtocolStale(path);
|
|
87
|
+
const serial = event.device?.serialNumber;
|
|
88
|
+
if (typeof serial !== 'string' || serial.length === 0) return;
|
|
89
|
+
activeWebUsbTransport?.markProtocolStale(serial);
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -256,24 +256,22 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
256
256
|
(desc: { vendorId: number; productId: number }) =>
|
|
257
257
|
dev.vendorId === desc.vendorId && dev.productId === desc.productId
|
|
258
258
|
);
|
|
259
|
-
|
|
259
|
+
const hasSerialNumber = typeof dev.serialNumber === 'string' && dev.serialNumber.length > 0;
|
|
260
|
+
return isOneKey && hasSerialNumber && !isKnownTrezorWebUsbDevice(dev);
|
|
260
261
|
});
|
|
261
262
|
|
|
262
|
-
this.deviceList = onekeyDevices.
|
|
263
|
-
const path =
|
|
264
|
-
|
|
265
|
-
const protocolHint = inferProtocolHintFromUsbId(device.vendorId, device.productId);
|
|
263
|
+
this.deviceList = onekeyDevices.map(device => {
|
|
264
|
+
const path = device.serialNumber as string;
|
|
265
|
+
const protocolHint = inferProtocolHintFromDeviceName(device.productName);
|
|
266
266
|
if (protocolHint) {
|
|
267
267
|
this.deviceProtocolHints.set(path, protocolHint);
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
return
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
},
|
|
276
|
-
];
|
|
270
|
+
return {
|
|
271
|
+
path,
|
|
272
|
+
device,
|
|
273
|
+
commType: 'webusb',
|
|
274
|
+
};
|
|
277
275
|
});
|
|
278
276
|
|
|
279
277
|
return this.deviceList;
|
|
@@ -318,12 +316,13 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
318
316
|
this.deviceProtocol.delete(input.path);
|
|
319
317
|
}
|
|
320
318
|
if (!this.deviceProtocol.has(input.path)) {
|
|
321
|
-
const
|
|
319
|
+
const deviceName = this.deviceList.find(device => device.path === input.path)?.device
|
|
320
|
+
.productName;
|
|
322
321
|
const protocolHint = input.expectedProtocol
|
|
323
322
|
? undefined
|
|
324
323
|
: input.protocolHint ??
|
|
325
324
|
this.deviceProtocolHints.get(input.path) ??
|
|
326
|
-
|
|
325
|
+
inferProtocolHintFromDeviceName(deviceName);
|
|
327
326
|
if (protocolHint) {
|
|
328
327
|
this.deviceProtocolHints.set(input.path, protocolHint);
|
|
329
328
|
}
|