@onekeyfe/hd-web-sdk 0.1.53 → 0.1.54

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.
@@ -4277,6 +4277,10 @@ const inject = ({
4277
4277
  connectId,
4278
4278
  method: 'firmwareUpdate'
4279
4279
  })),
4280
+ firmwareUpdateV2: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4281
+ connectId,
4282
+ method: 'firmwareUpdateV2'
4283
+ })),
4280
4284
  requestWebUsbDevice: () => call({
4281
4285
  method: 'requestWebUsbDevice'
4282
4286
  }),
@@ -14616,6 +14620,10 @@ const LoggerMap = {
14616
14620
 
14617
14621
  const getLogger = key => LoggerMap[key];
14618
14622
 
14623
+ const wait = ms => new Promise(resolve => {
14624
+ setTimeout(resolve, ms);
14625
+ });
14626
+
14619
14627
  const getReleaseStatus = (releases, currentVersion) => {
14620
14628
  const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
14621
14629
 
@@ -14842,6 +14850,7 @@ const UI_REQUEST$1 = {
14842
14850
  LOCATION_PERMISSION: 'ui-location_permission',
14843
14851
  LOCATION_SERVICE_PERMISSION: 'ui-location_service_permission',
14844
14852
  FIRMWARE_PROGRESS: 'ui-firmware-progress',
14853
+ FIRMWARE_TIP: 'ui-firmware-tip',
14845
14854
  NOT_IN_BOOTLOADER: 'ui-device_not_in_bootloader_mode'
14846
14855
  };
14847
14856
 
@@ -15515,7 +15524,8 @@ const UI_REQUEST = {
15515
15524
  FIRMWARE_NOT_SUPPORTED: 'ui-device_firmware_unsupported',
15516
15525
  FIRMWARE_NOT_COMPATIBLE: 'ui-device_firmware_not_compatible',
15517
15526
  FIRMWARE_NOT_INSTALLED: 'ui-device_firmware_not_installed',
15518
- NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device'
15527
+ NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device',
15528
+ FIRMWARE_TIP: 'ui-firmware-tip'
15519
15529
  };
15520
15530
 
15521
15531
  const pkg = __webpack_require__(2391);
@@ -16913,7 +16923,7 @@ const getBinary = ({
16913
16923
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no firmware found for this device');
16914
16924
  }
16915
16925
 
16916
- if (version && !semver__default["default"].eq(releaseInfo.version, version)) {
16926
+ if (version && !semver__default["default"].eq(releaseInfo.version.join('.'), version.join('.'))) {
16917
16927
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'firmware version mismatch');
16918
16928
  }
16919
16929
 
@@ -16962,6 +16972,15 @@ const postProgressMessage = (device, progress, postMessage) => {
16962
16972
  }));
16963
16973
  };
16964
16974
 
