@onekeyfe/hd-core 0.2.36 → 0.2.38

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":"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
+ {"version":3,"file":"DeviceUpdateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceUpdateBootloader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,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;CA+BV"}
@@ -1,3 +1,4 @@
1
1
  import { Features } from '../../types';
2
2
  export declare function checkNeedUpdateBoot(features: Features): boolean;
3
+ export declare function checkBootloaderLength(data: ArrayBuffer): boolean;
3
4
  //# sourceMappingURL=updateBootloader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/updateBootloader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,WAgBrD"}
1
+ {"version":3,"file":"updateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/updateBootloader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,WAgBrD;AAGD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,WAiBtD"}
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var semver = require('semver');
6
6
  var hdShared = require('@onekeyfe/hd-shared');
7
7
  var axios = require('axios');
8
+ var ByteBuffer = require('bytebuffer');
8
9
  var BigNumber = require('bignumber.js');
9
10
  var utils = require('@noble/hashes/utils');
10
11
  var blake2s = require('@noble/hashes/blake2s');
@@ -18,6 +19,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
18
19
 
19
20
  var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
20
21
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
22
+ var ByteBuffer__default = /*#__PURE__*/_interopDefaultLegacy(ByteBuffer);
21
23
  var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
22
24
  var JSZip__default = /*#__PURE__*/_interopDefaultLegacy(JSZip);
23
25
 
@@ -10849,6 +10851,21 @@ function checkNeedUpdateBoot(features) {
10849
10851
  semver__default["default"].gte(currentVersion, '4.1.0') &&
10850
10852
  semver__default["default"].lte(bootloaderVersion, targetBootloaderVersion.join('.')));
10851
10853
  }
10854
+ const INIT_DATA_CHUNK_SIZE$1 = 16 * 1024;
10855
+ function checkBootloaderLength(data) {
10856
+ const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE$1, data.byteLength)));
10857
+ const buffer = ByteBuffer__default["default"].wrap(chunk, undefined, undefined, true);
10858
+ buffer.LE();
10859
+ buffer.readByte();
10860
+ buffer.readByte();
10861
+ buffer.readByte();
10862
+ buffer.readByte();
10863
+ const hdrlen = buffer.readUint32();
10864
+ buffer.readUint32();
10865
+ const codelen = buffer.readUint32();
10866
+ const bootloaderLength = hdrlen + codelen;
10867
+ return bootloaderLength === data.byteLength;
10868
+ }
10852
10869
 
10853
10870
  const LOG_EVENT = 'LOG_EVENT';
10854
10871
  const LOG = {
@@ -13513,6 +13530,9 @@ class DeviceUpdateBootloader extends BaseMethod {
13513
13530
  const resource = yield getSysResourceBinary(resourceUrl);
13514
13531
  this.postTipMessage('DownloadLatestBootloaderResourceSuccess');
13515
13532
  if (resource) {
13533
+ if (!checkBootloaderLength(resource.binary)) {
13534
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CheckDownloadFileError);
13535
+ }
13516
13536
  yield updateBootloader(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, resource.binary);
13517
13537
  return Promise.resolve(true);
13518
13538
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.2.36",
3
+ "version": "0.2.38",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -24,10 +24,11 @@
24
24
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@onekeyfe/hd-shared": "^0.2.36",
28
- "@onekeyfe/hd-transport": "^0.2.36",
27
+ "@onekeyfe/hd-shared": "^0.2.38",
28
+ "@onekeyfe/hd-transport": "^0.2.38",
29
29
  "axios": "^0.27.2",
30
30
  "bignumber.js": "^9.0.2",
31
+ "bytebuffer": "^5.0.1",
31
32
  "jszip": "^3.10.1",
32
33
  "parse-uri": "^1.0.7",
33
34
  "semver": "^7.3.7"
@@ -42,5 +43,5 @@
42
43
  "@types/semver": "^7.3.9",
43
44
  "ripple-keypairs": "^1.1.4"
44
45
  },
45
- "gitHead": "53dfab54b8e9f221b4b855e5f36f2b618ebfcdd9"
46
+ "gitHead": "5c0a8dd681f9b2ae38b0555a86020b0a28ac3910"
46
47
  }
@@ -1,4 +1,4 @@
1
- import { Deferred } from '@onekeyfe/hd-shared';
1
+ import { Deferred, ERRORS, HardwareErrorCode } 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';
@@ -6,7 +6,7 @@ import { updateBootloader } from '../firmware/uploadFirmware';
6
6
  import { createUiMessage } from '../../events/ui-request';
7
7
  import type { KnownDevice } from '../../types';
8
8
  import { DataManager } from '../../data-manager';
9
- import { checkNeedUpdateBoot } from '../firmware/updateBootloader';
9
+ import { checkBootloaderLength, checkNeedUpdateBoot } from '../firmware/updateBootloader';
10
10
 
11
11
  export default class DeviceUpdateBootloader extends BaseMethod {
12
12
  checkPromise: Deferred<any> | null = null;
@@ -42,6 +42,9 @@ export default class DeviceUpdateBootloader extends BaseMethod {
42
42
  const resource = await getSysResourceBinary(resourceUrl);
43
43
  this.postTipMessage('DownloadLatestBootloaderResourceSuccess');
44
44
  if (resource) {
45
+ if (!checkBootloaderLength(resource.binary)) {
46
+ throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
47
+ }
45
48
  await updateBootloader(
46
49
  this.device.getCommands().typedCall.bind(this.device.getCommands()),
47
50
  this.postMessage,
@@ -1,3 +1,4 @@
1
+ import ByteBuffer from 'bytebuffer';
1
2
  import semver from 'semver';
2
3
  import { Features } from '../../types';
3
4
  import { getDeviceType } from '../../utils';
@@ -24,3 +25,23 @@ export function checkNeedUpdateBoot(features: Features) {
24
25
  semver.lte(bootloaderVersion, targetBootloaderVersion.join('.'))
25
26
  );
26
27
  }
28
+
29
+ const INIT_DATA_CHUNK_SIZE = 16 * 1024;
30
+ export function checkBootloaderLength(data: ArrayBuffer) {
31
+ const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
32
+ const buffer = ByteBuffer.wrap(chunk, undefined, undefined, true);
33
+ buffer.LE();
34
+ // byte 'O', 'K', 'T', 'B'
35
+ buffer.readByte();
36
+ buffer.readByte();
37
+ buffer.readByte();
38
+ buffer.readByte();
39
+ // g_header_end - g_header
40
+ const hdrlen = buffer.readUint32();
41
+ // word 0
42
+ buffer.readUint32();
43
+ // codelen
44
+ const codelen = buffer.readUint32();
45
+ const bootloaderLength = hdrlen + codelen;
46
+ return bootloaderLength === data.byteLength;
47
+ }