@onekeyfe/hd-transport-lowlevel 1.2.0-alpha.145 → 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.
@@ -249,11 +249,7 @@ describe('LowlevelTransport protocol framing', () => {
249
249
  );
250
250
  const plugin = createPlugin({
251
251
  devices: [{ id: 'pro2-id', name: 'OneKey Pro 2', commType: 'ble' }],
252
- responses: [
253
- new Error('Protocol V1 probe timed out'),
254
- ...splitFrame(probeResponse, 4),
255
- ...splitFrame(callResponse, 5),
256
- ],
252
+ responses: [...splitFrame(probeResponse, 4), ...splitFrame(callResponse, 5)],
257
253
  });
258
254
  const lowlevel = configureTransport(plugin);
259
255
 
@@ -273,9 +269,9 @@ describe('LowlevelTransport protocol framing', () => {
273
269
  },
274
270
  });
275
271
  expect(plugin.send).toHaveBeenCalled();
276
- const sentSeqs = plugin.send.mock.calls
277
- .map(([, hex]) => Number.parseInt(hex.slice(12, 14), 16))
278
- .filter(seq => seq > 0);
272
+ const sentSeqs = plugin.send.mock.calls.map(([, hex]) =>
273
+ Number.parseInt(hex.slice(12, 14), 16)
274
+ );
279
275
  expect(sentSeqs).toEqual([1, 2]);
280
276
  });
281
277
 
@@ -299,7 +295,7 @@ describe('LowlevelTransport protocol framing', () => {
299
295
  expect(lowlevel.getProtocolType('unknown-pro2-id')).toBe('V2');
300
296
  });
301
297
 
