@onekeyfe/hd-transport-usb 1.2.0-alpha.99 → 1.2.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,SAAS,EAAE,EAQhB,0BAA0B,EAE3B,MAAM,wBAAwB,CAAC;AAKhC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAuIhC,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,0BAA0B,CAAC,MAAM,CAAC;IAC9E,QAAQ,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAGlE,UAAU,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEpE,OAAO,CAAC,sBAAsB,CAAqB;IAEnD,IAAI,SAAsB;IAE1B,OAAO,SAAM;IAEb,UAAU,UAAS;IAEnB,UAAU,UAAS;IAEnB,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAGvB,OAAO,CAAC,aAAa,CAA6B;IAGlD,OAAO,CAAC,WAAW,CAAiC;IAGpD,OAAO,CAAC,cAAc,CAAwC;IAG9D,OAAO,CAAC,cAAc,CAA0C;IAMhE,OAAO,CAAC,eAAe,CAGnB;IAGJ,OAAO,CAAC,SAAS,CAAS;;IAc1B,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY;IAMxC,SAAS,CAAC,UAAU,EAAE,GAAG;IAOzB,mBAAmB,CAAC,UAAU,EAAE,GAAG;IAiBnC,MAAM;IAIA,IAAI,IAA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iB;YAuDX,sBAAsB;YAyCtB,mBAAmB;YA2CnB,UAAU;YA+DV,eAAe;IAiB7B,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;YAOtB,cAAc;YAyCd,yBAAyB;YAiBzB,uBAAuB;YA0CvB,eAAe;YAaf,eAAe;IAc7B,SAAS,CAAC,uBAAuB,IAAI,iBAAiB;IAUtD,SAAS,CAAC,sBAAsB;cAIhB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,IAAI,CAAC;cAOA,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,UAAU,CAAC;cAsBN,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1F,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;YAOnE,cAAc;YAad,WAAW;IA6CzB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.js CHANGED
@@ -210,6 +210,10 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
210
210
  if (!this.messages) {
211
211
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
212
212
  }
213
+ if (this.deviceProtocol.get(path) === 'V2') {
214
+ yield this.sendProtocolV2UsbFlowControl(path, name, data);
215
+ return;
216
+ }
213
217
  const encodeBuffers = ProtocolV1.encodeMessageChunks(this.messages, name, data);
214
218
  yield this.sendAllChunksWithRetry(path, encodeBuffers);
215
219
  });
@@ -253,7 +257,7 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
253
257
  });
254
258
  }
255
259
  acquire(input) {
256
- var _a, _b, _c, _d;
260
+ var _a, _b, _c, _d, _e;
257
261
  return __awaiter(this, void 0, void 0, function* () {
258
262
  this.cancelled = false;
259
263
  const path = (_a = input.path) !== null && _a !== void 0 ? _a : '';
@@ -264,18 +268,22 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
264
268
  yield this.rotateProtocolV2UsbGeneration(path, 'Node USB transport acquired');
265
269
  yield this.closeOpenDevice(path);
266
270
  yield this.openDevice(path);
267
- yield this.detectProtocol(path, input.expectedProtocol, input.protocolHint);
271
+ const descriptor = this.getOpenDevice(path).device.deviceDescriptor;
272
+ const protocolHint = input.expectedProtocol
273
+ ? undefined
274
+ : (_b = input.protocolHint) !== null && _b !== void 0 ? _b : hdShared.inferProtocolHintFromUsbId(descriptor.idVendor, descriptor.idProduct);
275
+ yield this.detectProtocol(path, input.expectedProtocol, protocolHint);
268
276
  return path;
269
277
  }
270
278
  catch (error) {
271
- (_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug('NodeUsbTransport acquire error: ', error);
279
+ (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug('NodeUsbTransport acquire error: ', error);
272
280
  try {
273
281
  yield this.release(path);
274
282
  }
275
283
  catch (cleanupError) {
276
- (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug('NodeUsbTransport acquire cleanup error: ', cleanupError);
284
+ (_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug('NodeUsbTransport acquire cleanup error: ', cleanupError);
277
285
  }
278
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, (_d = error.message) !== null && _d !== void 0 ? _d : String(error));
286
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, (_e = error.message) !== null && _e !== void 0 ? _e : String(error));
279
287
  }
280
288
  });
281
289
  }
@@ -386,7 +394,6 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
386
394
  });