16975
+ const postProgressTip = (device, message, postMessage) => {
16976
+ postMessage(createUiMessage(UI_REQUEST$1.FIRMWARE_TIP, {
16977
+ device: device.toMessageObject(),
16978
+ data: {
16979
+ message
16980
+ }
16981
+ }));
16982
+ };
16983
+
16965
16984
  const uploadFirmware = (updateType, typedCall, postMessage, device, {
16966
16985
  payload
16967
16986
  }) => __awaiter(void 0, void 0, void 0, function* () {
@@ -16969,8 +16988,10 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, {
16969
16988
 
16970
16989
  if (((_a = device.features) === null || _a === void 0 ? void 0 : _a.major_version) === 1) {
16971
16990
  postConfirmationMessage(device);
16991
+ postProgressTip(device, 'ConfirmOnDevice', postMessage);
16972
16992
  const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
16973
16993
  yield typedCall(eraseCommand, 'Success', {});
16994
+ postProgressTip(device, 'FirmwareEraseSuccess', postMessage);
16974
16995
  postProgressMessage(device, 0, postMessage);
16975
16996
  const {
16976
16997
  message
@@ -16983,10 +17004,12 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, {
16983
17004
 
16984
17005
  if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
16985
17006
  postConfirmationMessage(device);
17007
+ postProgressTip(device, 'ConfirmOnDevice', postMessage);
16986
17008
  const length = payload.byteLength;
16987
17009
  let response = yield typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], {
16988
17010
  length
16989
17011
  });
17012
+ postProgressTip(device, 'FirmwareEraseSuccess', postMessage);
16990
17013
 
16991
17014
  while (response.type !== 'Success') {
16992
17015
  const start = response.message.offset;
@@ -17009,7 +17032,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, {
17009
17032
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
17010
17033
  });
17011
17034
 
17012
- class FirmwareUpdate extends BaseMethod {
17035
+ class FirmwareUpdate$1 extends BaseMethod {
17013
17036
  init() {
17014
17037
  this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
17015
17038
  this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
@@ -17083,6 +17106,157 @@ class FirmwareUpdate extends BaseMethod {
17083
17106
 
17084
17107
  }
17085
17108
 
17109
+ class FirmwareUpdate extends BaseMethod {
17110
+ constructor() {
17111
+ super(...arguments);
17112
+ this.checkPromise = null;
17113
+
17114
+ this.postTipMessage = message => {
17115
+ this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_TIP, {
17116
+ device: this.device.toMessageObject(),
17117
+ data: {
17118
+ message
17119
+ }
17120
+ }));
17121
+ };
17122
+ }
17123
+
17124
+ init() {
17125
+ this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
17126
+ this.requireDeviceMode = [];
17127
+ this.useDevicePassphraseState = false;
17128
+ const {
17129
+ payload
17130
+ } = this;
17131
+ validateParams(payload, [{
17132
+ name: 'version',
17133
+ type: 'array'
17134
+ }, {
17135
+ name: 'binary',
17136
+ type: 'buffer'
17137
+ }]);
17138
+
17139
+ if (!payload.updateType) {
17140
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'updateType is required');
17141
+ }
17142
+
17143
+ this.params = {
17144
+ updateType: payload.updateType
17145
+ };
17146
+
17147
+ if ('version' in payload) {
17148
+ this.params = Object.assign(Object.assign({}, this.params), {
17149
+ version: payload.version
17150
+ });
17151
+ }
17152
+
17153
+ if ('binary' in payload) {
17154
+ this.params = Object.assign(Object.assign({}, this.params), {
17155
+ binary: payload.binary
17156
+ });
17157
+ }
17158
+ }
17159
+
17160
+ checkDeviceToBootloader() {
17161
+ this.checkPromise = hdShared.createDeferred();
17162
+ const intervalTimer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
17163
+ var _a, _b, _c, _d;
17164
+
17165
+ const deviceDiff = yield (_a = this.device.deviceConnector) === null || _a === void 0 ? void 0 : _a.enumerate();
17166
+ const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
17167
+ const {
17168
+ deviceList
17169
+ } = yield DevicePool.getDevices(devicesDescriptor, this.connectId);
17170
+ console.log('device list: ', deviceList);
17171
+
17172
+ if (deviceList.length === 1 && ((_c = deviceList[0].features) === null || _c === void 0 ? void 0 : _c.bootloader_mode)) {
17173
+ this.device.updateFromCache(deviceList[0]);
17174
+ this.device.commands.disposed = false;
17175
+ clearInterval(intervalTimer);
17176
+ (_d = this.checkPromise) === null || _d === void 0 ? void 0 : _d.resolve(true);
17177
+ }
17178
+ }), 2000);
17179
+ setTimeout(() => {
17180
+ if (this.checkPromise) {
17181
+ clearInterval(intervalTimer);
17182
+ this.checkPromise.reject(new Error());
17183
+ }
17184
+ }, 30000);
17185
+ }
17186
+
17187
+ run() {
17188
+ var _a, _b;
17189
+
17190
+ return __awaiter(this, void 0, void 0, function* () {
17191
+ const {
17192
+ device,
17193
+ params
17194
+ } = this;
17195
+ const {
17196
+ features,
17197
+ commands
17198
+ } = device;
17199
+
17200
+ if (!(features === null || features === void 0 ? void 0 : features.bootloader_mode)) {
17201
+ const uuid = getDeviceUUID(features);
17202
+ const deviceType = getDeviceType(features);
17203
+
17204
+ if (deviceType === 'mini') {
17205
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedBootloaderMode));
17206
+ }
17207
+
17208
+ try {
17209
+ this.postTipMessage('AutoRebootToBootloader');
17210
+ yield commands.typedCall('BixinReboot', 'Success');
17211
+ this.postTipMessage('GoToBootloaderSuccess');
17212
+ this.checkDeviceToBootloader();
17213
+
17214
+ if (deviceType === 'classic') {
17215
+ DevicePool.clearDeviceCache(uuid);
17216
+ }
17217
+
17218
+ delete DevicePool.devicesCache[''];
17219
+ yield (_a = this.checkPromise) === null || _a === void 0 ? void 0 : _a.promise;
17220
+ this.checkPromise = null;
17221
+ yield wait(1500);
17222
+ } catch (e) {
17223
+ console.log('auto go to bootloader mode failed: ', e);
17224
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'go to bootloader mode failed'));
17225
+ }
17226
+ }
17227
+
17228
+ let binary;
17229
+
17230
+ try {
17231
+ if (params.binary) {
17232
+ binary = this.params.binary;
17233
+ } else {
17234
+ if (!device.features) {
17235
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no features found for this device');
17236
+ }
17237
+
17238
+ this.postTipMessage('DownloadFirmware');
17239
+ const firmware = yield getBinary({
17240
+ features: device.features,
17241
+ version: params.version,
17242
+ updateType: params.updateType
17243
+ });
17244
+ binary = firmware.binary;
17245
+ this.postTipMessage('DownloadFirmwareSuccess');
17246
+ }
17247
+ } catch (err) {
17248
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, (_b = err.message) !== null && _b !== void 0 ? _b : err);
17249
+ }
17250
+
17251
+ yield this.device.acquire();
17252
+ return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, {
17253
+ payload: binary
17254
+ });
17255
+ });
17256
+ }
17257
+
17258
+ }
17259
+
17086
17260
  const Log$2 = getLogger(exports.d0.Method);
