@onekeyfe/hd-core 0.2.30 → 0.2.32

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":"FirmwareUpdateV2.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIT,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAO1C,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,UAAU,CAAC;AAItD,aAAK,MAAM,GAAG;IACZ,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,UAAU,GAAG,KAAK,CAAC;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAIF,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU,CAAC,MAAM,CAAC;IAC9D,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,IAAI;IAsCJ,cAAc,YAAa,MAAM,UAS/B;IAEF,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IA6CrD,qBAAqB,CAAC,QAAQ,EAAE,QAAQ;IAUxC,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM;IAc9D,gCAAgC,CAAC,QAAQ,CAAC,EAAE,QAAQ;IAwB9C,GAAG;CAiGV"}
1
+ {"version":3,"file":"FirmwareUpdateV2.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIT,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAO1C,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,UAAU,CAAC;AAItD,aAAK,MAAM,GAAG;IACZ,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,UAAU,GAAG,KAAK,CAAC;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAIF,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU,CAAC,MAAM,CAAC;IAC9D,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,IAAI;IAsCJ,cAAc,YAAa,MAAM,UAS/B;IAEF,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IAkDrD,qBAAqB,CAAC,QAAQ,EAAE,QAAQ;IAUxC,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM;IAc9D,gCAAgC,CAAC,QAAQ,CAAC,EAAE,QAAQ;IAwB9C,GAAG;CAiGV"}
@@ -1 +1 @@
1
- {"version":3,"file":"DeviceUpdateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceUpdateBootloader.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAQ3C,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,UAAU;IAC5D,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,IAAI;IAMJ,cAAc,YAAa,MAAM,UAS/B;IAEI,GAAG;CA4BV"}
1
+ {"version":3,"file":"DeviceUpdateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceUpdateBootloader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAQ3C,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,UAAU;IAC5D,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,IAAI;IAMJ,cAAc,YAAa,MAAM,UAS/B;IAEI,GAAG;CA4BV"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAqBlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AA4BxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBA+PjD,CAAC;AAqMF,eAAO,MAAM,MAAM,0CAkBlB,CAAC;AA8IF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IACtC,aAAa,CAAC,OAAO,EAAE,WAAW;IA8CxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAIzB,CAAC;AAMF,eAAO,MAAM,IAAI,aAAoB,eAAe,aAAa,GAAG,8BAmBnE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAqBlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AA4BxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBAkQjD,CAAC;AAqMF,eAAO,MAAM,MAAM,0CAkBlB,CAAC;AAoJF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IACtC,aAAa,CAAC,OAAO,EAAE,WAAW;IA8CxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAIzB,CAAC;AAMF,eAAO,MAAM,IAAI,aAAoB,eAAe,aAAa,GAAG,8BAmBnE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ interface CommonParams {
10
10
  pollIntervalTime?: number;
11
11
  timeout?: number;
12
12
  passphraseState?: string;
13
+ useEmptyPassphrase?: boolean;
13
14
  initSession?: boolean;
14
15
  }
15
16
  declare type Params<T> = CommonParams & T & {
package/dist/index.js CHANGED
@@ -13596,24 +13596,29 @@ class FirmwareUpdateV2 extends BaseMethod {
13596
13596
  const isBleReconnect = connectId && env === 'react-native';
13597
13597
  Log$3.log('FirmwareUpdateV2 [checkDeviceToBootloader] isBleReconnect: ', isBleReconnect);
13598
13598
  const intervalTimer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
13599
- var _a, _b, _c, _d, _e, _f, _g;
13599
+ var _a, _b, _c, _d, _e, _f, _g, _h;
13600
13600
  if (isBleReconnect) {
13601
- yield this.device.acquire();
13602
- yield this.device.initialize();
13603
- if ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.bootloader_mode) {
13604
- clearInterval(intervalTimer);
13605
- (_b = this.checkPromise) === null || _b === void 0 ? void 0 : _b.resolve(true);
13601
+ try {
13602
+ yield ((_a = this.device.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.device.originalDescriptor.id));
13603
+ yield this.device.initialize();
13604
+ if ((_b = this.device.features) === null || _b === void 0 ? void 0 : _b.bootloader_mode) {
13605
+ clearInterval(intervalTimer);
13606
+ (_c = this.checkPromise) === null || _c === void 0 ? void 0 : _c.resolve(true);
13607
+ }
13608
+ }
13609
+ catch (e) {
13610
+ Log$3.log('catch Bluetooth error when device is restarting: ', e);
13606
13611
  }
13607
13612
  }
13608
13613
  else {
13609
- const deviceDiff = yield ((_c = this.device.deviceConnector) === null || _c === void 0 ? void 0 : _c.enumerate());
13610
- const devicesDescriptor = (_d = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _d !== void 0 ? _d : [];
13614
+ const deviceDiff = yield ((_d = this.device.deviceConnector) === null || _d === void 0 ? void 0 : _d.enumerate());
13615
+ const devicesDescriptor = (_e = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _e !== void 0 ? _e : [];
13611
13616
  const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, connectId);
13612
- if (deviceList.length === 1 && ((_f = (_e = deviceList[0]) === null || _e === void 0 ? void 0 : _e.features) === null || _f === void 0 ? void 0 : _f.bootloader_mode)) {
13617
+ if (deviceList.length === 1 && ((_g = (_f = deviceList[0]) === null || _f === void 0 ? void 0 : _f.features) === null || _g === void 0 ? void 0 : _g.bootloader_mode)) {
13613
13618
  this.device.updateFromCache(deviceList[0]);
13614
13619
  this.device.commands.disposed = false;
13615
13620
  clearInterval(intervalTimer);
13616
- (_g = this.checkPromise) === null || _g === void 0 ? void 0 : _g.resolve(true);
13621
+ (_h = this.checkPromise) === null || _h === void 0 ? void 0 : _h.resolve(true);
13617
13622
  }
13618
13623
  }
13619
13624
  }), isBleReconnect ? 3000 : 2000);
@@ -18408,7 +18413,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
18408
18413
  (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
18409
18414
  device.on(DEVICE.PIN, onDevicePinHandler);
18410
18415
  device.on(DEVICE.BUTTON, onDeviceButtonHandler);
18411
- device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
18416
+ device.on(DEVICE.PASSPHRASE, message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler);
18412
18417
  device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
18413
18418
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
18414
18419
  try {
@@ -18712,7 +18717,9 @@ const cancel = (connectId) => {
18712
18717
  const checkPassphraseSafety = (method, features) => {
18713
18718
  if (!method.useDevicePassphraseState)
18714
18719
  return;
18715
- if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true && !method.payload.passphraseState) {
18720
+ if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true &&
18721
+ (method.payload.passphraseState == null || method.payload.passphraseState === '') &&
18722
+ !method.payload.useEmptyPassphrase) {
18716
18723
  DevicePool.clearDeviceCache(method.payload.connectId);
18717
18724
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
18718
18725
  }
@@ -18726,11 +18733,7 @@ const cleanup = () => {
18726
18733
  Log.debug('Cleanup...');
18727
18734
  };
18728
18735
  const removeDeviceListener = (device) => {
18729
- device.removeListener(DEVICE.PIN, onDevicePinHandler);
18730
- device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
18731
- device.removeListener(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
18732
- device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
18733
- device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
18736
+ device.removeAllListeners();
18734
18737
  DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
18735
18738
  };
18736
18739
  const closePopup = () => {
@@ -18786,6 +18789,10 @@ const onDevicePassphraseHandler = (...[device, callback]) => __awaiter(void 0, v
18786
18789
  cache: save,
18787
18790
  });
18788
18791
  });
18792
+ const onEmptyPassphraseHandler = (...[_, callback]) => {
18793
+ Log.debug('onEmptyPassphraseHandler');
18794
+ callback({ passphrase: '' });
18795
+ };
18789
18796
  const onEnterPassphraseOnDeviceHandler = (...[device]) => {
18790
18797
  postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PASSPHRASE_ON_DEVICE, {
18791
18798
  device: device.toMessageObject(),
@@ -4,6 +4,7 @@ export interface CommonParams {
4
4
  pollIntervalTime?: number;
5
5
  timeout?: number;
6
6
  passphraseState?: string;
7
+ useEmptyPassphrase?: boolean;
7
8
  initSession?: boolean;
8
9
  }
9
10
  export declare type Params<T> = CommonParams & T & {
@@ -1 +1 @@
1
- {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IAItB,UAAU,CAAC,EAAE,MAAM,CAAC;IAIpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAI1B,OAAO,CAAC,EAAE,MAAM,CAAC;IAIjB,eAAe,CAAC,EAAE,MAAM,CAAC;IAIzB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,oBAAY,MAAM,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,oBAAY,QAAQ,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC"}
1
+ {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IAItB,UAAU,CAAC,EAAE,MAAM,CAAC;IAIpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAI1B,OAAO,CAAC,EAAE,MAAM,CAAC;IAIjB,eAAe,CAAC,EAAE,MAAM,CAAC;IAIzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAI7B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,oBAAY,MAAM,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,oBAAY,QAAQ,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -24,8 +24,8 @@
24
24
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@onekeyfe/hd-shared": "^0.2.30",
28
- "@onekeyfe/hd-transport": "^0.2.30",
27
+ "@onekeyfe/hd-shared": "^0.2.32",
28
+ "@onekeyfe/hd-transport": "^0.2.32",
29
29
  "axios": "^0.27.2",
30
30
  "bignumber.js": "^9.0.2",
31
31
  "jszip": "^3.10.1",
@@ -42,5 +42,5 @@
42
42
  "@types/semver": "^7.3.9",
43
43
  "ripple-keypairs": "^1.1.4"
44
44
  },
45
- "gitHead": "ef7e66f72ac394b8c4faa35d65a3d3d9f6cd4846"
45
+ "gitHead": "361f104ba3c7c74eaf3916e71e9790aaf373a11b"
46
46
  }
@@ -90,11 +90,16 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
90
90
  const intervalTimer: ReturnType<typeof setInterval> | undefined = setInterval(
91
91
  async () => {
92
92
  if (isBleReconnect) {
93
- await this.device.acquire();
94
- await this.device.initialize();
95
- if (this.device.features?.bootloader_mode) {
96
- clearInterval(intervalTimer);
97
- this.checkPromise?.resolve(true);
93
+ try {
94
+ await this.device.deviceConnector?.acquire(this.device.originalDescriptor.id);
95
+ await this.device.initialize();
96
+ if (this.device.features?.bootloader_mode) {
97
+ clearInterval(intervalTimer);
98
+ this.checkPromise?.resolve(true);
99
+ }
100
+ } catch (e) {
101
+ // ignore error because of device is not connected
102
+ Log.log('catch Bluetooth error when device is restarting: ', e);
98
103
  }
99
104
  } else {
100
105
  const deviceDiff = await this.device.deviceConnector?.enumerate();
@@ -1,4 +1,4 @@
1
- import { ERRORS, HardwareErrorCode, Deferred } from '@onekeyfe/hd-shared';
1
+ import { Deferred } from '@onekeyfe/hd-shared';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { BaseMethod } from '../BaseMethod';
4
4
  import { getSysResourceBinary } from '../firmware/getBinary';
package/src/core/index.ts CHANGED
@@ -133,7 +133,10 @@ export const callAPI = async (message: CoreMessage) => {
133
133
 
134
134
  device.on(DEVICE.PIN, onDevicePinHandler);
135
135
  device.on(DEVICE.BUTTON, onDeviceButtonHandler);
136
- device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
136
+ device.on(
137
+ DEVICE.PASSPHRASE,
138
+ message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler
139
+ );
137
140
  device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
138
141
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
139
142
 
@@ -540,7 +543,11 @@ export const cancel = (connectId?: string) => {
540
543
  const checkPassphraseSafety = (method: BaseMethod, features?: Features) => {
541
544
  if (!method.useDevicePassphraseState) return;
542
545
 
543
- if (features?.passphrase_protection === true && !method.payload.passphraseState) {
546
+ if (
547
+ features?.passphrase_protection === true &&
548
+ (method.payload.passphraseState == null || method.payload.passphraseState === '') &&
549
+ !method.payload.useEmptyPassphrase
550
+ ) {
544
551
  DevicePool.clearDeviceCache(method.payload.connectId);
545
552
  throw ERRORS.TypedError(HardwareErrorCode.DeviceOpenedPassphrase);
546
553
  }
@@ -557,11 +564,7 @@ const cleanup = () => {
557
564
  };
558
565
 
559
566
  const removeDeviceListener = (device: Device) => {
560
- device.removeListener(DEVICE.PIN, onDevicePinHandler);
561
- device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
562
- device.removeListener(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
563
- device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
564
- device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
567
+ device.removeAllListeners();
565
568
  DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
566
569
  // DevicePool.emitter.removeListener(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
567
570
  };
@@ -641,6 +644,12 @@ const onDevicePassphraseHandler = async (...[device, callback]: DeviceEvents['pa
641
644
  });
642
645
  };
643
646
 
647
+ const onEmptyPassphraseHandler = (...[_, callback]: DeviceEvents['passphrase']) => {
648
+ Log.debug('onEmptyPassphraseHandler');
649
+ // send as PassphrasePromptResponse
650
+ callback({ passphrase: '' });
651
+ };
652
+
644
653
  const onEnterPassphraseOnDeviceHandler = (
645
654
  ...[device]: [...DeviceEvents['passphrase_on_device']]
646
655
  ) => {
@@ -16,6 +16,10 @@ export interface CommonParams {
16
16
  * passphrase state
17
17
  */
18
18
  passphraseState?: string;
19
+ /**
20
+ * Use empty passphrase
21
+ */
22
+ useEmptyPassphrase?: boolean;
19
23
  /**
20
24
  * Every init session
21
25
  */