@onekeyfe/hd-core 1.1.18 → 1.1.19-alpha.1
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/BaseMethod.d.ts +9 -4
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdate.d.ts +1 -1
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +3 -2
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +2 -2
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +2 -2
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceFullyUploadResource.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +6 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +6 -3
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/releaseHelper.d.ts +7 -2
- package/dist/api/firmware/releaseHelper.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +7 -2
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +4 -4
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +16 -9
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +5 -2
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +6 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/events/device.d.ts +2 -2
- package/dist/events/device.d.ts.map +1 -1
- package/dist/index.d.ts +96 -28
- package/dist/index.js +543 -132
- package/dist/types/api/checkAllFirmwareRelease.d.ts +5 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/checkBootloaderRelease.d.ts +5 -2
- package/dist/types/api/checkBootloaderRelease.d.ts.map +1 -1
- package/dist/types/api/checkFirmwareRelease.d.ts +6 -2
- package/dist/types/api/checkFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceFullyUploadResource.d.ts +6 -1
- package/dist/types/api/deviceFullyUploadResource.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -3
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +3 -1
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +128 -128
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/device.d.ts +4 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/settings.d.ts +3 -0
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +7 -5
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/release.d.ts +1 -1
- package/dist/utils/release.d.ts.map +1 -1
- package/dist/utils/tracing.d.ts +34 -0
- package/dist/utils/tracing.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +55 -8
- package/src/api/CheckAllFirmwareRelease.ts +14 -6
- package/src/api/CheckBootloaderRelease.ts +13 -2
- package/src/api/CheckFirmwareRelease.ts +9 -2
- package/src/api/FirmwareUpdate.ts +7 -5
- package/src/api/FirmwareUpdateV2.ts +26 -14
- package/src/api/FirmwareUpdateV3.ts +31 -18
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +56 -26
- package/src/api/device/DeviceFullyUploadResource.ts +8 -2
- package/src/api/device/DeviceUpdateBootloader.ts +21 -5
- package/src/api/firmware/getBinary.ts +15 -4
- package/src/api/firmware/releaseHelper.ts +22 -11
- package/src/api/firmware/updateBootloader.ts +17 -9
- package/src/api/firmware/uploadFirmware.ts +51 -15
- package/src/api/sui/SuiSignTransaction.ts +7 -1
- package/src/core/index.ts +111 -8
- package/src/data/messages/messages.json +11 -1
- package/src/data-manager/DataManager.ts +126 -22
- package/src/device/Device.ts +24 -3
- package/src/device/DeviceCommands.ts +42 -8
- package/src/events/device.ts +2 -2
- package/src/types/api/checkAllFirmwareRelease.ts +5 -1
- package/src/types/api/checkBootloaderRelease.ts +7 -3
- package/src/types/api/checkFirmwareRelease.ts +10 -2
- package/src/types/api/deviceFullyUploadResource.ts +7 -1
- package/src/types/api/deviceUpdateBootloader.ts +8 -4
- package/src/types/api/firmwareUpdate.ts +4 -1
- package/src/types/api/index.ts +128 -161
- package/src/types/device.ts +7 -1
- package/src/types/settings.ts +37 -0
- package/src/utils/deviceFeaturesUtils.ts +22 -10
- package/src/utils/index.ts +1 -0
- package/src/utils/release.ts +2 -1
- package/src/utils/tracing.ts +251 -0
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
+
EFirmwareType,
|
|
2
3
|
ERRORS,
|
|
3
|
-
HardwareErrorCode,
|
|
4
4
|
HardwareError,
|
|
5
|
+
HardwareErrorCode,
|
|
5
6
|
createDeferred,
|
|
6
|
-
Deferred,
|
|
7
7
|
} from '@onekeyfe/hd-shared';
|
|
8
|
+
|
|
8
9
|
import { UI_REQUEST } from '../constants/ui-request';
|
|
9
10
|
import { BaseMethod } from './BaseMethod';
|
|
10
11
|
import { validateParams } from './helpers/paramsValidator';
|
|
11
12
|
import { getBinary } from './firmware/getBinary';
|
|
12
13
|
import { uploadFirmware } from './firmware/uploadFirmware';
|
|
13
14
|
import { createUiMessage } from '../events';
|
|
14
|
-
import { type KnownDevice
|
|
15
|
-
|
|
15
|
+
import { DeviceModelToTypes, type KnownDevice } from '../types';
|
|
16
16
|
import { isEnteredManuallyBoot } from './firmware/bootloaderHelper';
|
|
17
|
-
|
|
18
17
|
import { LoggerNames, getDeviceType, getDeviceUUID, getLogger, wait } from '../utils';
|
|
19
18
|
import { DataManager } from '../data-manager';
|
|
20
19
|
import { DevicePool } from '../device/DevicePool';
|
|
21
20
|
|
|
21
|
+
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
22
|
+
|
|
22
23
|
type Params = {
|
|
23
24
|
binary?: ArrayBuffer;
|
|
24
25
|
version?: number[];
|
|
@@ -189,6 +190,7 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
|
|
|
189
190
|
features: device.features,
|
|
190
191
|
version: params.version,
|
|
191
192
|
updateType: params.updateType,
|
|
193
|
+
firmwareType: EFirmwareType.Universal,
|
|
192
194
|
});
|
|
193
195
|
binary = firmware.binary;
|
|
194
196
|
this.postTipMessage('DownloadFirmwareSuccess');
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
Deferred,
|
|
2
|
+
type Deferred,
|
|
4
3
|
EDeviceType,
|
|
4
|
+
type EFirmwareType,
|
|
5
5
|
ERRORS,
|
|
6
6
|
HardwareError,
|
|
7
7
|
HardwareErrorCode,
|
|
8
|
+
createDeferred,
|
|
8
9
|
} from '@onekeyfe/hd-shared';
|
|
9
10
|
import semver from 'semver';
|
|
11
|
+
|
|
10
12
|
import { UI_REQUEST } from '../constants/ui-request';
|
|
11
13
|
import { BaseMethod } from './BaseMethod';
|
|
12
14
|
import { validateParams } from './helpers/paramsValidator';
|
|
@@ -14,20 +16,21 @@ import { DevicePool } from '../device/DevicePool';
|
|
|
14
16
|
import { getBinary, getInfo, getSysResourceBinary } from './firmware/getBinary';
|
|
15
17
|
import { updateResources, uploadFirmware } from './firmware/uploadFirmware';
|
|
16
18
|
import {
|
|
19
|
+
LoggerNames,
|
|
20
|
+
getDeviceFirmwareVersion,
|
|
17
21
|
getDeviceType,
|
|
18
22
|
getDeviceUUID,
|
|
19
|
-
|
|
23
|
+
getFirmwareType,
|
|
20
24
|
getLogger,
|
|
21
|
-
|
|
22
|
-
getDeviceFirmwareVersion,
|
|
25
|
+
wait,
|
|
23
26
|
} from '../utils';
|
|
24
|
-
import {
|
|
27
|
+
import { FirmwareUpdateTipMessage, createUiMessage } from '../events/ui-request';
|
|
25
28
|
import { DeviceModelToTypes } from '../types';
|
|
26
29
|
import { DataManager } from '../data-manager';
|
|
30
|
+
import { DEVICE } from '../events';
|
|
27
31
|
|
|
28
|
-
import type {
|
|
32
|
+
import type { Features, KnownDevice } from '../types';
|
|
29
33
|
import type { Device } from '../device/Device';
|
|
30
|
-
import { DEVICE } from '../events';
|
|
31
34
|
|
|
32
35
|
type Params = {
|
|
33
36
|
binary?: ArrayBuffer;
|
|
@@ -35,6 +38,7 @@ type Params = {
|
|
|
35
38
|
updateType: 'firmware' | 'ble';
|
|
36
39
|
forcedUpdateRes?: boolean;
|
|
37
40
|
isUpdateBootloader?: boolean;
|
|
41
|
+
firmwareType?: EFirmwareType;
|
|
38
42
|
};
|
|
39
43
|
|
|
40
44
|
const Log = getLogger(LoggerNames.Method);
|
|
@@ -55,6 +59,7 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
55
59
|
{ name: 'binary', type: 'buffer' },
|
|
56
60
|
{ name: 'forcedUpdateRes', type: 'boolean' },
|
|
57
61
|
{ name: 'platform', type: 'string', required: true },
|
|
62
|
+
{ name: 'firmwareType', type: 'string' },
|
|
58
63
|
]);
|
|
59
64
|
|
|
60
65
|
if (!payload.updateType) {
|
|
@@ -74,6 +79,7 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
74
79
|
this.params = {
|
|
75
80
|
...this.params,
|
|
76
81
|
version: payload.version,
|
|
82
|
+
firmwareType: payload.firmwareType,
|
|
77
83
|
};
|
|
78
84
|
}
|
|
79
85
|
|
|
@@ -246,14 +252,14 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
246
252
|
* Check the version number of Touch to determine if it
|
|
247
253
|
* needs to be upgraded via the desktop
|
|
248
254
|
*/
|
|
249
|
-
checkVersionForCopyTouchResource(features
|
|
255
|
+
checkVersionForCopyTouchResource(features: Features | undefined, firmwareType: EFirmwareType) {
|
|
250
256
|
if (!features) return;
|
|
251
257
|
const deviceType = getDeviceType(features);
|
|
252
258
|
const currentVersion = getDeviceFirmwareVersion(features).join('.');
|
|
253
259
|
const targetVersion = this.params.version?.join('.');
|
|
254
260
|
const { updateType } = this.params;
|
|
255
261
|
|
|
256
|
-
const releaseInfo = getInfo({ features, updateType });
|
|
262
|
+
const releaseInfo = getInfo({ features, updateType, firmwareType });
|
|
257
263
|
if (!releaseInfo) return;
|
|
258
264
|
const { fullResourceRange } = releaseInfo;
|
|
259
265
|
if (!fullResourceRange) return;
|
|
@@ -275,7 +281,10 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
275
281
|
const { features, commands } = device;
|
|
276
282
|
const deviceType = getDeviceType(features);
|
|
277
283
|
|
|
278
|
-
|
|
284
|
+
const deviceFirmwareType = getFirmwareType(device.features);
|
|
285
|
+
const firmwareType = params.firmwareType ?? deviceFirmwareType;
|
|
286
|
+
|
|
287
|
+
this.checkVersionForCopyTouchResource(features, firmwareType);
|
|
279
288
|
|
|
280
289
|
if (!features?.bootloader_mode && features) {
|
|
281
290
|
const uuid = getDeviceUUID(features);
|
|
@@ -287,10 +296,11 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
287
296
|
// check & upgrade firmware resource
|
|
288
297
|
if (features && this.isSupportResourceUpdate(features, params.updateType)) {
|
|
289
298
|
this.postTipMessage('CheckLatestUiResource');
|
|
290
|
-
const resourceUrl = DataManager.getSysResourcesLatestRelease(
|
|
299
|
+
const resourceUrl = DataManager.getSysResourcesLatestRelease({
|
|
291
300
|
features,
|
|
292
|
-
params.forcedUpdateRes
|
|
293
|
-
|
|
301
|
+
forcedUpdateRes: params.forcedUpdateRes,
|
|
302
|
+
firmwareType,
|
|
303
|
+
});
|
|
294
304
|
if (resourceUrl) {
|
|
295
305
|
this.postTipMessage('DownloadLatestUiResource');
|
|
296
306
|
const resource = await getSysResourceBinary(resourceUrl);
|
|
@@ -360,11 +370,13 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
360
370
|
);
|
|
361
371
|
}
|
|
362
372
|
this.postTipMessage('DownloadFirmware');
|
|
373
|
+
|
|
363
374
|
const firmware = await getBinary({
|
|
364
375
|
features: device.features,
|
|
365
376
|
version: params.version,
|
|
366
377
|
updateType: params.updateType,
|
|
367
378
|
isUpdateBootloader: params.isUpdateBootloader,
|
|
379
|
+
firmwareType,
|
|
368
380
|
});
|
|
369
381
|
binary = firmware.binary;
|
|
370
382
|
this.postTipMessage('DownloadFirmwareSuccess');
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EDeviceType, ERRORS, HardwareErrorCode, wait } from '@onekeyfe/hd-shared';
|
|
2
2
|
import semver from 'semver';
|
|
3
3
|
import JSZip from 'jszip';
|
|
4
|
-
import { UI_REQUEST, FirmwareUpdateTipMessage } from '../events/ui-request';
|
|
5
|
-
import { validateParams } from './helpers/paramsValidator';
|
|
6
4
|
|
|
5
|
+
import { FirmwareUpdateTipMessage, UI_REQUEST } from '../events/ui-request';
|
|
6
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
getDeviceBootloaderVersion,
|
|
8
|
+
LoggerNames,
|
|
10
9
|
getDeviceBLEFirmwareVersion,
|
|
10
|
+
getDeviceBootloaderVersion,
|
|
11
11
|
getDeviceFirmwareVersion,
|
|
12
|
-
|
|
12
|
+
getDeviceType,
|
|
13
|
+
getFirmwareType,
|
|
13
14
|
getLogger,
|
|
14
15
|
} from '../utils';
|
|
15
16
|
import { getBinary, getSysResourceBinary } from './firmware/getBinary';
|
|
16
17
|
import { DataManager } from '../data-manager';
|
|
17
|
-
import { FirmwareUpdateV3Params } from '../types/api/firmwareUpdate';
|
|
18
18
|
import { FirmwareUpdateBaseMethod } from './firmware/FirmwareUpdateBaseMethod';
|
|
19
19
|
import { DevicePool } from '../device/DevicePool';
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
import type { FirmwareUpdateV3Params } from '../types/api/firmwareUpdate';
|
|
22
|
+
import type { Deferred, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
23
|
+
import type { TypedResponseMessage } from '../device/DeviceCommands';
|
|
21
24
|
|
|
22
25
|
const Log = getLogger(LoggerNames.Method);
|
|
23
26
|
|
|
@@ -54,6 +57,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
54
57
|
{ name: 'forcedUpdateRes', type: 'boolean' },
|
|
55
58
|
{ name: 'bootloaderVersion', type: 'array' },
|
|
56
59
|
{ name: 'bootloaderBinary', type: 'buffer' },
|
|
60
|
+
{ name: 'firmwareType', type: 'string' },
|
|
57
61
|
{ name: 'platform', type: 'string' },
|
|
58
62
|
]);
|
|
59
63
|
|
|
@@ -66,6 +70,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
66
70
|
bootloaderBinary: payload.bootloaderBinary,
|
|
67
71
|
firmwareVersion: payload.firmwareVersion,
|
|
68
72
|
resourceBinary: payload.resourceBinary,
|
|
73
|
+
firmwareType: payload.firmwareType,
|
|
69
74
|
platform: payload.platform,
|
|
70
75
|
};
|
|
71
76
|
}
|
|
@@ -83,14 +88,17 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
83
88
|
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device features not available');
|
|
84
89
|
}
|
|
85
90
|
|
|
91
|
+
const deviceFirmwareType = getFirmwareType(features);
|
|
92
|
+
const firmwareType = this.params.firmwareType ?? deviceFirmwareType;
|
|
93
|
+
|
|
86
94
|
let resourceBinary: ArrayBuffer | null = null;
|
|
87
95
|
let fwBinaryMap: { fileName: string; binary: ArrayBuffer }[] = [];
|
|
88
96
|
let bootloaderBinary: ArrayBuffer | null = null;
|
|
89
97
|
try {
|
|
90
98
|
this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
91
|
-
resourceBinary = await this.prepareResourceBinary();
|
|
92
|
-
fwBinaryMap = await this.prepareFirmwareAndBleBinary();
|
|
93
|
-
bootloaderBinary = await this.prepareBootloaderBinary();
|
|
99
|
+
resourceBinary = await this.prepareResourceBinary(firmwareType);
|
|
100
|
+
fwBinaryMap = await this.prepareFirmwareAndBleBinary(firmwareType);
|
|
101
|
+
bootloaderBinary = await this.prepareBootloaderBinary(firmwareType);
|
|
94
102
|
this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
95
103
|
} catch (err) {
|
|
96
104
|
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, err.message ?? err);
|
|
@@ -130,16 +138,17 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
130
138
|
}
|
|
131
139
|
}
|
|
132
140
|
|
|
133
|
-
private async prepareResourceBinary() {
|
|
141
|
+
private async prepareResourceBinary(firmwareType: EFirmwareType) {
|
|
134
142
|
if (this.params.resourceBinary) {
|
|
135
143
|
return this.params.resourceBinary;
|
|
136
144
|
}
|
|
137
145
|
const { features } = this.device;
|
|
138
146
|
if (!features) return null;
|
|
139
|
-
const resourceUrl = DataManager.getSysResourcesLatestRelease(
|
|
147
|
+
const resourceUrl = DataManager.getSysResourcesLatestRelease({
|
|
140
148
|
features,
|
|
141
|
-
this.params.forcedUpdateRes
|
|
142
|
-
|
|
149
|
+
forcedUpdateRes: this.params.forcedUpdateRes,
|
|
150
|
+
firmwareType,
|
|
151
|
+
});
|
|
143
152
|
|
|
144
153
|
if (resourceUrl) {
|
|
145
154
|
const resource = (await getSysResourceBinary(resourceUrl)).binary;
|
|
@@ -149,7 +158,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
149
158
|
return null;
|
|
150
159
|
}
|
|
151
160
|
|
|
152
|
-
private async prepareBootloaderBinary(): Promise<ArrayBuffer | null> {
|
|
161
|
+
private async prepareBootloaderBinary(firmwareType: EFirmwareType): Promise<ArrayBuffer | null> {
|
|
153
162
|
if (this.params.bootloaderBinary) {
|
|
154
163
|
return this.params.bootloaderBinary;
|
|
155
164
|
}
|
|
@@ -157,7 +166,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
157
166
|
if (!features) return null;
|
|
158
167
|
|
|
159
168
|
if (this.params.bootloaderVersion) {
|
|
160
|
-
const bootResourceUrl = DataManager.getBootloaderResource(features);
|
|
169
|
+
const bootResourceUrl = DataManager.getBootloaderResource(features, firmwareType);
|
|
161
170
|
if (bootResourceUrl) {
|
|
162
171
|
const bootBinary = (await getSysResourceBinary(bootResourceUrl)).binary;
|
|
163
172
|
return bootBinary;
|
|
@@ -166,7 +175,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
166
175
|
return null;
|
|
167
176
|
}
|
|
168
177
|
|
|
169
|
-
private async prepareFirmwareAndBleBinary() {
|
|
178
|
+
private async prepareFirmwareAndBleBinary(firmwareType: EFirmwareType) {
|
|
170
179
|
const fwBinaryMap: { fileName: string; binary: ArrayBuffer }[] = [];
|
|
171
180
|
if (this.params.firmwareBinary) {
|
|
172
181
|
fwBinaryMap.push({
|
|
@@ -182,6 +191,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
182
191
|
version: this.params.firmwareVersion,
|
|
183
192
|
updateType: 'firmware',
|
|
184
193
|
isUpdateBootloader: false,
|
|
194
|
+
firmwareType,
|
|
185
195
|
})
|
|
186
196
|
).binary;
|
|
187
197
|
fwBinaryMap.push({
|
|
@@ -203,6 +213,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
203
213
|
features,
|
|
204
214
|
version: this.params.bleVersion,
|
|
205
215
|
updateType: 'ble',
|
|
216
|
+
firmwareType,
|
|
206
217
|
});
|
|
207
218
|
fwBinaryMap.push({
|
|
208
219
|
fileName: 'ble-firmware.bin',
|
|
@@ -288,6 +299,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
288
299
|
if (error?.errorCode) {
|
|
289
300
|
const unexpectedError = [
|
|
290
301
|
HardwareErrorCode.ActionCancelled,
|
|
302
|
+
HardwareErrorCode.CallQueueActionCancelled,
|
|
291
303
|
HardwareErrorCode.FirmwareVerificationFailed,
|
|
292
304
|
// BLE connection errors
|
|
293
305
|
HardwareErrorCode.BleDeviceNotBonded,
|
|
@@ -354,6 +366,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
354
366
|
firmwareVersion,
|
|
355
367
|
};
|
|
356
368
|
} catch (error) {
|
|
369
|
+
// Hardware install firmware progress message
|
|
357
370
|
if (error.message && error.message.includes('Update mode')) {
|
|
358
371
|
const updateParts = error.message.split('Update mode ');
|
|
359
372
|
const progressValue = updateParts[1] ?? '0';
|
|
@@ -9,22 +9,26 @@ import {
|
|
|
9
9
|
import { serializedPath, toHardened } from '../helpers/pathUtils';
|
|
10
10
|
import { BaseMethod } from '../BaseMethod';
|
|
11
11
|
import { validateParams } from '../helpers/paramsValidator';
|
|
12
|
-
import { CoreApi } from '../../types';
|
|
13
|
-
import type {
|
|
14
|
-
AllNetworkAddressParams,
|
|
15
|
-
INetwork,
|
|
16
|
-
AllNetworkAddress,
|
|
17
|
-
CommonResponseParams,
|
|
18
|
-
} from '../../types/api/allNetworkGetAddress';
|
|
19
12
|
import { PROTO } from '../../constants';
|
|
20
|
-
|
|
21
13
|
import { findMethod } from '../utils';
|
|
22
|
-
import {
|
|
14
|
+
import { DEVICE, IFRAME, createUiMessage } from '../../events';
|
|
23
15
|
import { getDeviceFirmwareVersion, getMethodVersionRange } from '../../utils';
|
|
24
|
-
import { Device, DeviceEvents } from '../../device/Device';
|
|
25
16
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
26
17
|
import { onDeviceButtonHandler } from '../../core';
|
|
27
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
completeRequestContext,
|
|
20
|
+
createRequestContext,
|
|
21
|
+
updateRequestContext,
|
|
22
|
+
} from '../../utils/tracing';
|
|
23
|
+
|
|
24
|
+
import type { Device, DeviceEvents } from '../../device/Device';
|
|
25
|
+
import type { CoreApi } from '../../types';
|
|
26
|
+
import type {
|
|
27
|
+
AllNetworkAddress,
|
|
28
|
+
AllNetworkAddressParams,
|
|
29
|
+
CommonResponseParams,
|
|
30
|
+
INetwork,
|
|
31
|
+
} from '../../types/api/allNetworkGetAddress';
|
|
28
32
|
|
|
29
33
|
const Mainnet = 'mainnet';
|
|
30
34
|
|
|
@@ -322,6 +326,27 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
322
326
|
|
|
323
327
|
method.connector = this.connector;
|
|
324
328
|
method.postMessage = this.postMessage;
|
|
329
|
+
if (this.context) {
|
|
330
|
+
method.setContext?.(this.context);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
method.requestContext = createRequestContext(method.responseID, methodName, {
|
|
334
|
+
sdkInstanceId: this.sdkInstanceId,
|
|
335
|
+
connectId: this.payload.connectId,
|
|
336
|
+
parentResponseID: this.responseID,
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
const onSignalAbort = () => {
|
|
340
|
+
this.abortController?.abort(HardwareErrorCodeMessage[HardwareErrorCode.RepeatUnlocking]);
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const buttonListener = (...[device, request]: [...DeviceEvents['button']]) => {
|
|
344
|
+
if (request.code === 'ButtonRequest_PinEntry' || request.code === 'ButtonRequest_AttachPin') {
|
|
345
|
+
onSignalAbort();
|
|
346
|
+
} else {
|
|
347
|
+
onDeviceButtonHandler(device, request);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
325
350
|
|
|
326
351
|
let result: AllNetworkAddress[];
|
|
327
352
|
try {
|
|
@@ -329,23 +354,15 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
329
354
|
method.setDevice?.(this.device);
|
|
330
355
|
method.context = this.context;
|
|
331
356
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
request.code === 'ButtonRequest_PinEntry' ||
|
|
339
|
-
request.code === 'ButtonRequest_AttachPin'
|
|
340
|
-
) {
|
|
341
|
-
onSignalAbort();
|
|
342
|
-
} else {
|
|
343
|
-
onDeviceButtonHandler(device, request);
|
|
344
|
-
}
|
|
345
|
-
};
|
|
357
|
+
if (method.requestContext && this.device) {
|
|
358
|
+
updateRequestContext(method.requestContext.responseID, {
|
|
359
|
+
deviceInstanceId: this.device.instanceId,
|
|
360
|
+
commandsInstanceId: this.device.commands?.instanceId,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
346
363
|
|
|
347
364
|
// pro pin event
|
|
348
|
-
this.device.on(DEVICE.BUTTON,
|
|
365
|
+
this.device.on(DEVICE.BUTTON, buttonListener);
|
|
349
366
|
// classic pin event
|
|
350
367
|
this.device.on(DEVICE.PIN, onSignalAbort);
|
|
351
368
|
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
@@ -366,6 +383,9 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
366
383
|
rootFingerprint,
|
|
367
384
|
},
|
|
368
385
|
}));
|
|
386
|
+
if (method.requestContext) {
|
|
387
|
+
completeRequestContext(method.requestContext.responseID);
|
|
388
|
+
}
|
|
369
389
|
} catch (e: any) {
|
|
370
390
|
const error = handleSkippableHardwareError(e, this.device, method);
|
|
371
391
|
|
|
@@ -384,6 +404,16 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
384
404
|
} else {
|
|
385
405
|
throw e;
|
|
386
406
|
}
|
|
407
|
+
if (method.requestContext) {
|
|
408
|
+
completeRequestContext(
|
|
409
|
+
method.requestContext.responseID,
|
|
410
|
+
e instanceof Error ? e : new Error(String(e))
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
} finally {
|
|
414
|
+
this.device.off(DEVICE.BUTTON, buttonListener);
|
|
415
|
+
this.device.off(DEVICE.PIN, onSignalAbort);
|
|
416
|
+
this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
|
|
387
417
|
}
|
|
388
418
|
|
|
389
419
|
return result;
|
|
@@ -4,10 +4,11 @@ import { UI_REQUEST } from '../../constants/ui-request';
|
|
|
4
4
|
import { BaseMethod } from '../BaseMethod';
|
|
5
5
|
import { getSysResourceBinary } from '../firmware/getBinary';
|
|
6
6
|
import { updateResources } from '../firmware/uploadFirmware';
|
|
7
|
-
import { getDeviceType, getDeviceFirmwareVersion } from '../../utils';
|
|
7
|
+
import { getDeviceType, getDeviceFirmwareVersion, getFirmwareType } from '../../utils';
|
|
8
8
|
import { createUiMessage } from '../../events/ui-request';
|
|
9
9
|
import type { KnownDevice, Features } from '../../types';
|
|
10
10
|
import { DataManager } from '../../data-manager';
|
|
11
|
+
import type { DeviceFullyUploadResourceParams } from '../../types/api/deviceFullyUploadResource';
|
|
11
12
|
|
|
12
13
|
export default class DeviceFullyUploadResource extends BaseMethod {
|
|
13
14
|
checkPromise: Deferred<any> | null = null;
|
|
@@ -43,13 +44,18 @@ export default class DeviceFullyUploadResource extends BaseMethod {
|
|
|
43
44
|
const { device } = this;
|
|
44
45
|
const { features } = device;
|
|
45
46
|
|
|
47
|
+
const payload = this.payload as DeviceFullyUploadResourceParams;
|
|
48
|
+
|
|
49
|
+
const deviceFirmwareType = getFirmwareType(features);
|
|
50
|
+
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
51
|
+
|
|
46
52
|
if (!features?.bootloader_mode && features) {
|
|
47
53
|
// check & upgrade firmware resource
|
|
48
54
|
if (features) {
|
|
49
55
|
let { binary } = this.payload;
|
|
50
56
|
if (!binary) {
|
|
51
57
|
this.postTipMessage('CheckLatestUiResource');
|
|
52
|
-
const resourceUrl = DataManager.getSysFullResource(features);
|
|
58
|
+
const resourceUrl = DataManager.getSysFullResource(features, firmwareType);
|
|
53
59
|
if (resourceUrl) {
|
|
54
60
|
this.postTipMessage('DownloadLatestUiResource');
|
|
55
61
|
const resource = await getSysResourceBinary(resourceUrl);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
1
|
+
import { EFirmwareType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
2
|
import { RebootType } from '@onekeyfe/hd-transport';
|
|
3
3
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
4
4
|
import { FirmwareUpdateTipMessage } from '../../events/ui-request';
|
|
@@ -8,10 +8,11 @@ import { updateBootloader } from '../firmware/uploadFirmware';
|
|
|
8
8
|
import { DeviceModelToTypes } from '../../types';
|
|
9
9
|
import { DataManager } from '../../data-manager';
|
|
10
10
|
import { checkBootloaderLength } from '../firmware/updateBootloader';
|
|
11
|
-
import { getDeviceType } from '../../utils';
|
|
11
|
+
import { getDeviceType, getFirmwareType } from '../../utils';
|
|
12
12
|
|
|
13
13
|
import type { Device } from '../../device/Device';
|
|
14
14
|
import type { Features } from '../../types';
|
|
15
|
+
import { DeviceUpdateBootloaderParams } from '../../types/api/deviceUpdateBootloader';
|
|
15
16
|
|
|
16
17
|
export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any> {
|
|
17
18
|
init() {
|
|
@@ -41,11 +42,21 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
41
42
|
return true;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
async updateTouchBootloader(
|
|
45
|
+
async updateTouchBootloader({
|
|
46
|
+
device,
|
|
47
|
+
features,
|
|
48
|
+
firmwareType,
|
|
49
|
+
}: {
|
|
50
|
+
device: Device;
|
|
51
|
+
features?: Features;
|
|
52
|
+
firmwareType: EFirmwareType;
|
|
53
|
+
}) {
|
|
45
54
|
let { binary } = this.payload;
|
|
46
55
|
if (!binary) {
|
|
47
56
|
this.postTipMessage(FirmwareUpdateTipMessage.CheckLatestUiResource);
|
|
48
|
-
const resourceUrl = features
|
|
57
|
+
const resourceUrl = features
|
|
58
|
+
? DataManager.getBootloaderResource(features, firmwareType)
|
|
59
|
+
: null;
|
|
49
60
|
if (resourceUrl) {
|
|
50
61
|
this.postTipMessage(FirmwareUpdateTipMessage.DownloadLatestBootloaderResource);
|
|
51
62
|
const resource = await getSysResourceBinary(resourceUrl);
|
|
@@ -83,9 +94,14 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
83
94
|
const { device } = this;
|
|
84
95
|
const { features } = device;
|
|
85
96
|
|
|
97
|
+
const payload = this.payload as DeviceUpdateBootloaderParams;
|
|
98
|
+
|
|
86
99
|
const deviceType = getDeviceType(features);
|
|
100
|
+
const deviceFirmwareType = getFirmwareType(features);
|
|
101
|
+
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
102
|
+
|
|
87
103
|
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
88
|
-
return this.updateTouchBootloader(device, features);
|
|
104
|
+
return this.updateTouchBootloader({ device, features, firmwareType });
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
return Promise.resolve(true);
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
2
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
import { getDeviceType, httpRequest } from '../../utils';
|
|
5
5
|
import { DataManager } from '../../data-manager';
|
|
6
6
|
import { findLatestRelease } from '../../utils/release';
|
|
7
7
|
import { getFirmwareUpdateField } from '../../utils/deviceFeaturesUtils';
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
import type { Features } from '../../types';
|
|
10
|
+
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
11
|
+
import type { IFirmwareField } from '../../data-manager/DataManager';
|
|
9
12
|
|
|
10
13
|
export interface GetInfoProps {
|
|
11
14
|
features: Features;
|
|
12
15
|
updateType: 'firmware' | 'ble';
|
|
13
16
|
isUpdateBootloader?: boolean;
|
|
14
17
|
targetVersion?: string;
|
|
18
|
+
firmwareType: EFirmwareType;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
interface GetBinaryProps extends GetInfoProps {
|
|
@@ -23,8 +27,14 @@ export const getBinary = async ({
|
|
|
23
27
|
updateType,
|
|
24
28
|
version,
|
|
25
29
|
isUpdateBootloader,
|
|
30
|
+
firmwareType,
|
|
26
31
|
}: GetBinaryProps) => {
|
|
27
|
-
const releaseInfo = getInfo({
|
|
32
|
+
const releaseInfo = getInfo({
|
|
33
|
+
features,
|
|
34
|
+
updateType,
|
|
35
|
+
targetVersion: version?.join('.'),
|
|
36
|
+
firmwareType,
|
|
37
|
+
});
|
|
28
38
|
|
|
29
39
|
if (!releaseInfo) {
|
|
30
40
|
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'no firmware found for this device');
|
|
@@ -71,7 +81,7 @@ export const getSysResourceBinary = async (url: string) => {
|
|
|
71
81
|
};
|
|
72
82
|
};
|
|
73
83
|
|
|
74
|
-
export const getInfo = ({ features, updateType, targetVersion }: GetInfoProps) => {
|
|
84
|
+
export const getInfo = ({ features, updateType, targetVersion, firmwareType }: GetInfoProps) => {
|
|
75
85
|
const deviceType = getDeviceType(features);
|
|
76
86
|
if (deviceType === 'unknown') {
|
|
77
87
|
return null;
|
|
@@ -82,6 +92,7 @@ export const getInfo = ({ features, updateType, targetVersion }: GetInfoProps) =
|
|
|
82
92
|
features,
|
|
83
93
|
updateType,
|
|
84
94
|
targetVersion,
|
|
95
|
+
firmwareType,
|
|
85
96
|
});
|
|
86
97
|
const releaseInfo = deviceMap?.[deviceType]?.[firmwareUpdateField] ?? [];
|
|
87
98
|
return findLatestRelease(releaseInfo);
|
|
@@ -6,10 +6,12 @@ import {
|
|
|
6
6
|
getDeviceType,
|
|
7
7
|
} from '../../utils';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
9
|
+
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
10
|
+
|
|
11
|
+
export const getFirmwareReleaseInfo = (features: Features, firmwareType: EFirmwareType) => {
|
|
12
|
+
const firmwareStatus = DataManager.getFirmwareStatus(features, firmwareType);
|
|
13
|
+
const changelog = DataManager.getFirmwareChangelog(features, firmwareType);
|
|
14
|
+
const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
|
|
13
15
|
const bootloaderMode = !!features.bootloader_mode;
|
|
14
16
|
return {
|
|
15
17
|
status: firmwareStatus,
|
|
@@ -32,11 +34,16 @@ export const getBleFirmwareReleaseInfo = (features: Features) => {
|
|
|
32
34
|
};
|
|
33
35
|
};
|
|
34
36
|
|
|
35
|
-
export const getBootloaderReleaseInfo = (
|
|
36
|
-
features
|
|
37
|
-
willUpdateFirmwareVersion
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
export const getBootloaderReleaseInfo = ({
|
|
38
|
+
features,
|
|
39
|
+
willUpdateFirmwareVersion,
|
|
40
|
+
firmwareType,
|
|
41
|
+
}: {
|
|
42
|
+
features: Features;
|
|
43
|
+
willUpdateFirmwareVersion?: string;
|
|
44
|
+
firmwareType: EFirmwareType;
|
|
45
|
+
}) => {
|
|
46
|
+
const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
|
|
40
47
|
const changelog = [release?.bootloaderChangelog].filter(
|
|
41
48
|
item =>
|
|
42
49
|
item != null &&
|
|
@@ -52,9 +59,13 @@ export const getBootloaderReleaseInfo = (
|
|
|
52
59
|
const deviceType = getDeviceType(features);
|
|
53
60
|
// classic mini classic1s
|
|
54
61
|
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
|
|
55
|
-
shouldUpdate = !!checkNeedUpdateBootForClassicAndMini(
|
|
62
|
+
shouldUpdate = !!checkNeedUpdateBootForClassicAndMini({
|
|
63
|
+
features,
|
|
64
|
+
willUpdateFirmware: willUpdateFirmwareVersion,
|
|
65
|
+
firmwareType,
|
|
66
|
+
});
|
|
56
67
|
} else if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
57
|
-
shouldUpdate = checkNeedUpdateBootForTouch(features);
|
|
68
|
+
shouldUpdate = checkNeedUpdateBootForTouch(features, firmwareType);
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
return {
|