387
395
  }
388
396
  call(path, name, data, options) {
389
- var _a;
390
397
  return __awaiter(this, void 0, void 0, function* () {
391
398
  this.cancelled = false;
392
399
  if (!this.messages) {
@@ -399,9 +406,6 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
399
406
  if (!protocol) {
400
407
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${path}`);
401
408
  }
402
- if (!transport.shouldSuppressHighVolumeCallLog(name)) {
403
- (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('transport call', transport.createTransportCallLog(name, protocol, data));
404
- }
405
409
  if (protocol === 'V2') {
406
410
  return this.callProtocolV2(path, name, data, options);
407
411
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-usb",
3
- "version": "1.2.0-alpha.99",
3
+ "version": "1.2.0",
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",
@@ -21,10 +21,10 @@
21
21
  "lint:fix": "eslint . --fix"
22
22
  },
23
23
  "dependencies": {
24
- "@onekeyfe/hd-shared": "1.2.0-alpha.99",
25
- "@onekeyfe/hd-transport": "1.2.0-alpha.99",
24
+ "@onekeyfe/hd-shared": "1.2.0",
25
+ "@onekeyfe/hd-transport": "1.2.0",
26
26
  "bytebuffer": "^5.0.1",
27
27
  "usb": "^2.14.0"
28
28
  },
29
- "gitHead": "8924c0e509f84675a2c33c0062166967f5bcb2d0"
29
+ "gitHead": "cc51df0a415bead21304ad1d8bc92b5312c91344"
30
30
  }
package/src/index.ts CHANGED
@@ -11,9 +11,13 @@ import transport, {
11
11
  ProtocolV2UsbTransportBase,
12
12
  probeProtocolV2 as probeProtocolV2Helper,
13
13
  } from '@onekeyfe/hd-transport';
14
- import { ERRORS, HardwareErrorCode, ONEKEY_WEBUSB_FILTER, wait } from '@onekeyfe/hd-shared';
15
-
16
- import { createTransportCallLog, shouldSuppressHighVolumeCallLog } from './transportLog';
14
+ import {
15
+ ERRORS,
16
+ HardwareErrorCode,
17
+ ONEKEY_WEBUSB_FILTER,
18
+ inferProtocolHintFromUsbId,
19
+ wait,
20
+ } from '@onekeyfe/hd-shared';
17
21
 
18
22
  import type EventEmitter from 'events';
19
23
  import type {
@@ -279,6 +283,10 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
279
283
  if (!this.messages) {
280
284
  throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
281
285
  }
286
+ if (this.deviceProtocol.get(path) === 'V2') {
287
+ await this.sendProtocolV2UsbFlowControl(path, name, data);
288
+ return;
289
+ }
282
290
  const encodeBuffers = ProtocolV1.encodeMessageChunks(this.messages, name, data);
283
291
  await this.sendAllChunksWithRetry(path, encodeBuffers);
284
292
  }
@@ -346,7 +354,12 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
346
354
  await this.rotateProtocolV2UsbGeneration(path, 'Node USB transport acquired');
347
355
  await this.closeOpenDevice(path);
348
356
  await this.openDevice(path);
349
- await this.detectProtocol(path, input.expectedProtocol, input.protocolHint);
357
+ const descriptor = this.getOpenDevice(path).device.deviceDescriptor;
358
+ const protocolHint = input.expectedProtocol
359
+ ? undefined
360
+ : input.protocolHint ??
361
+ inferProtocolHintFromUsbId(descriptor.idVendor, descriptor.idProduct);
362
+ await this.detectProtocol(path, input.expectedProtocol, protocolHint);
350
363
  return path;
351
364
  } catch (error: any) {
352
365
  this.Log?.debug('NodeUsbTransport acquire error: ', error);
@@ -502,10 +515,6 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
502
515
  `Device protocol has not been detected for ${path}`
503
516
  );
504
517
  }
505
- if (!shouldSuppressHighVolumeCallLog(name)) {
506
- this.Log?.debug('transport call', createTransportCallLog(name, protocol, data));
507
- }
508
-
509
518
  if (protocol === 'V2') {
510
519
  return this.callProtocolV2(path, name, data, options);
511
520
  }