@onekeyfe/hd-transport-lowlevel 1.2.0-alpha.21 → 1.2.0-alpha.22
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__/protocol-v2.test.js +36 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -3
- package/package.json +4 -4
- package/src/index.ts +16 -6
|
@@ -172,7 +172,7 @@ describe('LowlevelTransport protocol framing', () => {
|
|
|
172
172
|
supported_messages: [60200, 60201, 60206, 60207],
|
|
173
173
|
protobuf_definition: 'onekey-protocol-v2',
|
|
174
174
|
},
|
|
175
|
-
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
175
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART, seq: 2 }
|
|
176
176
|
);
|
|
177
177
|
const plugin = createPlugin({
|
|
178
178
|
devices: [{ id: 'pro2-id', name: 'OneKey Pro 2', commType: 'ble' }],
|
|
@@ -253,15 +253,19 @@ describe('LowlevelTransport protocol framing', () => {
|
|
|
253
253
|
});
|
|
254
254
|
|
|
255
255
|
test('reuses the active generation when Core acquires the same BLE connection again', async () => {
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
const responses = [1, 2, 3, 4].map(seq =>
|
|
257
|
+
bytesToHex(
|
|
258
|
+
ProtocolV2.encodeFrame(
|
|
259
|
+
schemas,
|
|
260
|
+
'Success',
|
|
261
|
+
{ message: 'ok' },
|
|
262
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART, seq }
|
|
263
|
+
)
|
|
264
|
+
)
|
|
261
265
|
);
|
|
262
266
|
const plugin = createPlugin({
|
|
263
267
|
devices: [{ id: 'repeated-acquire-id', name: 'OneKey Pro 2', commType: 'ble' }],
|
|
264
|
-
responses
|
|
268
|
+
responses,
|
|
265
269
|
});
|
|
266
270
|
const lowlevel = configureTransport(plugin);
|
|
267
271
|
|
|
@@ -283,13 +287,19 @@ describe('LowlevelTransport protocol framing', () => {
|
|
|
283
287
|
const sentSeqs = plugin.send.mock.calls.map(([, hex]) =>
|
|
284
288
|
Number.parseInt(hex.slice(12, 14), 16)
|
|
285
289
|
);
|
|
286
|
-
expect(sentSeqs).toEqual([1, 2]);
|
|
290
|
+
expect(sentSeqs).toEqual([1, 2, 3, 4]);
|
|
287
291
|
});
|
|
288
292
|
|
|
289
|
-
test('
|
|
293
|
+
test('actively probes explicit Protocol V2 during bootloader reconnect', async () => {
|
|
294
|
+
const probeResponse = ProtocolV2.encodeFrame(
|
|
295
|
+
schemas,
|
|
296
|
+
'Success',
|
|
297
|
+
{ message: 'ok' },
|
|
298
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
299
|
+
);
|
|
290
300
|
const plugin = createPlugin({
|
|
291
301
|
devices: [{ id: 'bootloader-v2-id', name: 'OneKey Pro 2', commType: 'ble' }],
|
|
292
|
-
responses: [],
|
|
302
|
+
responses: [bytesToHex(probeResponse)],
|
|
293
303
|
});
|
|
294
304
|
const lowlevel = configureTransport(plugin);
|
|
295
305
|
|
|
@@ -299,8 +309,8 @@ describe('LowlevelTransport protocol framing', () => {
|
|
|
299
309
|
uuid: 'bootloader-v2-id',
|
|
300
310
|
protocolType: 'V2',
|
|
301
311
|
});
|
|
302
|
-
expect(plugin.send).
|
|
303
|
-
expect(plugin.receive).
|
|
312
|
+
expect(plugin.send).toHaveBeenCalledTimes(1);
|
|
313
|
+
expect(plugin.receive).toHaveBeenCalledTimes(1);
|
|
304
314
|
});
|
|
305
315
|
|
|
306
316
|
test('resets the lowlevel connection before probing Protocol V2 after a V1 timeout', async () => {
|
|
@@ -342,11 +352,23 @@ describe('LowlevelTransport protocol framing', () => {
|
|
|
342
352
|
});
|
|
343
353
|
|
|
344
354
|
test('disconnects a tainted Protocol V2 link after a response timeout', async () => {
|
|
355
|
+
const probeResponse = ProtocolV2.encodeFrame(
|
|
356
|
+
schemas,
|
|
357
|
+
'Success',
|
|
358
|
+
{ message: 'ok' },
|
|
359
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
360
|
+
);
|
|
345
361
|
const plugin = createPlugin({
|
|
346
362
|
devices: [{ id: 'timeout-v2-id', name: 'OneKey Pro 2', commType: 'ble' }],
|
|
347
|
-
responses: [],
|
|
363
|
+
responses: [bytesToHex(probeResponse)],
|
|
364
|
+
});
|
|
365
|
+
let receiveCount = 0;
|
|
366
|
+
plugin.receive.mockImplementation(() => {
|
|
367
|
+
receiveCount += 1;
|
|
368
|
+
return receiveCount === 1
|
|
369
|
+
? Promise.resolve(bytesToHex(probeResponse))
|
|
370
|
+
: new Promise(() => {});
|
|
348
371
|
});
|
|
349
|
-
plugin.receive.mockImplementation(() => new Promise(() => {}));
|
|
350
372
|
const lowlevel = configureTransport(plugin);
|
|
351
373
|
|
|
352
374
|
await lowlevel.acquire({ uuid: 'timeout-v2-id', expectedProtocol: 'V2' });
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,SAWN,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,cAAc,EACd,6BAA6B,EAC7B,YAAY,EACZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAUpD,wBAAgB,+BAA+B,CAAC,EAC9C,OAAO,EACP,iBAAiB,EACjB,GAAG,EACH,YAAY,GACb,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;CACtB,WAMA;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM;;cAEpD;AAcD,MAAM,CAAC,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ACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YAsBlB,cAAc;IA6E5B,OAAO,CAAC,0BAA0B;IAOlC,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;YAsDd,yBAAyB;YAiCzB,eAAe;YAgBf,eAAe;YA6Bf,UAAU;YAUV,qBAAqB;YAmBrB,mBAAmB;YAqBnB,oBAAoB;YAOpB,cAAc;IAwB5B,OAAO,CAAC,uBAAuB;IAkC/B,OAAO,CAAC,2BAA2B;IAMnC,MAAM;CAGP"}
|
package/dist/index.js
CHANGED
|
@@ -241,6 +241,15 @@ class LowlevelTransport {
|
|
|
241
241
|
return check.call(jsonData);
|
|
242
242
|
}
|
|
243
243
|
catch (e) {
|
|
244
|
+
if ((e === null || e === void 0 ? void 0 : e.errorCode) === hdShared.HardwareErrorCode.BleTimeoutError &&
|
|
245
|
+
(options === null || options === void 0 ? void 0 : options.timeoutMs) !== PROTOCOL_PROBE_TIMEOUT_MS) {
|
|
246
|
+
try {
|
|
247
|
+
yield this.resetConnectionAfterProbe(uuid, 'V1');
|
|
248
|
+
}
|
|
249
|
+
catch (resetError) {
|
|
250
|
+
this.Log.debug('[LowlevelTransport] reset after Protocol V1 timeout failed:', resetError);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
244
253
|
if (name === 'Initialize' && (options === null || options === void 0 ? void 0 : options.timeoutMs) === PROTOCOL_PROBE_TIMEOUT_MS) {
|
|
245
254
|
this.Log.debug('[LowlevelTransport] Protocol V1 Initialize probe call failed:', e);
|
|
246
255
|
}
|
|
@@ -269,9 +278,12 @@ class LowlevelTransport {
|
|
|
269
278
|
var _a, _b, _c, _d, _e, _f;
|
|
270
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
271
280
|
if (expectedProtocol === 'V2') {
|
|
272
|
-
this.
|
|
273
|
-
|
|
274
|
-
|
|
281
|
+
if (yield this.probeProtocolV2(uuid)) {
|
|
282
|
+
this.deviceProtocol.set(uuid, 'V2');
|
|
283
|
+
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug(`[LowlevelTransport] detectProtocol: uuid=${uuid} -> V2 (expected)`);
|
|
284
|
+
return 'V2';
|
|
285
|
+
}
|
|
286
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
275
287
|
}
|
|
276
288
|
if (expectedProtocol === 'V1') {
|
|
277
289
|
if (yield this.probeProtocolV1(uuid)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-lowlevel",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.22",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
23
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.22",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.22"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "ce94a5ebbe141b0c15db7c68d08085ca1ddb0166"
|
|
27
27
|
}
|
package/src/index.ts
CHANGED
|
@@ -285,6 +285,16 @@ export default class LowlevelTransport {
|
|
|
285
285
|
const jsonData = ProtocolV1.decodeMessage(messages, response);
|
|
286
286
|
return check.call(jsonData);
|
|
287
287
|
} catch (e) {
|
|
288
|
+
if (
|
|
289
|
+
e?.errorCode === HardwareErrorCode.BleTimeoutError &&
|
|
290
|
+
options?.timeoutMs !== PROTOCOL_PROBE_TIMEOUT_MS
|
|
291
|
+
) {
|
|
292
|
+
try {
|
|
293
|
+
await this.resetConnectionAfterProbe(uuid, 'V1');
|
|
294
|
+
} catch (resetError) {
|
|
295
|
+
this.Log.debug('[LowlevelTransport] reset after Protocol V1 timeout failed:', resetError);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
288
298
|
if (name === 'Initialize' && options?.timeoutMs === PROTOCOL_PROBE_TIMEOUT_MS) {
|
|
289
299
|
this.Log.debug('[LowlevelTransport] Protocol V1 Initialize probe call failed:', e);
|
|
290
300
|
} else {
|
|
@@ -327,12 +337,12 @@ export default class LowlevelTransport {
|
|
|
327
337
|
protocolHint?: ProtocolType
|
|
328
338
|
): Promise<ProtocolType> {
|
|
329
339
|
if (expectedProtocol === 'V2') {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
340
|
+
if (await this.probeProtocolV2(uuid)) {
|
|
341
|
+
this.deviceProtocol.set(uuid, 'V2');
|
|
342
|
+
this.Log?.debug(`[LowlevelTransport] detectProtocol: uuid=${uuid} -> V2 (expected)`);
|
|
343
|
+
return 'V2';
|
|
344
|
+
}
|
|
345
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
336
346
|
}
|
|
337
347
|
|
|
338
348
|
if (expectedProtocol === 'V1') {
|