17087
17261
 
17088
17262
  class RequestWebUsbDevice extends BaseMethod {
@@ -20841,7 +21015,8 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
20841
21015
  deviceSupportFeatures: DeviceSupportFeatures,
20842
21016
  deviceVerify: DeviceVerify,
20843
21017
  deviceWipe: DeviceWipe,
20844
- firmwareUpdate: FirmwareUpdate,
21018
+ firmwareUpdate: FirmwareUpdate$1,
21019
+ firmwareUpdateV2: FirmwareUpdate,
20845
21020
  requestWebUsbDevice: RequestWebUsbDevice,
20846
21021
  batchGetPublicKey: BatchGetPublicKey,
20847
21022
  cipherKeyValue: CipherKeyValue,
@@ -21296,7 +21471,7 @@ function initDevice(method) {
21296
21471
  } else if (allDevices.length === 1) {
21297
21472
  [device] = allDevices;
21298
21473
  } else if (allDevices.length > 1) {
21299
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.SelectDevice);
21474
+ throw hdShared.ERRORS.TypedError(method.name === 'firmwareUpdateV2' ? hdShared.HardwareErrorCode.FirmwareUpdateLimitOneDevice : hdShared.HardwareErrorCode.SelectDevice);
21300
21475
  }
21301
21476
 
21302
21477
  if (!device) {
@@ -21399,7 +21574,7 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
21399
21574
  } catch (error) {
21400
21575
  Log.debug('device error: ', error);
21401
21576
 
21402
- if ([hdShared.HardwareErrorCode.BlePermissionError, hdShared.HardwareErrorCode.BleLocationError, hdShared.HardwareErrorCode.BleLocationServicesDisabled, hdShared.HardwareErrorCode.BleDeviceNotBonded, hdShared.HardwareErrorCode.BleCharacteristicNotifyError, hdShared.HardwareErrorCode.BleWriteCharacteristicError, hdShared.HardwareErrorCode.BleAlreadyConnected].includes(error.errorCode)) {
21577
+ if ([hdShared.HardwareErrorCode.BlePermissionError, hdShared.HardwareErrorCode.BleLocationError, hdShared.HardwareErrorCode.BleLocationServicesDisabled, hdShared.HardwareErrorCode.BleDeviceNotBonded, hdShared.HardwareErrorCode.BleCharacteristicNotifyError, hdShared.HardwareErrorCode.BleWriteCharacteristicError, hdShared.HardwareErrorCode.BleAlreadyConnected, hdShared.HardwareErrorCode.FirmwareUpdateLimitOneDevice].includes(error.errorCode)) {
21403
21578
  reject(error);
21404
21579
  return;
21405
21580
  }
@@ -21747,6 +21922,7 @@ __webpack_unused_export__ = safeThrowError;
21747
21922
  exports.hZ = setLoggerPostMessage;
21748
21923
  __webpack_unused_export__ = versionCompare;
21749
21924
  __webpack_unused_export__ = versionSplit;
21925
+ __webpack_unused_export__ = wait;
21750
21926
 
21751
21927
  /***/ }),
