@onekeyfe/hd-transport-web-device 1.2.0-alpha.144 → 1.2.0-alpha.146
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 +10 -10
- package/__tests__/webusb-protocol-cache.test.ts +1 -1
- package/__tests__/webusb-protocol-v2-timeout.test.ts +9 -3
- 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 +28 -44
- package/dist/webusb.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/electron-ble-transport.ts +4 -27
- package/src/webusb.ts +20 -19
|
@@ -456,7 +456,7 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
456
456
|
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
457
457
|
});
|
|
458
458
|
|
|
459
|
-
test('
|
|
459
|
+
test('keeps a second expected Protocol V2 probe miss retryable', async () => {
|
|
460
460
|
const device = { id: 'retry-pro2-id', name: 'OneKey Pro 2' };
|
|
461
461
|
const nobleBle = createNobleBle(device);
|
|
462
462
|
const transport = configureTransport(nobleBle);
|
|
@@ -470,7 +470,7 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
470
470
|
await expect(
|
|
471
471
|
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
472
472
|
).rejects.toMatchObject({
|
|
473
|
-
errorCode: HardwareErrorCode.
|
|
473
|
+
errorCode: HardwareErrorCode.RuntimeError,
|
|
474
474
|
});
|
|
475
475
|
|
|
476
476
|
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
@@ -497,7 +497,7 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
497
497
|
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
498
498
|
});
|
|
499
499
|
|
|
500
|
-
test('
|
|
500
|
+
test('does not take a Protocol V2 hint from the BLE name', async () => {
|
|
501
501
|
const device = { id: 'named-pro2-id', name: 'OneKey Pro 2' };
|
|
502
502
|
const nobleBle = createNobleBle(device);
|
|
503
503
|
let notificationHandler: ((deviceId: string, data: string) => void) | undefined;
|
|
@@ -527,15 +527,15 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
527
527
|
protocolType: 'V2',
|
|
528
528
|
})
|
|
529
529
|
);
|
|
530
|
-
expect(nobleBle.write).
|
|
530
|
+
expect(nobleBle.write.mock.calls.length).toBeGreaterThan(1);
|
|
531
531
|
expect(transport.getProtocolType(device.id)).toBe('V2');
|
|
532
532
|
await expect(transport.call(device.id, 'Ping', { message: 'after-probe' })).resolves.toEqual({
|
|
533
533
|
type: 'Success',
|
|
534
534
|
message: { message: 'ok' },
|
|
535
535
|
});
|
|
536
|
-
const sentSeqs = nobleBle.write.mock.calls
|
|
537
|
-
Number.parseInt(hex.slice(12, 14), 16)
|
|
538
|
-
|
|
536
|
+
const sentSeqs = nobleBle.write.mock.calls
|
|
537
|
+
.map(([, hex]) => Number.parseInt(hex.slice(12, 14), 16))
|
|
538
|
+
.filter(seq => seq > 0);
|
|
539
539
|
expect(sentSeqs).toEqual([1, 2]);
|
|
540
540
|
} finally {
|
|
541
541
|
await transport.release(device.id);
|
|
@@ -615,9 +615,9 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
615
615
|
message: { message: 'ok' },
|
|
616
616
|
});
|
|
617
617
|
|
|
618
|
-
const sentSeqs = nobleBle.write.mock.calls
|
|
619
|
-
Number.parseInt(hex.slice(12, 14), 16)
|
|
620
|
-
|
|
618
|
+
const sentSeqs = nobleBle.write.mock.calls
|
|
619
|
+
.map(([, hex]) => Number.parseInt(hex.slice(12, 14), 16))
|
|
620
|
+
.filter(seq => seq > 0);
|
|
621
621
|
expect(sentSeqs).toEqual([1, 2, 3]);
|
|
622
622
|
} finally {
|
|
623
623
|
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 device identity are ignored.
|
|
234
234
|
handler({ device: { serialNumber: null } });
|
|
235
235
|
handler({});
|
|
236
236
|
expect(second.staleProtocolPaths.size).toBe(1);
|
|
@@ -21,8 +21,9 @@ const schema = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
describe('WebUsbTransport Protocol V2 timeout recovery', () => {
|
|
24
|
-
test('
|
|
25
|
-
const filter =
|
|
24
|
+
test('enumerates OneKey USB devices even when the serial string is omitted', async () => {
|
|
25
|
+
const filter =
|
|
26
|
+
ONEKEY_WEBUSB_FILTER.find(item => item.productId === 0x4f4c) ?? ONEKEY_WEBUSB_FILTER[0];
|
|
26
27
|
const deviceWithSerial = {
|
|
27
28
|
...filter,
|
|
28
29
|
manufacturerName: 'OneKey',
|
|
@@ -32,7 +33,7 @@ describe('WebUsbTransport Protocol V2 timeout recovery', () => {
|
|
|
32
33
|
const deviceWithoutSerial = {
|
|
33
34
|
...filter,
|
|
34
35
|
manufacturerName: 'OneKey',
|
|
35
|
-
productName: 'OneKey
|
|
36
|
+
productName: 'OneKey Neo',
|
|
36
37
|
serialNumber: null,
|
|
37
38
|
} as USBDevice;
|
|
38
39
|
const webusb = new WebUsbTransport();
|
|
@@ -46,6 +47,11 @@ describe('WebUsbTransport Protocol V2 timeout recovery', () => {
|
|
|
46
47
|
device: deviceWithSerial,
|
|
47
48
|
commType: 'webusb',
|
|
48
49
|
},
|
|
50
|
+
{
|
|
51
|
+
path: 'usb-1209-4f4c-onekey-neo',
|
|
52
|
+
device: deviceWithoutSerial,
|
|
53
|
+
commType: 'webusb',
|
|
54
|
+
},
|
|
49
55
|
]);
|
|
50
56
|
});
|
|
51
57
|
|
|
@@ -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,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EAEZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAIvC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,UAAU,CAAC;KACzB;CACF;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;
|
|
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,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EAEZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAIvC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,UAAU,CAAC;KACzB;CACF;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAiCF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,OAAO,CAAC,SAAS,CAA0D;IAE3E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AAO,EAAE,WAAW,CAAC,EAAE,OAAO;IAY7D,UAAU,CAAC,EAAE,EAAE,MAAM;YAKb,aAAa;YAiBb,cAAc;IAwB5B,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;IAoD5B,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
|
@@ -212,8 +212,6 @@ declare class ElectronBleTransport {
|
|
|
212
212
|
private deviceProtocolHints;
|
|
213
213
|
/** Endpoints that answered a V2 probe in this transport lifetime. Survives disconnect. */
|
|
214
214
|
private confirmedProtocolV2;
|
|
215
|
-
/** First expected-V2 miss for an unconfirmed endpoint; the next miss is a stale bond. */
|
|
216
|
-
private retryableV2Mismatch;
|
|
217
215
|
private deviceMtus;
|
|
218
216
|
private devicePacketCapacities;
|
|
219
217
|
private v1Buffers;
|
package/dist/index.js
CHANGED
|
@@ -54,9 +54,6 @@ 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
|
-
}
|
|
60
57
|
let activeWebUsbTransport;
|
|
61
58
|
let usbDisconnectListenerAttached = false;
|
|
62
59
|
function registerActiveWebUsbTransport(instance, usb) {
|
|
@@ -65,11 +62,12 @@ function registerActiveWebUsbTransport(instance, usb) {
|
|
|
65
62
|
return;
|
|
66
63
|
usbDisconnectListenerAttached = true;
|
|
67
64
|
usb.addEventListener('disconnect', event => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
if (!event.device)
|
|
66
|
+
return;
|
|
67
|
+
const path = hdShared.resolveOneKeyUsbDevicePath(event.device);
|
|
68
|
+
if (!path)
|
|
71
69
|
return;
|
|
72
|
-
activeWebUsbTransport === null || activeWebUsbTransport === void 0 ? void 0 : activeWebUsbTransport.markProtocolStale(
|
|
70
|
+
activeWebUsbTransport === null || activeWebUsbTransport === void 0 ? void 0 : activeWebUsbTransport.markProtocolStale(path);
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
73
|
class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
@@ -152,20 +150,23 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
152
150
|
const devices = yield this.usb.getDevices();
|
|
153
151
|
const onekeyDevices = devices.filter(dev => {
|
|
154
152
|
const isOneKey = hdShared.ONEKEY_WEBUSB_FILTER.some((desc) => dev.vendorId === desc.vendorId && dev.productId === desc.productId);
|
|
155
|
-
|
|
156
|
-
return isOneKey && hasSerialNumber && !hdShared.isKnownTrezorWebUsbDevice(dev);
|
|
153
|
+
return isOneKey && !hdShared.isKnownTrezorWebUsbDevice(dev);
|
|
157
154
|
});
|
|
158
|
-
this.deviceList = onekeyDevices.
|
|
159
|
-
const path = device
|
|
160
|
-
|
|
155
|
+
this.deviceList = onekeyDevices.flatMap(device => {
|
|
156
|
+
const path = hdShared.resolveOneKeyUsbDevicePath(device);
|
|
157
|
+
if (!path)
|
|
158
|
+
return [];
|
|
159
|
+
const protocolHint = hdShared.inferProtocolHintFromUsbId(device.vendorId, device.productId);
|
|
161
160
|
if (protocolHint) {
|
|
162
161
|
this.deviceProtocolHints.set(path, protocolHint);
|
|
163
162
|
}
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
return [
|
|
164
|
+
{
|
|
165
|
+
path,
|
|
166
|
+
device,
|
|
167
|
+
commType: 'webusb',
|
|
168
|
+
},
|
|
169
|
+
];
|
|
169
170
|
});
|
|
170
171
|
return this.deviceList;
|
|
171
172
|
});
|
|
@@ -199,10 +200,10 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
199
200
|
this.deviceProtocol.delete(input.path);
|
|
200
201
|
}
|
|
201
202
|
if (!this.deviceProtocol.has(input.path)) {
|
|
202
|
-
const
|
|
203
|
+
const usbDevice = (_c = this.deviceList.find(device => device.path === input.path)) === null || _c === void 0 ? void 0 : _c.device;
|
|
203
204
|
const protocolHint = input.expectedProtocol
|
|
204
205
|
? undefined
|
|
205
|
-
: (_e = (_d = input.protocolHint) !== null && _d !== void 0 ? _d : this.deviceProtocolHints.get(input.path)) !== null && _e !== void 0 ? _e :
|
|
206
|
+
: (_e = (_d = input.protocolHint) !== null && _d !== void 0 ? _d : this.deviceProtocolHints.get(input.path)) !== null && _e !== void 0 ? _e : hdShared.inferProtocolHintFromUsbId(usbDevice === null || usbDevice === void 0 ? void 0 : usbDevice.vendorId, usbDevice === null || usbDevice === void 0 ? void 0 : usbDevice.productId);
|
|
206
207
|
if (protocolHint) {
|
|
207
208
|
this.deviceProtocolHints.set(input.path, protocolHint);
|
|
208
209
|
}
|
|
@@ -792,9 +793,6 @@ function resolveBlePacketCapacity(mtu, maximumPacketCapacity, fallbackPacketCapa
|
|
|
792
793
|
}
|
|
793
794
|
|
|
794
795
|
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
|
-
}
|
|
798
796
|
const toBleDescriptor = (device, protocolType) => (Object.assign({ id: device.id, name: device.name, path: device.id, debug: false, commType: 'electron-ble' }, (protocolType ? { protocolType } : {})));
|
|
799
797
|
const BLE_PACKET_SIZE_FALLBACK = 192;
|
|
800
798
|
const BLE_PACKET_SIZE_MAXIMUM = 244;
|
|
@@ -811,7 +809,6 @@ class ElectronBleTransport {
|
|
|
811
809
|
this.deviceProtocol = new Map();
|
|
812
810
|
this.deviceProtocolHints = new Map();
|
|
813
811
|
this.confirmedProtocolV2 = new Set();
|
|
814
|
-
this.retryableV2Mismatch = new Set();
|
|
815
812
|
this.deviceMtus = new Map();
|
|
816
813
|
this.devicePacketCapacities = new Map();
|
|
817
814
|
this.v1Buffers = new Map();
|
|
@@ -951,10 +948,6 @@ class ElectronBleTransport {
|
|
|
951
948
|
(_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug(`[Electron BLE] enumerate found ${devices.length} device(s):`);
|
|
952
949
|
for (const dev of devices) {
|
|
953
950
|
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[Electron BLE] id="${dev.id}" name="${dev.name}"`);
|
|
954
|
-
const protocolHint = inferProtocolHintFromDeviceName(dev.name);
|
|
955
|
-
if (protocolHint) {
|
|
956
|
-
this.deviceProtocolHints.set(dev.id, protocolHint);
|
|
957
|
-
}
|
|
958
951
|
}
|
|
959
952
|
return devices.map(device => toBleDescriptor(device));
|
|
960
953
|
}
|
|
@@ -965,7 +958,7 @@ class ElectronBleTransport {
|
|
|
965
958
|
});
|
|
966
959
|
}
|
|
967
960
|
acquire(input) {
|
|
968
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
961
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
969
962
|
return __awaiter(this, void 0, void 0, function* () {
|
|
970
963
|
const { uuid, forceCleanRunPromise, expectedProtocol } = input;
|
|
971
964
|
if (!uuid) {
|
|
@@ -990,7 +983,7 @@ class ElectronBleTransport {
|
|
|
990
983
|
}
|
|
991
984
|
const protocolHint = expectedProtocol
|
|
992
985
|
? undefined
|
|
993
|
-
: (
|
|
986
|
+
: (_b = input.protocolHint) !== null && _b !== void 0 ? _b : this.deviceProtocolHints.get(uuid);
|
|
994
987
|
if (protocolHint) {
|
|
995
988
|
this.deviceProtocolHints.set(uuid, protocolHint);
|
|
996
989
|
}
|
|
@@ -1014,10 +1007,10 @@ class ElectronBleTransport {
|
|
|
1014
1007
|
const connectionToken = this.notificationTokens.get(uuid);
|
|
1015
1008
|
const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint);
|
|
1016
1009
|
if (protocolType === 'V2') {
|
|
1017
|
-
(
|
|
1010
|
+
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug('[Electron BLE] Protocol V2 write configured', {
|
|
1018
1011
|
writeMode: 'withoutResponse',
|
|
1019
1012
|
negotiatedMtu: this.deviceMtus.get(uuid),
|
|
1020
|
-
packetCapacity: (
|
|
1013
|
+
packetCapacity: (_d = this.devicePacketCapacities.get(uuid)) !== null && _d !== void 0 ? _d : BLE_PACKET_SIZE_FALLBACK,
|
|
1021
1014
|
});
|
|
1022
1015
|
}
|
|
1023
1016
|
const disconnectCleanup = window.desktopApi.nobleBle.onDeviceDisconnected((disconnectedDevice) => {
|
|
@@ -1036,15 +1029,15 @@ class ElectronBleTransport {
|
|
|
1036
1029
|
return Object.assign(Object.assign({}, toBleDescriptor({ id: device.id, name: device.name }, protocolType)), { uuid });
|
|
1037
1030
|
}
|
|
1038
1031
|
catch (error) {
|
|
1039
|
-
(
|
|
1032
|
+
(_e = this.Log) === null || _e === void 0 ? void 0 : _e.error('[Electron BLE] acquire failed:', error);
|
|
1040
1033
|
try {
|
|
1041
|
-
if (((
|
|
1034
|
+
if (((_f = window.desktopApi) === null || _f === void 0 ? void 0 : _f.nobleBle) && this.connectedDevices.has(uuid)) {
|
|
1042
1035
|
yield window.desktopApi.nobleBle.unsubscribe(uuid);
|
|
1043
1036
|
yield window.desktopApi.nobleBle.disconnect(uuid);
|
|
1044
1037
|
}
|
|
1045
1038
|
}
|
|
1046
1039
|
catch (cleanupError) {
|
|
1047
|
-
(
|
|
1040
|
+
(_g = this.Log) === null || _g === void 0 ? void 0 : _g.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
|
|
1048
1041
|
}
|
|
1049
1042
|
this.cleanupDeviceState(uuid);
|
|
1050
1043
|
throw error;
|
|
@@ -1112,14 +1105,7 @@ class ElectronBleTransport {
|
|
|
1112
1105
|
});
|
|
1113
1106
|
}
|
|
1114
1107
|
createProtocolMismatchError(expected, uuid) {
|
|
1115
|
-
const isStaleV2Bond = expected === 'V2' &&
|
|
1116
|
-
(this.confirmedProtocolV2.has(uuid) || this.retryableV2Mismatch.has(uuid));
|
|
1117
|
-
if (expected === 'V2' && !isStaleV2Bond) {
|
|
1118
|
-
this.retryableV2Mismatch.add(uuid);
|
|
1119
|
-
}
|
|
1120
|
-
else if (isStaleV2Bond) {
|
|
1121
|
-
this.retryableV2Mismatch.delete(uuid);
|
|
1122
|
-
}
|
|
1108
|
+
const isStaleV2Bond = expected === 'V2' && this.confirmedProtocolV2.has(uuid);
|
|
1123
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`);
|
|
1124
1110
|
}
|
|
1125
1111
|
createProtocolDetectionError() {
|
|
@@ -1145,7 +1131,6 @@ class ElectronBleTransport {
|
|
|
1145
1131
|
if (yield this.probeProtocolV2(uuid)) {
|
|
1146
1132
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1147
1133
|
this.confirmedProtocolV2.add(uuid);
|
|
1148
|
-
this.retryableV2Mismatch.delete(uuid);
|
|
1149
1134
|
(_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V2 (expected)`);
|
|
1150
1135
|
return 'V2';
|
|
1151
1136
|
}
|
|
@@ -1162,7 +1147,6 @@ class ElectronBleTransport {
|
|
|
1162
1147
|
this.deviceProtocol.set(uuid, protocol);
|
|
1163
1148
|
if (protocol === 'V2') {
|
|
1164
1149
|
this.confirmedProtocolV2.add(uuid);
|
|
1165
|
-
this.retryableV2Mismatch.delete(uuid);
|
|
1166
1150
|
}
|
|
1167
1151
|
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> ${protocol}`);
|
|
1168
1152
|
return protocol;
|
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;AAYhC,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EAC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,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.146",
|
|
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.146",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.146"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.146",
|
|
29
29
|
"@types/w3c-web-usb": "^1.0.6",
|
|
30
30
|
"@types/web-bluetooth": "^0.0.17"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "447f0806b061695326a6dcba63d8c228b871d01a"
|
|
33
33
|
}
|
|
@@ -51,10 +51,6 @@ 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
|
-
|
|
58
54
|
const toBleDescriptor = (
|
|
59
55
|
device: { id: string; name: string | null },
|
|
60
56
|
protocolType?: ProtocolType
|
|
@@ -108,9 +104,6 @@ export default class ElectronBleTransport {
|
|
|
108
104
|
/** Endpoints that answered a V2 probe in this transport lifetime. Survives disconnect. */
|
|
109
105
|
private confirmedProtocolV2 = new Set<string>();
|
|
110
106
|
|
|
111
|
-
/** First expected-V2 miss for an unconfirmed endpoint; the next miss is a stale bond. */
|
|
112
|
-
private retryableV2Mismatch = new Set<string>();
|
|
113
|
-
|
|
114
107
|
private deviceMtus: Map<string, number> = new Map();
|
|
115
108
|
|
|
116
109
|
private devicePacketCapacities: Map<string, number> = new Map();
|
|
@@ -275,10 +268,6 @@ export default class ElectronBleTransport {
|
|
|
275
268
|
this.Log?.debug(`[Electron BLE] enumerate found ${devices.length} device(s):`);
|
|
276
269
|
for (const dev of devices) {
|
|
277
270
|
this.Log?.debug(`[Electron BLE] id="${dev.id}" name="${dev.name}"`);
|
|
278
|
-
const protocolHint = inferProtocolHintFromDeviceName(dev.name);
|
|
279
|
-
if (protocolHint) {
|
|
280
|
-
this.deviceProtocolHints.set(dev.id, protocolHint);
|
|
281
|
-
}
|
|
282
271
|
}
|
|
283
272
|
return devices.map(device => toBleDescriptor(device));
|
|
284
273
|
} catch (error) {
|
|
@@ -316,9 +305,7 @@ export default class ElectronBleTransport {
|
|
|
316
305
|
}
|
|
317
306
|
const protocolHint = expectedProtocol
|
|
318
307
|
? undefined
|
|
319
|
-
: input.protocolHint ??
|
|
320
|
-
this.deviceProtocolHints.get(uuid) ??
|
|
321
|
-
inferProtocolHintFromDeviceName(device.name);
|
|
308
|
+
: input.protocolHint ?? this.deviceProtocolHints.get(uuid);
|
|
322
309
|
if (protocolHint) {
|
|
323
310
|
this.deviceProtocolHints.set(uuid, protocolHint);
|
|
324
311
|
}
|
|
@@ -449,17 +436,9 @@ export default class ElectronBleTransport {
|
|
|
449
436
|
}
|
|
450
437
|
|
|
451
438
|
private createProtocolMismatchError(expected: ProtocolType, uuid: string) {
|
|
452
|
-
//
|
|
453
|
-
//
|
|
454
|
-
|
|
455
|
-
const isStaleV2Bond =
|
|
456
|
-
expected === 'V2' &&
|
|
457
|
-
(this.confirmedProtocolV2.has(uuid) || this.retryableV2Mismatch.has(uuid));
|
|
458
|
-
if (expected === 'V2' && !isStaleV2Bond) {
|
|
459
|
-
this.retryableV2Mismatch.add(uuid);
|
|
460
|
-
} else if (isStaleV2Bond) {
|
|
461
|
-
this.retryableV2Mismatch.delete(uuid);
|
|
462
|
-
}
|
|
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);
|
|
463
442
|
return ERRORS.TypedError(
|
|
464
443
|
isStaleV2Bond ? HardwareErrorCode.BleDeviceBondError : HardwareErrorCode.RuntimeError,
|
|
465
444
|
`Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`
|
|
@@ -497,7 +476,6 @@ export default class ElectronBleTransport {
|
|
|
497
476
|
if (await this.probeProtocolV2(uuid)) {
|
|
498
477
|
this.deviceProtocol.set(uuid, 'V2');
|
|
499
478
|
this.confirmedProtocolV2.add(uuid);
|
|
500
|
-
this.retryableV2Mismatch.delete(uuid);
|
|
501
479
|
this.Log?.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V2 (expected)`);
|
|
502
480
|
return 'V2';
|
|
503
481
|
}
|
|
@@ -522,7 +500,6 @@ export default class ElectronBleTransport {
|
|
|
522
500
|
this.deviceProtocol.set(uuid, protocol);
|
|
523
501
|
if (protocol === 'V2') {
|
|
524
502
|
this.confirmedProtocolV2.add(uuid);
|
|
525
|
-
this.retryableV2Mismatch.delete(uuid);
|
|
526
503
|
}
|
|
527
504
|
this.Log?.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> ${protocol}`);
|
|
528
505
|
return protocol;
|
package/src/webusb.ts
CHANGED
|
@@ -14,7 +14,9 @@ import {
|
|
|
14
14
|
ERRORS,
|
|
15
15
|
HardwareErrorCode,
|
|
16
16
|
ONEKEY_WEBUSB_FILTER,
|
|
17
|
+
inferProtocolHintFromUsbId,
|
|
17
18
|
isKnownTrezorWebUsbDevice,
|
|
19
|
+
resolveOneKeyUsbDevicePath,
|
|
18
20
|
wait,
|
|
19
21
|
} from '@onekeyfe/hd-shared';
|
|
20
22
|
import ByteBuffer from 'bytebuffer';
|
|
@@ -45,9 +47,6 @@ const PACKET_IO_RETRY_DELAY = 300;
|
|
|
45
47
|
const PROTOCOL_V1_PROBE_TIMEOUT = 5000;
|
|
46
48
|
const PROTOCOL_V2_PROBE_TIMEOUT = 1000;
|
|
47
49
|
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
|
-
}
|
|
51
50
|
|
|
52
51
|
/**
|
|
53
52
|
* Device information with path and WebUSB device instance
|
|
@@ -84,9 +83,10 @@ function registerActiveWebUsbTransport(instance: WebUsbTransport, usb: USB) {
|
|
|
84
83
|
if (usbDisconnectListenerAttached) return;
|
|
85
84
|
usbDisconnectListenerAttached = true;
|
|
86
85
|
usb.addEventListener('disconnect', event => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
if (!event.device) return;
|
|
87
|
+
const path = resolveOneKeyUsbDevicePath(event.device);
|
|
88
|
+
if (!path) return;
|
|
89
|
+
activeWebUsbTransport?.markProtocolStale(path);
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -256,22 +256,24 @@ 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
|
-
|
|
260
|
-
return isOneKey && hasSerialNumber && !isKnownTrezorWebUsbDevice(dev);
|
|
259
|
+
return isOneKey && !isKnownTrezorWebUsbDevice(dev);
|
|
261
260
|
});
|
|
262
261
|
|
|
263
|
-
this.deviceList = onekeyDevices.
|
|
264
|
-
const path = device
|
|
265
|
-
|
|
262
|
+
this.deviceList = onekeyDevices.flatMap(device => {
|
|
263
|
+
const path = resolveOneKeyUsbDevicePath(device);
|
|
264
|
+
if (!path) return [];
|
|
265
|
+
const protocolHint = inferProtocolHintFromUsbId(device.vendorId, device.productId);
|
|
266
266
|
if (protocolHint) {
|
|
267
267
|
this.deviceProtocolHints.set(path, protocolHint);
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
return
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
270
|
+
return [
|
|
271
|
+
{
|
|
272
|
+
path,
|
|
273
|
+
device,
|
|
274
|
+
commType: 'webusb',
|
|
275
|
+
},
|
|
276
|
+
];
|
|
275
277
|
});
|
|
276
278
|
|
|
277
279
|
return this.deviceList;
|
|
@@ -316,13 +318,12 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
316
318
|
this.deviceProtocol.delete(input.path);
|
|
317
319
|
}
|
|
318
320
|
if (!this.deviceProtocol.has(input.path)) {
|
|
319
|
-
const
|
|
320
|
-
.productName;
|
|
321
|
+
const usbDevice = this.deviceList.find(device => device.path === input.path)?.device;
|
|
321
322
|
const protocolHint = input.expectedProtocol
|
|
322
323
|
? undefined
|
|
323
324
|
: input.protocolHint ??
|
|
324
325
|
this.deviceProtocolHints.get(input.path) ??
|
|
325
|
-
|
|
326
|
+
inferProtocolHintFromUsbId(usbDevice?.vendorId, usbDevice?.productId);
|
|
326
327
|
if (protocolHint) {
|
|
327
328
|
this.deviceProtocolHints.set(input.path, protocolHint);
|
|
328
329
|
}
|