@onekeyfe/hd-core 0.3.13 → 0.3.15
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/__tests__/checkBootloaderReleast.test.js +108 -0
- package/dist/api/firmware/bootloaderHelper.d.ts +9 -0
- package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +1 -1
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +25 -7
- package/dist/utils/deviceFeaturesUtils.d.ts +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/jest.config.js +5 -0
- package/package.json +6 -5
- package/src/api/firmware/bootloaderHelper.ts +32 -0
- package/src/api/firmware/getBinary.ts +0 -1
- package/src/api/firmware/updateBootloader.ts +8 -8
- package/src/device/DeviceCommands.ts +4 -0
- package/src/utils/deviceFeaturesUtils.ts +12 -3
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
const { shouldUpdateBootloaderForClassicAndMini } = require('../src/api/firmware/bootloaderHelper');
|
|
3
|
+
|
|
4
|
+
const fixtures = [
|
|
5
|
+
{
|
|
6
|
+
description: 'version: 2.10.0 -> 2.11.0, boot 1.9.0 -> boot 2.0.0, No need to upgrade',
|
|
7
|
+
currentVersion: '2.10.0',
|
|
8
|
+
bootloaderVersion: '1.9.0',
|
|
9
|
+
willUpdateFirmware: '2.11.0',
|
|
10
|
+
targetBootloaderVersion: [2, 0, 0],
|
|
11
|
+
bootloaderRelatedFirmwareVersion: [3, 0, 0],
|
|
12
|
+
shouldUpdateBootloader: false,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
description: 'version: 2.10.0 -> 3.0.0, boot 1.9.0 -> boot 2.0.0, Should upgrade bootloader',
|
|
16
|
+
currentVersion: '2.10.0',
|
|
17
|
+
bootloaderVersion: '1.9.0',
|
|
18
|
+
willUpdateFirmware: '3.0.0',
|
|
19
|
+
targetBootloaderVersion: [2, 0, 0],
|
|
20
|
+
bootloaderRelatedFirmwareVersion: [3, 0, 0],
|
|
21
|
+
shouldUpdateBootloader: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
description: 'version: 2.10.0 -> 3.0.0, boot 2.0.0 -> boot 2.0.0, No need to upgrade',
|
|
25
|
+
currentVersion: '2.10.0',
|
|
26
|
+
bootloaderVersion: '2.0.0',
|
|
27
|
+
willUpdateFirmware: '3.0.0',
|
|
28
|
+
targetBootloaderVersion: [2, 0, 0],
|
|
29
|
+
bootloaderRelatedFirmwareVersion: [3, 0, 0],
|
|
30
|
+
shouldUpdateBootloader: false,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
description: 'version: 3.0.0 -> 3.0.0, boot 2.0.0 -> boot 2.0.0, No need to upgrade',
|
|
34
|
+
currentVersion: '3.0.0',
|
|
35
|
+
bootloaderVersion: '2.0.0',
|
|
36
|
+
willUpdateFirmware: '3.0.0',
|
|
37
|
+
targetBootloaderVersion: [2, 0, 0],
|
|
38
|
+
bootloaderRelatedFirmwareVersion: [3, 0, 0],
|
|
39
|
+
shouldUpdateBootloader: false,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
description: 'version: 3.0.0 -> 3.1.0, boot 2.0.0 -> boot 2.0.0, No need to upgrade',
|
|
43
|
+
currentVersion: '3.0.0',
|
|
44
|
+
bootloaderVersion: '2.0.0',
|
|
45
|
+
willUpdateFirmware: '3.1.0',
|
|
46
|
+
targetBootloaderVersion: [2, 0, 0],
|
|
47
|
+
bootloaderRelatedFirmwareVersion: [3, 0, 0],
|
|
48
|
+
shouldUpdateBootloader: false,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
description: 'version: 2.11.0 -> 3.1.0, boot 1.9.0 -> boot 2.0.0, Should upgrade bootloader',
|
|
52
|
+
currentVersion: '2.11.0',
|
|
53
|
+
bootloaderVersion: '2.0.0',
|
|
54
|
+
willUpdateFirmware: '3.1.0',
|
|
55
|
+
targetBootloaderVersion: [2, 0, 0],
|
|
56
|
+
bootloaderRelatedFirmwareVersion: [3, 0, 0],
|
|
57
|
+
shouldUpdateBootloader: false,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
description: 'version: 2.11.0 -> 3.1.0, boot 2.0.0 -> boot 2.0.0, No need to upgrade',
|
|
61
|
+
currentVersion: '2.11.0',
|
|
62
|
+
bootloaderVersion: '2.0.0',
|
|
63
|
+
willUpdateFirmware: '3.1.0',
|
|
64
|
+
targetBootloaderVersion: [2, 0, 0],
|
|
65
|
+
bootloaderRelatedFirmwareVersion: [3, 0, 0],
|
|
66
|
+
shouldUpdateBootloader: false,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
description: 'version: 3.1.0 -> 3.2.0, boot 1.9.0 -> boot 2.0.0, Should upgrade bootloader',
|
|
70
|
+
currentVersion: '3.1.0',
|
|
71
|
+
bootloaderVersion: '1.9.0',
|
|
72
|
+
willUpdateFirmware: '3.2.0',
|
|
73
|
+
targetBootloaderVersion: [2, 0, 0],
|
|
74
|
+
bootloaderRelatedFirmwareVersion: [3, 0, 0],
|
|
75
|
+
shouldUpdateBootloader: true,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
description: 'version: 3.1.0 -> 3.3.0, boot 2.0.0 -> boot 2.0.0, No need to upgrade',
|
|
79
|
+
currentVersion: '3.1.0',
|
|
80
|
+
bootloaderVersion: '1.9.0',
|
|
81
|
+
willUpdateFirmware: '3.2.0',
|
|
82
|
+
targetBootloaderVersion: [2, 0, 0],
|
|
83
|
+
bootloaderRelatedFirmwareVersion: [3, 0, 0],
|
|
84
|
+
shouldUpdateBootloader: true,
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
describe('CheckBootloaderReleast', () => {
|
|
89
|
+
fixtures.forEach(data => {
|
|
90
|
+
test(data.description, () => {
|
|
91
|
+
const {
|
|
92
|
+
currentVersion,
|
|
93
|
+
bootloaderVersion,
|
|
94
|
+
willUpdateFirmware,
|
|
95
|
+
targetBootloaderVersion,
|
|
96
|
+
bootloaderRelatedFirmwareVersion,
|
|
97
|
+
} = data;
|
|
98
|
+
const shouldUpdateBootloader = shouldUpdateBootloaderForClassicAndMini({
|
|
99
|
+
currentVersion,
|
|
100
|
+
bootloaderVersion,
|
|
101
|
+
willUpdateFirmware,
|
|
102
|
+
targetBootloaderVersion,
|
|
103
|
+
bootloaderRelatedFirmwareVersion,
|
|
104
|
+
});
|
|
105
|
+
expect(shouldUpdateBootloader).toBe(data.shouldUpdateBootloader);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IVersionArray } from '../../types';
|
|
2
|
+
export declare function shouldUpdateBootloaderForClassicAndMini({ currentVersion, bootloaderVersion, willUpdateFirmware, targetBootloaderVersion, bootloaderRelatedFirmwareVersion, }: {
|
|
3
|
+
currentVersion: string;
|
|
4
|
+
bootloaderVersion: string;
|
|
5
|
+
willUpdateFirmware: string;
|
|
6
|
+
targetBootloaderVersion?: IVersionArray;
|
|
7
|
+
bootloaderRelatedFirmwareVersion: IVersionArray;
|
|
8
|
+
}): boolean;
|
|
9
|
+
//# sourceMappingURL=bootloaderHelper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootloaderHelper.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/bootloaderHelper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,wBAAgB,uCAAuC,CAAC,EACtD,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,gCAAgC,GACjC,EAAE;IACD,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,uBAAuB,CAAC,EAAE,aAAa,CAAC;IACxC,gCAAgC,EAAE,aAAa,CAAC;CACjD,WAgBA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBinary.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/getBinary.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAMvC,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,UAAU,GAAG,KAAK,CAAC;IAC/B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,cAAe,SAAQ,YAAY;IAC3C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,SAAS,2DAKnB,cAAc;;;;;;;;;;;;;;;;;;;;EAiChB,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAe,MAAM;;EAWrD,CAAC;AAEF,eAAO,MAAM,OAAO,4CAA6C,YAAY,
|
|
1
|
+
{"version":3,"file":"getBinary.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/getBinary.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAMvC,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,UAAU,GAAG,KAAK,CAAC;IAC/B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,cAAe,SAAQ,YAAY;IAC3C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,SAAS,2DAKnB,cAAc;;;;;;;;;;;;;;;;;;;;EAiChB,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAe,MAAM;;EAWrD,CAAC;AAEF,eAAO,MAAM,OAAO,4CAA6C,YAAY,2DAgB5E,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Features } from '../../types';
|
|
2
2
|
export declare function checkNeedUpdateBootForTouch(features: Features): boolean;
|
|
3
|
-
export declare function checkNeedUpdateBootForClassicAndMini(features: Features, willUpdateFirmware: string): boolean
|
|
3
|
+
export declare function checkNeedUpdateBootForClassicAndMini(features: Features, willUpdateFirmware: string): boolean;
|
|
4
4
|
export declare function checkBootloaderLength(data: ArrayBuffer): boolean;
|
|
5
5
|
//# sourceMappingURL=updateBootloader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/updateBootloader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"updateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/updateBootloader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AASvC,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,QAAQ,WAgB7D;AAED,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,QAAQ,EAClB,kBAAkB,EAAE,MAAM,WAuB3B;AAGD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,WAiBtD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceCommands.d.ts","sourceRoot":"","sources":["../../src/device/DeviceCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAe,MAAM,wBAAwB,CAAC;AAK/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,aAAK,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;AACxC,aAAK,UAAU,GAAG,MA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EAAE,MAAM;IAOpC,OAAO,CAAC,aAAa,EAAE,OAAO;IAU9B,IAAI,CACR,IAAI,EAAE,UAAU,EAChB,GAAG,GAAE,sBAAsB,CAAC,SAAS,CAAM,GAC1C,OAAO,CAAC,sBAAsB,CAAC;IAqClC,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAAE,EACpD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,EACV,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAE3C,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAClD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,EACV,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IA8C7B,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC;IAK3E,kBAAkB,CAChB,GAAG,EAAE,sBAAsB,EAC3B,QAAQ,EAAE,UAAU,GACnB,OAAO,CAAC,sBAAsB,CAAC;IA0HlC,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,oBAAoB;IAwB/C,iBAAiB;CA2BlB;AAED,oBAAY,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2212,14 +2212,14 @@ declare const getDeviceTypeByDeviceId: (deviceId?: string | undefined) => IDevic
|
|
|
2212
2212
|
declare const getDeviceUUID: (features: Features) => string;
|
|
2213
2213
|
declare const getDeviceLabel: (features: Features) => string;
|
|
2214
2214
|
declare const supportInputPinOnSoftware: (features: Features) => SupportFeatureType;
|
|
2215
|
-
declare const getFirmwareUpdateField: (features: Features, updateType: 'firmware' | 'ble') =>
|
|
2215
|
+
declare const getFirmwareUpdateField: (features: Features, updateType: 'firmware' | 'ble') => 'firmware' | 'ble' | 'firmware-v3' | 'firmware-v2';
|
|
2216
2216
|
|
|
2217
2217
|
declare const getHDPath: (path: string) => Array<number>;
|
|
2218
2218
|
declare const getScriptType: (path: Array<number>) => InputScriptType;
|
|
2219
2219
|
declare const getOutputScriptType: (path?: number[] | undefined) => ChangeOutputScriptType;
|
|
2220
2220
|
|
|
2221
2221
|
declare function checkNeedUpdateBootForTouch(features: Features): boolean;
|
|
2222
|
-
declare function checkNeedUpdateBootForClassicAndMini(features: Features, willUpdateFirmware: string): boolean
|
|
2222
|
+
declare function checkNeedUpdateBootForClassicAndMini(features: Features, willUpdateFirmware: string): boolean;
|
|
2223
2223
|
|
|
2224
2224
|
declare type LogMessage = {
|
|
2225
2225
|
level: string;
|
package/dist/index.js
CHANGED
|
@@ -918,12 +918,15 @@ const supportNewPassphrase = (features) => {
|
|
|
918
918
|
const getPassphraseState = (features, commands) => __awaiter(void 0, void 0, void 0, function* () {
|
|
919
919
|
if (!features)
|
|
920
920
|
return false;
|
|
921
|
-
const { message } = yield commands.typedCall('GetAddress', 'Address', {
|
|
921
|
+
const { message, type } = yield commands.typedCall('GetAddress', 'Address', {
|
|
922
922
|
address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
|
|
923
923
|
coin_name: 'Testnet',
|
|
924
924
|
script_type: 'SPENDADDRESS',
|
|
925
925
|
show_display: false,
|
|
926
926
|
});
|
|
927
|
+
if (type === 'CallMethodError') {
|
|
928
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
|
|
929
|
+
}
|
|
927
930
|
return message.address;
|
|
928
931
|
});
|
|
929
932
|
const supportBatchPublicKey = (features) => {
|
|
@@ -953,7 +956,7 @@ const getFirmwareUpdateField = (features, updateType) => {
|
|
|
953
956
|
return 'ble';
|
|
954
957
|
}
|
|
955
958
|
if (deviceType === 'classic' || deviceType === 'mini') {
|
|
956
|
-
return 'firmware-
|
|
959
|
+
return 'firmware-v3';
|
|
957
960
|
}
|
|
958
961
|
if (deviceType === 'touch') {
|
|
959
962
|
if (semver__default["default"].lt(deviceFirmwareVersion.join('.'), '3.4.0'))
|
|
@@ -11408,6 +11411,19 @@ const parseConnectSettings = (input = {}) => {
|
|
|
11408
11411
|
return settings;
|
|
11409
11412
|
};
|
|
11410
11413
|
|
|
11414
|
+
function shouldUpdateBootloaderForClassicAndMini({ currentVersion, bootloaderVersion, willUpdateFirmware, targetBootloaderVersion, bootloaderRelatedFirmwareVersion, }) {
|
|
11415
|
+
if (targetBootloaderVersion && semver__default["default"].gte(bootloaderVersion, targetBootloaderVersion.join('.'))) {
|
|
11416
|
+
return false;
|
|
11417
|
+
}
|
|
11418
|
+
if (semver__default["default"].gte(willUpdateFirmware, bootloaderRelatedFirmwareVersion.join('.'))) {
|
|
11419
|
+
return true;
|
|
11420
|
+
}
|
|
11421
|
+
if (semver__default["default"].gte(currentVersion, bootloaderRelatedFirmwareVersion.join('.'))) {
|
|
11422
|
+
return true;
|
|
11423
|
+
}
|
|
11424
|
+
return false;
|
|
11425
|
+
}
|
|
11426
|
+
|
|
11411
11427
|
function checkNeedUpdateBootForTouch(features) {
|
|
11412
11428
|
const deviceType = getDeviceType(features);
|
|
11413
11429
|
if (deviceType !== 'touch')
|
|
@@ -11436,10 +11452,13 @@ function checkNeedUpdateBootForClassicAndMini(features, willUpdateFirmware) {
|
|
|
11436
11452
|
const bootloaderRelatedFirmwareVersion = DataManager.getBootloaderRelatedFirmwareVersion(features);
|
|
11437
11453
|
if (!bootloaderRelatedFirmwareVersion)
|
|
11438
11454
|
return false;
|
|
11439
|
-
return (
|
|
11440
|
-
|
|
11441
|
-
|
|
11442
|
-
|
|
11455
|
+
return shouldUpdateBootloaderForClassicAndMini({
|
|
11456
|
+
currentVersion,
|
|
11457
|
+
bootloaderVersion,
|
|
11458
|
+
willUpdateFirmware,
|
|
11459
|
+
targetBootloaderVersion,
|
|
11460
|
+
bootloaderRelatedFirmwareVersion,
|
|
11461
|
+
});
|
|
11443
11462
|
}
|
|
11444
11463
|
const INIT_DATA_CHUNK_SIZE$1 = 16 * 1024;
|
|
11445
11464
|
function checkBootloaderLength(data) {
|
|
@@ -14070,7 +14089,6 @@ const getInfo = ({ features, updateType, targetVersion }) => {
|
|
|
14070
14089
|
firmwareUpdateField = 'firmware-v3';
|
|
14071
14090
|
}
|
|
14072
14091
|
}
|
|
14073
|
-
console.log('=====>>>getInfo: ', firmwareUpdateField);
|
|
14074
14092
|
const releaseInfo = (_b = (_a = deviceMap === null || deviceMap === void 0 ? void 0 : deviceMap[deviceType]) === null || _a === void 0 ? void 0 : _a[firmwareUpdateField]) !== null && _b !== void 0 ? _b : [];
|
|
14075
14093
|
return findLatestRelease(releaseInfo);
|
|
14076
14094
|
};
|
|
@@ -15,5 +15,5 @@ export declare const supportNewPassphrase: (features?: import("packages/hd-trans
|
|
|
15
15
|
export declare const getPassphraseState: (features: Features, commands: DeviceCommands) => Promise<string | false>;
|
|
16
16
|
export declare const supportBatchPublicKey: (features?: import("packages/hd-transport/dist").Features | undefined) => boolean;
|
|
17
17
|
export declare const supportModifyHomescreen: (features?: import("packages/hd-transport/dist").Features | undefined) => SupportFeatureType;
|
|
18
|
-
export declare const getFirmwareUpdateField: (features: Features, updateType: 'firmware' | 'ble') =>
|
|
18
|
+
export declare const getFirmwareUpdateField: (features: Features, updateType: 'firmware' | 'ble') => 'firmware' | 'ble' | 'firmware-v3' | 'firmware-v2';
|
|
19
19
|
//# sourceMappingURL=deviceFeaturesUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceFeaturesUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceFeaturesUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deviceFeaturesUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceFeaturesUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAA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
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -18,14 +18,15 @@
|
|
|
18
18
|
"dev": "rimraf dist && rollup -c ../../build/rollup.config.js -w",
|
|
19
19
|
"build": "rimraf dist && rollup -c ../../build/rollup.config.js",
|
|
20
20
|
"lint": "eslint .",
|
|
21
|
-
"lint:fix": "eslint . --fix"
|
|
21
|
+
"lint:fix": "eslint . --fix",
|
|
22
|
+
"test": "jest"
|
|
22
23
|
},
|
|
23
24
|
"bugs": {
|
|
24
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@onekeyfe/hd-shared": "^0.3.
|
|
28
|
-
"@onekeyfe/hd-transport": "^0.3.
|
|
28
|
+
"@onekeyfe/hd-shared": "^0.3.15",
|
|
29
|
+
"@onekeyfe/hd-transport": "^0.3.15",
|
|
29
30
|
"axios": "^0.27.2",
|
|
30
31
|
"bignumber.js": "^9.0.2",
|
|
31
32
|
"bytebuffer": "^5.0.1",
|
|
@@ -43,5 +44,5 @@
|
|
|
43
44
|
"@types/semver": "^7.3.9",
|
|
44
45
|
"ripple-keypairs": "^1.1.4"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "3c2dd011378ec987f6a9ab900d72a83bc6811608"
|
|
47
48
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import { IVersionArray } from '../../types';
|
|
3
|
+
|
|
4
|
+
export function shouldUpdateBootloaderForClassicAndMini({
|
|
5
|
+
currentVersion,
|
|
6
|
+
bootloaderVersion,
|
|
7
|
+
willUpdateFirmware,
|
|
8
|
+
targetBootloaderVersion,
|
|
9
|
+
bootloaderRelatedFirmwareVersion,
|
|
10
|
+
}: {
|
|
11
|
+
currentVersion: string;
|
|
12
|
+
bootloaderVersion: string;
|
|
13
|
+
willUpdateFirmware: string;
|
|
14
|
+
targetBootloaderVersion?: IVersionArray;
|
|
15
|
+
bootloaderRelatedFirmwareVersion: IVersionArray;
|
|
16
|
+
}) {
|
|
17
|
+
// If the current bootloader version is greater than or equal to the version that needs to be upgraded, then no upgrade is required
|
|
18
|
+
if (targetBootloaderVersion && semver.gte(bootloaderVersion, targetBootloaderVersion.join('.'))) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (semver.gte(willUpdateFirmware, bootloaderRelatedFirmwareVersion.join('.'))) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The current version is greater than the relatedVersion and the bootloader version is lower than the target bootloader version
|
|
27
|
+
if (semver.gte(currentVersion, bootloaderRelatedFirmwareVersion.join('.'))) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
@@ -84,7 +84,6 @@ export const getInfo = ({ features, updateType, targetVersion }: GetInfoProps) =
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
console.log('=====>>>getInfo: ', firmwareUpdateField);
|
|
88
87
|
const releaseInfo = deviceMap?.[deviceType]?.[firmwareUpdateField] ?? [];
|
|
89
88
|
return findLatestRelease(releaseInfo);
|
|
90
89
|
};
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
getDeviceFirmwareVersion,
|
|
8
8
|
} from '../../utils/deviceFeaturesUtils';
|
|
9
9
|
import { DataManager } from '../../data-manager';
|
|
10
|
+
import { shouldUpdateBootloaderForClassicAndMini } from './bootloaderHelper';
|
|
10
11
|
|
|
11
12
|
export function checkNeedUpdateBootForTouch(features: Features) {
|
|
12
13
|
const deviceType = getDeviceType(features);
|
|
@@ -44,14 +45,13 @@ export function checkNeedUpdateBootForClassicAndMini(
|
|
|
44
45
|
DataManager.getBootloaderRelatedFirmwareVersion(features);
|
|
45
46
|
if (!bootloaderRelatedFirmwareVersion) return false;
|
|
46
47
|
|
|
47
|
-
return (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
48
|
+
return shouldUpdateBootloaderForClassicAndMini({
|
|
49
|
+
currentVersion,
|
|
50
|
+
bootloaderVersion,
|
|
51
|
+
willUpdateFirmware,
|
|
52
|
+
targetBootloaderVersion,
|
|
53
|
+
bootloaderRelatedFirmwareVersion,
|
|
54
|
+
});
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
const INIT_DATA_CHUNK_SIZE = 16 * 1024;
|
|
@@ -142,6 +142,10 @@ export class DeviceCommands {
|
|
|
142
142
|
// throw bridge network error
|
|
143
143
|
if (error instanceof HardwareError) {
|
|
144
144
|
if (error.errorCode === HardwareErrorCode.ResponseUnexpectTypeError) {
|
|
145
|
+
// Do not intercept CallMethodError
|
|
146
|
+
// Do not intercept “assertType: Response of unexpected type” error
|
|
147
|
+
// Blocking the above two messages will not know what the specific error message is, and the specific error should be handled by the subsequent business logic.
|
|
148
|
+
|
|
145
149
|
if (error.message.indexOf('BridgeNetworkError') > -1) {
|
|
146
150
|
throw ERRORS.TypedError(HardwareErrorCode.BridgeNetworkError);
|
|
147
151
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
3
|
import { toHardened } from '../api/helpers/pathUtils';
|
|
3
4
|
import { DeviceCommands } from '../device/DeviceCommands';
|
|
4
5
|
import type {
|
|
@@ -139,13 +140,18 @@ export const supportNewPassphrase = (features?: Features): SupportFeatureType =>
|
|
|
139
140
|
|
|
140
141
|
export const getPassphraseState = async (features: Features, commands: DeviceCommands) => {
|
|
141
142
|
if (!features) return false;
|
|
142
|
-
const { message } = await commands.typedCall('GetAddress', 'Address', {
|
|
143
|
+
const { message, type } = await commands.typedCall('GetAddress', 'Address', {
|
|
143
144
|
address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
|
|
144
145
|
coin_name: 'Testnet',
|
|
145
146
|
script_type: 'SPENDADDRESS',
|
|
146
147
|
show_display: false,
|
|
147
148
|
});
|
|
148
149
|
|
|
150
|
+
// @ts-expect-error
|
|
151
|
+
if (type === 'CallMethodError') {
|
|
152
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
|
|
153
|
+
}
|
|
154
|
+
|
|
149
155
|
return message.address;
|
|
150
156
|
};
|
|
151
157
|
|
|
@@ -176,7 +182,10 @@ export const supportModifyHomescreen = (features?: Features): SupportFeatureType
|
|
|
176
182
|
/**
|
|
177
183
|
* Since 3.5.0, Touch uses the firmware-v3 field to get firmware release info
|
|
178
184
|
*/
|
|
179
|
-
export const getFirmwareUpdateField = (
|
|
185
|
+
export const getFirmwareUpdateField = (
|
|
186
|
+
features: Features,
|
|
187
|
+
updateType: 'firmware' | 'ble'
|
|
188
|
+
): 'firmware' | 'ble' | 'firmware-v3' | 'firmware-v2' => {
|
|
180
189
|
const deviceType = getDeviceType(features);
|
|
181
190
|
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
|
|
182
191
|
if (updateType === 'ble') {
|
|
@@ -184,7 +193,7 @@ export const getFirmwareUpdateField = (features: Features, updateType: 'firmware
|
|
|
184
193
|
}
|
|
185
194
|
|
|
186
195
|
if (deviceType === 'classic' || deviceType === 'mini') {
|
|
187
|
-
return 'firmware-
|
|
196
|
+
return 'firmware-v3';
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
if (deviceType === 'touch') {
|