@onekeyfe/hd-transport-web-device 1.2.0-alpha.170 → 1.2.0-alpha.172
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__/webusb-protocol-cache.test.ts +16 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -1
- package/dist/webusb.d.ts +1 -0
- package/dist/webusb.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/webusb.ts +15 -1
|
@@ -69,10 +69,11 @@ describe('WebUsbTransport protocol probe cache', () => {
|
|
|
69
69
|
expect(webusb.detectProtocol).toHaveBeenCalledWith(path, 'V1', undefined);
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
test('acquire
|
|
72
|
+
test('acquire reuses a previously confirmed protocol during explicit no-probe recovery', async () => {
|
|
73
73
|
const webusb = buildAcquirableTransport();
|
|
74
74
|
const path = 'pro-webusb';
|
|
75
75
|
webusb.deviceProtocol.set(path, 'V1');
|
|
76
|
+
webusb.confirmedDeviceProtocols.set(path, 'V2');
|
|
76
77
|
webusb.markProtocolStale(path);
|
|
77
78
|
webusb.detectProtocol = jest.fn();
|
|
78
79
|
|
|
@@ -86,6 +87,20 @@ describe('WebUsbTransport protocol probe cache', () => {
|
|
|
86
87
|
expect(webusb.acquiredPaths.has(path)).toBe(true);
|
|
87
88
|
});
|
|
88
89
|
|
|
90
|
+
test('acquire rejects no-probe recovery without a previously confirmed protocol', async () => {
|
|
91
|
+
const webusb = buildAcquirableTransport();
|
|
92
|
+
const path = 'pro-webusb';
|
|
93
|
+
webusb.detectProtocol = jest.fn();
|
|
94
|
+
|
|
95
|
+
await expect(
|
|
96
|
+
webusb.acquire({ path, expectedProtocol: 'V2', skipProtocolProbe: true })
|
|
97
|
+
).rejects.toThrow('previously confirmed protocol');
|
|
98
|
+
|
|
99
|
+
expect(webusb.detectProtocol).not.toHaveBeenCalled();
|
|
100
|
+
expect(webusb.deviceProtocol.has(path)).toBe(false);
|
|
101
|
+
expect(webusb.acquiredPaths.has(path)).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
89
104
|
test('forced protocol detection bypasses a valid cache and probes on the wire', async () => {
|
|
90
105
|
const webusb = buildAcquirableTransport();
|
|
91
106
|
const path = 'pro-webusb';
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ declare class WebUsbTransport extends ProtocolV2UsbTransportBase<string> {
|
|
|
19
19
|
private protocolV2SchemaSource;
|
|
20
20
|
/** Per-path protocol type detected by active wire-level probe. */
|
|
21
21
|
private deviceProtocol;
|
|
22
|
+
/** Protocols previously confirmed by an active response for this transport instance. */
|
|
23
|
+
private confirmedDeviceProtocols;
|
|
22
24
|
private deviceProtocolHints;
|
|
23
25
|
/**
|
|
24
26
|
* Paths whose cached protocol must be re-probed on the next acquire (a USB
|
package/dist/index.js
CHANGED
|
@@ -79,6 +79,7 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
79
79
|
logPrefix: 'ProtocolV2 WebUSB',
|
|
80
80
|
});
|
|
81
81
|
this.deviceProtocol = new Map();
|
|
82
|
+
this.confirmedDeviceProtocols = new Map();
|
|
82
83
|
this.deviceProtocolHints = new Map();
|
|
83
84
|
this.staleProtocolPaths = new Set();
|
|
84
85
|
this.acquiredPaths = new Set();
|
|
@@ -194,6 +195,9 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
194
195
|
if (!input.expectedProtocol) {
|
|
195
196
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires an expected protocol');
|
|
196
197
|
}
|
|
198
|
+
if (this.confirmedDeviceProtocols.get(input.path) !== input.expectedProtocol) {
|
|
199
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires a previously confirmed protocol for this WebUSB endpoint');
|
|
200
|
+
}
|
|
197
201
|
this.staleProtocolPaths.delete(input.path);
|
|
198
202
|
this.deviceProtocol.set(input.path, input.expectedProtocol);
|
|
199
203
|
const currentDevice = (_b = this.deviceList.find(d => d.path === input.path)) === null || _b === void 0 ? void 0 : _b.device;
|
|
@@ -231,7 +235,8 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
231
235
|
if (protocolHint) {
|
|
232
236
|
this.deviceProtocolHints.set(input.path, protocolHint);
|
|
233
237
|
}
|
|
234
|
-
yield this.detectProtocol(input.path, input.expectedProtocol, protocolHint);
|
|
238
|
+
const detectedProtocol = yield this.detectProtocol(input.path, input.expectedProtocol, protocolHint);
|
|
239
|
+
this.confirmedDeviceProtocols.set(input.path, detectedProtocol);
|
|
235
240
|
const probedDevice = (_g = this.deviceList.find(d => d.path === input.path)) === null || _g === void 0 ? void 0 : _g.device;
|
|
236
241
|
if (probedDevice) {
|
|
237
242
|
this.probedDeviceObjects.set(input.path, probedDevice);
|
package/dist/webusb.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
13
13
|
messagesV2: ReturnType<typeof transport.parseConfigure> | undefined;
|
|
14
14
|
private protocolV2SchemaSource;
|
|
15
15
|
private deviceProtocol;
|
|
16
|
+
private confirmedDeviceProtocols;
|
|
16
17
|
private deviceProtocolHints;
|
|
17
18
|
private staleProtocolPaths;
|
|
18
19
|
private acquiredPaths;
|
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,EAG3B,MAAM,wBAAwB,CAAC;AAYhC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAuBhC,MAAM,WAAW,UA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-transport-web-device",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.172",
|
|
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.172",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.172"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.172",
|
|
29
29
|
"@types/w3c-web-usb": "^1.0.6",
|
|
30
30
|
"@types/web-bluetooth": "^0.0.17"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "4c6c4a4fcc52bcdd0b3ec9c36454b2074fa17a8c"
|
|
33
33
|
}
|
package/src/webusb.ts
CHANGED
|
@@ -107,6 +107,9 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
107
107
|
/** Per-path protocol type detected by active wire-level probe. */
|
|
108
108
|
private deviceProtocol: Map<string, ProtocolType> = new Map();
|
|
109
109
|
|
|
110
|
+
/** Protocols previously confirmed by an active response for this transport instance. */
|
|
111
|
+
private confirmedDeviceProtocols: Map<string, ProtocolType> = new Map();
|
|
112
|
+
|
|
110
113
|
private deviceProtocolHints: Map<string, ProtocolType> = new Map();
|
|
111
114
|
|
|
112
115
|
/**
|
|
@@ -316,6 +319,12 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
316
319
|
'skipProtocolProbe requires an expected protocol'
|
|
317
320
|
);
|
|
318
321
|
}
|
|
322
|
+
if (this.confirmedDeviceProtocols.get(input.path) !== input.expectedProtocol) {
|
|
323
|
+
throw ERRORS.TypedError(
|
|
324
|
+
HardwareErrorCode.RuntimeError,
|
|
325
|
+
'skipProtocolProbe requires a previously confirmed protocol for this WebUSB endpoint'
|
|
326
|
+
);
|
|
327
|
+
}
|
|
319
328
|
this.staleProtocolPaths.delete(input.path);
|
|
320
329
|
this.deviceProtocol.set(input.path, input.expectedProtocol);
|
|
321
330
|
const currentDevice = this.deviceList.find(d => d.path === input.path)?.device;
|
|
@@ -366,7 +375,12 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
366
375
|
if (protocolHint) {
|
|
367
376
|
this.deviceProtocolHints.set(input.path, protocolHint);
|
|
368
377
|
}
|
|
369
|
-
await this.detectProtocol(
|
|
378
|
+
const detectedProtocol = await this.detectProtocol(
|
|
379
|
+
input.path,
|
|
380
|
+
input.expectedProtocol,
|
|
381
|
+
protocolHint
|
|
382
|
+
);
|
|
383
|
+
this.confirmedDeviceProtocols.set(input.path, detectedProtocol);
|
|
370
384
|
const probedDevice = this.deviceList.find(d => d.path === input.path)?.device;
|
|
371
385
|
if (probedDevice) {
|
|
372
386
|
this.probedDeviceObjects.set(input.path, probedDevice);
|