302
- test('detects Protocol V2 again after release without a name-derived hint', async () => {
298
+ test('retains the Protocol V2 hint and sequence cursor across release and reacquire', async () => {
303
299
  const probeResponse = ProtocolV2.encodeFrame(
304
300
  schemas,
305
301
  'Success',
@@ -308,12 +304,7 @@ describe('LowlevelTransport protocol framing', () => {
308
304
  );
309
305
  const plugin = createPlugin({
310
306
  devices: [{ id: 'reconnect-pro2-id', name: 'OneKey Pro 2', commType: 'ble' }],
311
- responses: [
312
- new Error('Protocol V1 probe timed out'),
313
- bytesToHex(probeResponse),
314
- new Error('Protocol V1 probe timed out'),
315
- bytesToHex(probeResponse),
316
- ],
307
+ responses: [bytesToHex(probeResponse), bytesToHex(probeResponse)],
317
308
  });
318
309
  const lowlevel = configureTransport(plugin);
319
310
 
@@ -328,9 +319,9 @@ describe('LowlevelTransport protocol framing', () => {
328
319
  protocolType: 'V2',
329
320
  });
330
321
 
331
- const sentSeqs = plugin.send.mock.calls
332
- .map(([, hex]) => Number.parseInt(hex.slice(12, 14), 16))
333
- .filter(seq => seq > 0);
322
+ const sentSeqs = plugin.send.mock.calls.map(([, hex]) =>
323
+ Number.parseInt(hex.slice(12, 14), 16)
324
+ );
334
325
  expect(sentSeqs).toEqual([1, 2]);
335
326
  });
336
327
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as transport from '@onekeyfe/hd-transport';
2
- import transport__default, { ProtocolType, LowlevelTransportSharedPlugin, TransportCallOptions } from '@onekeyfe/hd-transport';
2
+ import transport__default, { ProtocolType, LowlevelTransportSharedPlugin, LowLevelDevice, TransportCallOptions } from '@onekeyfe/hd-transport';
3
3
  import EventEmitter from 'events';
4
4
 
5
5
  type LowLevelAcquireInput = {
@@ -36,7 +36,7 @@ declare class LowlevelTransport {
36
36
  configure(signedData: any): void;
37
37
  configureProtocolV2(signedData: any): void;
38
38
  listen(): void;
39
- enumerate(): Promise<transport.LowLevelDevice[]>;
39
+ enumerate(): Promise<LowLevelDevice[]>;
40
40
  acquire(input: LowLevelAcquireInput): Promise<{
41
41
  uuid: string;
42
42
  protocolType: ProtocolType;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,SAYN,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,6BAA6B,EAC7B,YAAY,EAEZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CA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Ae;YA6Bf,UAAU;YAUV,qBAAqB;YAmBrB,mBAAmB;YAqBnB,oBAAoB;YAgBpB,cAAc;IAwB5B,OAAO,CAAC,uBAAuB;IAgC/B,OAAO,CAAC,2BAA2B;IAMnC,MAAM;CAGP"}
package/dist/index.js CHANGED
@@ -53,6 +53,9 @@ function shouldLogFirmwareUploadProgress({ percent, lastLoggedPercent, now, last
53
53
  function getProtocolV1SendOptions(name) {
54
54
  return name === 'FirmwareUpload' ? { withoutResponse: false } : undefined;
55
55
  }
56
+ function inferProtocolHintFromDeviceName(name) {
57
+ return /\bpro\s*2\b/i.test(name !== null && name !== void 0 ? name : '') ? 'V2' : undefined;
58
+ }
56
59
  function isProtocolV1TransportChunk(data) {
57
60
  return data.length >= 9 && data[0] === 0x3f && data[1] === 0x23 && data[2] === 0x23;
58
61
  }
@@ -132,7 +135,13 @@ class LowlevelTransport {
132
135
  enumerate() {
133
136
  return __awaiter(this, void 0, void 0, function* () {
134
137
  const devices = yield this.plugin.enumerate();
135
- return devices;
138
+ return devices.map((device) => {
139
+ const protocolHint = inferProtocolHintFromDeviceName(device.name);
140
+ if (protocolHint) {
141
+ this.deviceProtocolHints.set(device.id, protocolHint);
142
+ }
143
+ return device;
144
+ });
136
145
  });
137
146
  }
138
147
  acquire(input) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-lowlevel",
3
- "version": "1.2.0-alpha.145",
3
+ "version": "1.2.0-alpha.147",
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.145",
24
- "@onekeyfe/hd-transport": "1.2.0-alpha.145"
23
+ "@onekeyfe/hd-shared": "1.2.0-alpha.147",
24
+ "@onekeyfe/hd-transport": "1.2.0-alpha.147"
25
25
  },
26
- "gitHead": "9a136f881865c15e603ef271ae820c2b5a991dcc"
26
+ "gitHead": "a34e98865e6be227cf3e00d486146e6592761db0"
27
27
  }
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ import transport, {
15
15
 
16
16
  import type EventEmitter from 'events';
17
17
  import type {
18
+ LowLevelDevice,
18
19
  LowlevelTransportSharedPlugin,
19
20
  ProtocolType,
20
21
  ProtocolV2CallContext,
@@ -52,6 +53,10 @@ export function getProtocolV1SendOptions(name: string) {
52
53
  return name === 'FirmwareUpload' ? { withoutResponse: false } : undefined;
53
54
  }
54
55
 
56
+ function inferProtocolHintFromDeviceName(name?: string | null): ProtocolType | undefined {
57
+ return /\bpro\s*2\b/i.test(name ?? '') ? 'V2' : undefined;
58
+ }
59
+
55
60
  function isProtocolV1TransportChunk(data: Uint8Array) {
56
61
  return data.length >= 9 && data[0] === 0x3f && data[1] === 0x23 && data[2] === 0x23;
57
62
  }
@@ -156,7 +161,13 @@ export default class LowlevelTransport {
156
161
 
157
162
  async enumerate() {
158
163
  const devices = await this.plugin.enumerate();
159
- return devices;
164
+ return devices.map((device: LowLevelDevice) => {
165
+ const protocolHint = inferProtocolHintFromDeviceName(device.name);
166
+ if (protocolHint) {
167
+ this.deviceProtocolHints.set(device.id, protocolHint);
168
+ }
169
+ return device;
170
+ });
160
171
  }
161
172
 
162
173
  async acquire(input: LowLevelAcquireInput) {
@@ -216,7 +227,8 @@ export default class LowlevelTransport {
216
227
  await this.plugin.disconnect(uuid);
217
228
  this.connectedDevices.delete(uuid);
218
229
  this.deviceProtocol.delete(uuid);
219
- // Confirmed protocol stays on the device endpoint; BLE names are not a probe hint.
230
+ // A name-derived protocol hint survives disconnect and lets fast reconnect probe
231
+ // Protocol V2 first without sending a redundant V1 Initialize.
220
232
  this.protocolV2Assemblers.delete(uuid);
221
233
  return true;
222
234
  } catch (error) {