21752
21928
 
@@ -22997,6 +23173,7 @@ const HardwareErrorCode = {
22997
23173
  FirmwareUpdateDownloadFailed: 406,
22998
23174
  CallMethodNeedUpgradeFirmware: 407,
22999
23175
  CallMethodDeprecated: 408,
23176
+ FirmwareUpdateLimitOneDevice: 409,
23000
23177
  NetworkError: 500,
23001
23178
  TransportNotConfigured: 600,
23002
23179
  TransportCallInProgress: 601,
@@ -23057,6 +23234,7 @@ const HardwareErrorCodeMessage = {
23057
23234
  [HardwareErrorCode.FirmwareUpdateDownloadFailed]: 'Firmware update download failed',
23058
23235
  [HardwareErrorCode.CallMethodNeedUpgradeFirmware]: 'Call method need upgrade firmware',
23059
23236
  [HardwareErrorCode.CallMethodDeprecated]: 'Call method is deprecated',
23237
+ [HardwareErrorCode.FirmwareUpdateLimitOneDevice]: 'Only one device can be connected during firmware upgrade',
23060
23238
  [HardwareErrorCode.NetworkError]: 'Network request error',
23061
23239
  [HardwareErrorCode.TransportNotConfigured]: 'Transport not configured',
23062
23240
  [HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
@@ -46478,7 +46656,7 @@ try {
46478
46656
  /***/ ((module) => {
46479
46657
 
46480
46658
  "use strict";
46481
- module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.1.53","description":"> TODO: description","author":"OneKey","homepage":"https://github.com/OneKeyHQ/hardware-js-sdk#readme","license":"ISC","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/OneKeyHQ/hardware-js-sdk.git"},"publishConfig":{"access":"public"},"scripts":{"dev":"rimraf dist && rollup -c ../../build/rollup.config.js -w","build":"rimraf dist && rollup -c ../../build/rollup.config.js","lint":"eslint .","lint:fix":"eslint . --fix"},"bugs":{"url":"https://github.com/OneKeyHQ/hardware-js-sdk/issues"},"dependencies":{"@onekeyfe/hd-shared":"^0.1.53","@onekeyfe/hd-transport":"^0.1.53","axios":"^0.27.2","bignumber.js":"^9.0.2","js-sha256":"^0.9.0","js-sha3":"^0.8.0","parse-uri":"^1.0.7","semver":"^7.3.7"},"devDependencies":{"@types/parse-uri":"^1.0.0","@types/semver":"^7.3.9"}}');
46659
+ module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.1.54","description":"> TODO: description","author":"OneKey","homepage":"https://github.com/OneKeyHQ/hardware-js-sdk#readme","license":"ISC","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/OneKeyHQ/hardware-js-sdk.git"},"publishConfig":{"access":"public"},"scripts":{"dev":"rimraf dist && rollup -c ../../build/rollup.config.js -w","build":"rimraf dist && rollup -c ../../build/rollup.config.js","lint":"eslint .","lint:fix":"eslint . --fix"},"bugs":{"url":"https://github.com/OneKeyHQ/hardware-js-sdk/issues"},"dependencies":{"@onekeyfe/hd-shared":"^0.1.54","@onekeyfe/hd-transport":"^0.1.54","axios":"^0.27.2","bignumber.js":"^9.0.2","js-sha256":"^0.9.0","js-sha3":"^0.8.0","parse-uri":"^1.0.7","semver":"^7.3.7"},"devDependencies":{"@types/parse-uri":"^1.0.0","@types/semver":"^7.3.9"}}');
46482
46660
 
46483
46661
  /***/ })
46484
46662
 
@@ -49010,7 +49188,7 @@ const src_init = async settings => {
49010
49188
 
49011
49189
  try {
49012
49190
  await init({ ..._settings,
49013
- version: "0.1.53"
49191
+ version: "0.1.54"
49014
49192
  });
49015
49193
  return true;
49016
49194
  } catch (e) {