@onekeyfe/hd-core 0.2.35 → 0.2.37
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.
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +1 -0
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +27 -9
- package/dist/types/params.d.ts +0 -1
- package/dist/types/params.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/api/device/DeviceUpdateBootloader.ts +5 -2
- package/src/api/firmware/updateBootloader.ts +21 -0
- package/src/core/index.ts +7 -16
- package/src/types/params.ts +0 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceUpdateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceUpdateBootloader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/updateBootloader.ts"],"names":[],"mappings":"
|
|
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/core/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/index.d.ts
CHANGED
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
|
|
|
@@ -10842,6 +10844,21 @@ function checkNeedUpdateBoot(features) {
|
|
|
10842
10844
|
semver__default["default"].gte(currentVersion, '4.1.0') &&
|
|
10843
10845
|
semver__default["default"].lte(bootloaderVersion, targetBootloaderVersion.join('.')));
|
|
10844
10846
|
}
|
|
10847
|
+
const INIT_DATA_CHUNK_SIZE$1 = 16 * 1024;
|
|
10848
|
+
function checkBootloaderLength(data) {
|
|
10849
|
+
const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE$1, data.byteLength)));
|
|
10850
|
+
const buffer = ByteBuffer__default["default"].wrap(chunk, undefined, undefined, true);
|
|
10851
|
+
buffer.LE();
|
|
10852
|
+
buffer.readByte();
|
|
10853
|
+
buffer.readByte();
|
|
10854
|
+
buffer.readByte();
|
|
10855
|
+
buffer.readByte();
|
|
10856
|
+
const hdrlen = buffer.readUint32();
|
|
10857
|
+
buffer.readUint32();
|
|
10858
|
+
const codelen = buffer.readUint32();
|
|
10859
|
+
const bootloaderLength = hdrlen + codelen;
|
|
10860
|
+
return bootloaderLength === data.byteLength;
|
|
10861
|
+
}
|
|
10845
10862
|
|
|
10846
10863
|
const LOG_EVENT = 'LOG_EVENT';
|
|
10847
10864
|
const LOG = {
|
|
@@ -13506,6 +13523,9 @@ class DeviceUpdateBootloader extends BaseMethod {
|
|
|
13506
13523
|
const resource = yield getSysResourceBinary(resourceUrl);
|
|
13507
13524
|
this.postTipMessage('DownloadLatestBootloaderResourceSuccess');
|
|
13508
13525
|
if (resource) {
|
|
13526
|
+
if (!checkBootloaderLength(resource.binary)) {
|
|
13527
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CheckDownloadFileError);
|
|
13528
|
+
}
|
|
13509
13529
|
yield updateBootloader(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, resource.binary);
|
|
13510
13530
|
return Promise.resolve(true);
|
|
13511
13531
|
}
|
|
@@ -18426,7 +18446,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
18426
18446
|
(_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
|
|
18427
18447
|
device.on(DEVICE.PIN, onDevicePinHandler);
|
|
18428
18448
|
device.on(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
18429
|
-
device.on(DEVICE.PASSPHRASE,
|
|
18449
|
+
device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
|
|
18430
18450
|
device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
|
|
18431
18451
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
18432
18452
|
try {
|
|
@@ -18730,9 +18750,7 @@ const cancel = (connectId) => {
|
|
|
18730
18750
|
const checkPassphraseSafety = (method, features) => {
|
|
18731
18751
|
if (!method.useDevicePassphraseState)
|
|
18732
18752
|
return;
|
|
18733
|
-
if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true &&
|
|
18734
|
-
(method.payload.passphraseState == null || method.payload.passphraseState === '') &&
|
|
18735
|
-
!method.payload.useEmptyPassphrase) {
|
|
18753
|
+
if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true && !method.payload.passphraseState) {
|
|
18736
18754
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
18737
18755
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
|
|
18738
18756
|
}
|
|
@@ -18746,7 +18764,11 @@ const cleanup = () => {
|
|
|
18746
18764
|
Log.debug('Cleanup...');
|
|
18747
18765
|
};
|
|
18748
18766
|
const removeDeviceListener = (device) => {
|
|
18749
|
-
device.
|
|
18767
|
+
device.removeListener(DEVICE.PIN, onDevicePinHandler);
|
|
18768
|
+
device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
18769
|
+
device.removeListener(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
|
|
18770
|
+
device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
|
|
18771
|
+
device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
18750
18772
|
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
18751
18773
|
};
|
|
18752
18774
|
const closePopup = () => {
|
|
@@ -18802,10 +18824,6 @@ const onDevicePassphraseHandler = (...[device, callback]) => __awaiter(void 0, v
|
|
|
18802
18824
|
cache: save,
|
|
18803
18825
|
});
|
|
18804
18826
|
});
|
|
18805
|
-
const onEmptyPassphraseHandler = (...[_, callback]) => {
|
|
18806
|
-
Log.debug('onEmptyPassphraseHandler');
|
|
18807
|
-
callback({ passphrase: '' });
|
|
18808
|
-
};
|
|
18809
18827
|
const onEnterPassphraseOnDeviceHandler = (...[device]) => {
|
|
18810
18828
|
postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PASSPHRASE_ON_DEVICE, {
|
|
18811
18829
|
device: device.toMessageObject(),
|
package/dist/types/params.d.ts
CHANGED
|
@@ -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,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.37",
|
|
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.
|
|
28
|
-
"@onekeyfe/hd-transport": "^0.2.
|
|
27
|
+
"@onekeyfe/hd-shared": "^0.2.37",
|
|
28
|
+
"@onekeyfe/hd-transport": "^0.2.37",
|
|
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": "
|
|
46
|
+
"gitHead": "5d80d2bdb1f7e5863286c3e59064c858b245b3ca"
|
|
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
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -133,10 +133,7 @@ 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(
|
|
137
|
-
DEVICE.PASSPHRASE,
|
|
138
|
-
message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler
|
|
139
|
-
);
|
|
136
|
+
device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
|
|
140
137
|
device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
|
|
141
138
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
142
139
|
|
|
@@ -543,11 +540,7 @@ export const cancel = (connectId?: string) => {
|
|
|
543
540
|
const checkPassphraseSafety = (method: BaseMethod, features?: Features) => {
|
|
544
541
|
if (!method.useDevicePassphraseState) return;
|
|
545
542
|
|
|
546
|
-
if (
|
|
547
|
-
features?.passphrase_protection === true &&
|
|
548
|
-
(method.payload.passphraseState == null || method.payload.passphraseState === '') &&
|
|
549
|
-
!method.payload.useEmptyPassphrase
|
|
550
|
-
) {
|
|
543
|
+
if (features?.passphrase_protection === true && !method.payload.passphraseState) {
|
|
551
544
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
552
545
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceOpenedPassphrase);
|
|
553
546
|
}
|
|
@@ -564,7 +557,11 @@ const cleanup = () => {
|
|
|
564
557
|
};
|
|
565
558
|
|
|
566
559
|
const removeDeviceListener = (device: Device) => {
|
|
567
|
-
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);
|
|
568
565
|
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
569
566
|
// DevicePool.emitter.removeListener(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
|
|
570
567
|
};
|
|
@@ -644,12 +641,6 @@ const onDevicePassphraseHandler = async (...[device, callback]: DeviceEvents['pa
|
|
|
644
641
|
});
|
|
645
642
|
};
|
|
646
643
|
|
|
647
|
-
const onEmptyPassphraseHandler = (...[_, callback]: DeviceEvents['passphrase']) => {
|
|
648
|
-
Log.debug('onEmptyPassphraseHandler');
|
|
649
|
-
// send as PassphrasePromptResponse
|
|
650
|
-
callback({ passphrase: '' });
|
|
651
|
-
};
|
|
652
|
-
|
|
653
644
|
const onEnterPassphraseOnDeviceHandler = (
|
|
654
645
|
...[device]: [...DeviceEvents['passphrase_on_device']]
|
|
655
646
|
) => {
|