@onekeyfe/hd-transport-usb 1.2.0-alpha.16 → 1.2.0-alpha.17

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.
@@ -189,7 +189,19 @@ const createHarness = () => {
189
189
  };
190
190
 
191
191
  describe('NodeUsbTransport Protocol V2 link lifecycle', () => {
192
- test('keeps seq across probe, call and reacquire', async () => {
192
+ test('trusts explicit Protocol V2 during bootloader reconnect without probing Ping', async () => {
193
+ const harness = createHarness();
194
+ const { transport, path, epOut } = harness;
195
+
196
+ await transport.enumerate();
197
+ await transport.acquire({ path, expectedProtocol: 'V2' });
198
+
199
+ expect(epOut.transfer).not.toHaveBeenCalled();
200
+ expect(transport.getProtocolType(path)).toBe('V2');
201
+ await transport.release(path);
202
+ });
203
+
204
+ test('keeps seq across calls and reacquire without probing explicit V2', async () => {
193
205
  const harness = createHarness();
194
206
  const { transport, path, sentSeqs } = harness;
195
207
 
@@ -199,7 +211,7 @@ describe('NodeUsbTransport Protocol V2 link lifecycle', () => {
199
211
  await harness.acquire();
200
212
  await transport.call(path, 'Ping', { message: 'second' });
201
213
 
202
- expect(sentSeqs).toEqual([1, 2, 3, 4]);
214
+ expect(sentSeqs).toEqual([1, 2]);
203
215
  await transport.release(path);
204
216
  });
205
217
 
@@ -254,7 +266,7 @@ describe('NodeUsbTransport Protocol V2 link lifecycle', () => {
254
266
  await harness.acquire();
255
267
  await transport.call(path, 'Ping', { message: 'after-timeout' });
256
268
 
257
- expect(sentSeqs).toEqual([1, 2, 3, 4]);
269
+ expect(sentSeqs).toEqual([1, 2]);
258
270
  await transport.release(path);
259
271
  });
260
272
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,SAAS,EAAE,EAOhB,0BAA0B,EAE3B,MAAM,wBAAwB,CAAC;AAKhC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO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AAG,KAAK;YAInE,cAAc;YAad,WAAW;IA6CzB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.js CHANGED
@@ -569,7 +569,13 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
569
569
  return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Unable to detect USB protocol: device did not respond to Protocol V1 Initialize or Protocol V2 Ping');
570
570
  }
571
571
  detectProtocol(path, expectedProtocol) {
572
+ var _a;
572
573
  return __awaiter(this, void 0, void 0, function* () {
574
+ if (expectedProtocol === 'V2') {
575
+ this.deviceProtocol.set(path, 'V2');
576
+ (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2 (expected)`);
577
+ return 'V2';
578
+ }
573
579
  if (expectedProtocol === 'V1') {
574
580
  if (yield this.probeProtocolV1(path)) {
575
581
  this.deviceProtocol.set(path, 'V1');
@@ -577,13 +583,6 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
577
583
  }
578
584
  throw this.createProtocolMismatchError(expectedProtocol);
579
585
  }
580
- if (expectedProtocol === 'V2') {
581
- if (yield this.probeProtocolV2(path)) {
582
- this.deviceProtocol.set(path, 'V2');
583
- return 'V2';
584
- }
585
- throw this.createProtocolMismatchError(expectedProtocol);
586
- }
587
586
  if (this.deviceProtocol.get(path) === 'V2' && (yield this.probeProtocolV2(path))) {
588
587
  this.deviceProtocol.set(path, 'V2');
589
588
  return 'V2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-usb",
3
- "version": "1.2.0-alpha.16",
3
+ "version": "1.2.0-alpha.17",
4
4
  "description": "OneKey hardware wallet direct USB transport plugin (libusb)",
5
5
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
6
6
  "license": "MIT",
@@ -20,10 +20,10 @@
20
20
  "lint:fix": "eslint . --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@onekeyfe/hd-shared": "1.2.0-alpha.16",
24
- "@onekeyfe/hd-transport": "1.2.0-alpha.16",
23
+ "@onekeyfe/hd-shared": "1.2.0-alpha.17",
24
+ "@onekeyfe/hd-transport": "1.2.0-alpha.17",
25
25
  "bytebuffer": "^5.0.1",
26
26
  "usb": "^2.14.0"
27
27
  },
28
- "gitHead": "2356d951f63a39a46bc995c2090348a383966175"
28
+ "gitHead": "9027b743e4f73beb42e1a7950397504b4191f2a3"
29
29
  }
package/src/index.ts CHANGED
@@ -743,6 +743,15 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
743
743
  path: string,
744
744
  expectedProtocol?: ProtocolType
745
745
  ): Promise<ProtocolType> {
746
+ if (expectedProtocol === 'V2') {
747
+ // 固件升级重启后的 bootloader 不保证响应 Ping。上层显式传入 V2
748
+ // 表示协议已在重启前确认;直接建立 V2 链路,由首个业务命令验证
749
+ // bootloader 是否已经完成 USB 初始化。
750
+ this.deviceProtocol.set(path, 'V2');
751
+ this.Log?.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2 (expected)`);
752
+ return 'V2';
753
+ }
754
+
746
755
  if (expectedProtocol === 'V1') {
747
756
  if (await this.probeProtocolV1(path)) {
748
757
  this.deviceProtocol.set(path, 'V1');
@@ -751,14 +760,6 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
751
760
  throw this.createProtocolMismatchError(expectedProtocol);
752
761
  }
753
762
 
754
- if (expectedProtocol === 'V2') {
755
- if (await this.probeProtocolV2(path)) {
756
- this.deviceProtocol.set(path, 'V2');
757
- return 'V2';
758
- }
759
- throw this.createProtocolMismatchError(expectedProtocol);
760
- }
761
-
762
763
  if (this.deviceProtocol.get(path) === 'V2' && (await this.probeProtocolV2(path))) {
763
764
  this.deviceProtocol.set(path, 'V2');
764
765
  return 'V2';