@onekeyfe/hd-core 1.2.0-alpha.79 → 1.2.0-alpha.80
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__/check-all-firmware-release-protocol-v2.test.ts +51 -5
- package/__tests__/check-firmware-release-protocol-v2.test.ts +164 -0
- package/__tests__/protocol-v2-resources.test.ts +24 -8
- package/__tests__/protocol-v2.test.ts +195 -49
- package/dist/api/CheckAllFirmwareRelease.d.ts +2 -3
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBLEFirmwareRelease.d.ts +2 -1
- package/dist/api/CheckBLEFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts +3 -2
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts +2 -1
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/firmware/protocolV2Release.d.ts +33 -0
- package/dist/api/firmware/protocolV2Release.d.ts.map +1 -0
- package/dist/index.d.ts +35 -49
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +340 -183
- package/dist/protocols/protocol-v2/resources.d.ts +0 -4
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +20 -9
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/checkBLEFirmwareRelease.d.ts +2 -13
- package/dist/types/api/checkBLEFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/checkBootloaderRelease.d.ts +2 -6
- package/dist/types/api/checkBootloaderRelease.d.ts.map +1 -1
- package/dist/types/api/checkFirmwareRelease.d.ts +2 -13
- package/dist/types/api/checkFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/checkFirmwareTypeAvailable.d.ts +2 -2
- package/dist/types/api/checkFirmwareTypeAvailable.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +1 -1
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/settings.d.ts +3 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/CheckAllFirmwareRelease.ts +49 -49
- package/src/api/CheckBLEFirmwareRelease.ts +41 -3
- package/src/api/CheckBootloaderRelease.ts +40 -1
- package/src/api/CheckFirmwareRelease.ts +37 -3
- package/src/api/FirmwareUpdateV4.ts +35 -15
- package/src/api/firmware/protocolV2Release.ts +166 -0
- package/src/index.ts +0 -1
- package/src/protocols/protocol-v2/resources.ts +19 -25
- package/src/types/api/checkAllFirmwareRelease.ts +27 -13
- package/src/types/api/checkBLEFirmwareRelease.ts +4 -13
- package/src/types/api/checkBootloaderRelease.ts +2 -6
- package/src/types/api/checkFirmwareRelease.ts +2 -13
- package/src/types/api/checkFirmwareTypeAvailable.ts +2 -2
- package/src/types/api/export.ts +6 -1
- package/src/types/api/firmwareUpdate.ts +2 -3
- package/src/types/settings.ts +3 -1
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
1
3
|
import { BaseMethod } from './BaseMethod';
|
|
2
4
|
import { UI_REQUEST } from '../constants/ui-request';
|
|
3
5
|
import { getFirmwareReleaseInfo } from './firmware/releaseHelper';
|
|
6
|
+
import {
|
|
7
|
+
PROTOCOL_V2_MAIN_FIRMWARE_TARGETS,
|
|
8
|
+
loadProtocolV2FirmwareReleaseContext,
|
|
9
|
+
summarizeProtocolV2FirmwareRelease,
|
|
10
|
+
toProtocolV2FirmwareReleaseInfo,
|
|
11
|
+
} from './firmware/protocolV2Release';
|
|
12
|
+
import { buildProtocolV2FirmwareRelease } from './CheckAllFirmwareRelease';
|
|
4
13
|
|
|
5
14
|
import type { CheckFirmwareReleaseParams } from '../types/api/checkFirmwareRelease';
|
|
6
15
|
|
|
7
16
|
export default class CheckFirmwareRelease extends BaseMethod {
|
|
17
|
+
getSupportedProtocols() {
|
|
18
|
+
return ['V1', 'V2'] as const;
|
|
19
|
+
}
|
|
20
|
+
|
|
8
21
|
init() {
|
|
9
22
|
this.allowDeviceMode = [
|
|
10
23
|
...this.allowDeviceMode,
|
|
@@ -15,16 +28,37 @@ export default class CheckFirmwareRelease extends BaseMethod {
|
|
|
15
28
|
this.skipForceUpdateCheck = true;
|
|
16
29
|
}
|
|
17
30
|
|
|
18
|
-
run() {
|
|
31
|
+
async run() {
|
|
19
32
|
const payload = this.payload as CheckFirmwareReleaseParams;
|
|
20
33
|
|
|
34
|
+
if (this.device.isProtocolV2()) {
|
|
35
|
+
const { state, firmwareType, release } = await loadProtocolV2FirmwareReleaseContext({
|
|
36
|
+
device: this.device,
|
|
37
|
+
firmwareType: payload.firmwareType,
|
|
38
|
+
methodName: 'checkFirmwareRelease',
|
|
39
|
+
});
|
|
40
|
+
const plan = summarizeProtocolV2FirmwareRelease(
|
|
41
|
+
buildProtocolV2FirmwareRelease({
|
|
42
|
+
currentVersions: state.versions,
|
|
43
|
+
firmwareType,
|
|
44
|
+
release,
|
|
45
|
+
deviceType: state.identity.deviceType,
|
|
46
|
+
}),
|
|
47
|
+
PROTOCOL_V2_MAIN_FIRMWARE_TARGETS
|
|
48
|
+
);
|
|
49
|
+
return toProtocolV2FirmwareReleaseInfo({ plan, state, release });
|
|
50
|
+
}
|
|
51
|
+
|
|
21
52
|
if (this.device.features) {
|
|
22
53
|
const deviceFirmwareType = this.device.getCurrentFirmwareType();
|
|
23
54
|
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
24
55
|
|
|
25
56
|
const releaseInfo = getFirmwareReleaseInfo(this.device.features, firmwareType);
|
|
26
|
-
return
|
|
57
|
+
return releaseInfo;
|
|
27
58
|
}
|
|
28
|
-
|
|
59
|
+
throw ERRORS.TypedError(
|
|
60
|
+
HardwareErrorCode.RuntimeError,
|
|
61
|
+
'checkFirmwareRelease requires initialized device features'
|
|
62
|
+
);
|
|
29
63
|
}
|
|
30
64
|
}
|
|
@@ -146,6 +146,9 @@ type ProtocolV2ResourceBundleBinary = {
|
|
|
146
146
|
name: string;
|
|
147
147
|
binary: ArrayBuffer;
|
|
148
148
|
devicePath: string;
|
|
149
|
+
version?: IVersionArray;
|
|
150
|
+
payloadHash?: string;
|
|
151
|
+
headerHash?: string;
|
|
149
152
|
};
|
|
150
153
|
|
|
151
154
|
type ProtocolV2RemoteComponentBinary = ProtocolV2RemoteComponentTarget & {
|
|
@@ -668,10 +671,8 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
668
671
|
return this.runProtocolV2PreparedArtifacts(deviceFeatures, firmwareType);
|
|
669
672
|
}
|
|
670
673
|
const hasExplicitResourceFiles = !!this.params.resourceFiles?.length;
|
|
671
|
-
const
|
|
672
|
-
const
|
|
673
|
-
const needsPreparedResources =
|
|
674
|
-
!hasExplicitResourceFiles && (wantsStableResources || wantsBootResources);
|
|
674
|
+
const wantsResources = !!this.params.targetsToUpdate?.includes('resource');
|
|
675
|
+
const needsPreparedResources = !hasExplicitResourceFiles && wantsResources;
|
|
675
676
|
|
|
676
677
|
let fwBinaryMap: ProtocolV2TargetBinary[] = [];
|
|
677
678
|
let bootloaderBinary: ArrayBuffer | null = null;
|
|
@@ -897,7 +898,19 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
897
898
|
try {
|
|
898
899
|
this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
899
900
|
const installSources = await this.prepareProtocolV2InstallSources(firmwareType, features);
|
|
900
|
-
const
|
|
901
|
+
const explicitResourceBundles = this.prepareExplicitProtocolV2ResourceFiles();
|
|
902
|
+
const resourceSources = explicitResourceBundles?.length
|
|
903
|
+
? await Promise.all(
|
|
904
|
+
explicitResourceBundles.map(async bundle => ({
|
|
905
|
+
name: bundle.name,
|
|
906
|
+
source: await this.openProtocolV2MemorySource(bundle.binary),
|
|
907
|
+
devicePath: bundle.devicePath,
|
|
908
|
+
version: bundle.version,
|
|
909
|
+
payloadHash: bundle.payloadHash,
|
|
910
|
+
headerHash: bundle.headerHash,
|
|
911
|
+
}))
|
|
912
|
+
)
|
|
913
|
+
: await this.prepareProtocolV2ResourceSources(firmwareType, features);
|
|
901
914
|
if (installSources.length === 0 && resourceSources.length === 0) {
|
|
902
915
|
throw ERRORS.TypedError(
|
|
903
916
|
HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
@@ -1272,10 +1285,18 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1272
1285
|
) {
|
|
1273
1286
|
throw new Error(`resourceFiles[${index}] SHA-256 mismatch`);
|
|
1274
1287
|
}
|
|
1288
|
+
const header = parseProtocolV2OkppHeader(toProtocolV2Bytes(file.binary));
|
|
1275
1289
|
return {
|
|
1276
1290
|
name: devicePath.split('/').pop() ?? devicePath,
|
|
1277
1291
|
binary: file.binary,
|
|
1278
1292
|
devicePath,
|
|
1293
|
+
...(header
|
|
1294
|
+
? {
|
|
1295
|
+
version: header.version,
|
|
1296
|
+
payloadHash: header.payloadHash,
|
|
1297
|
+
headerHash: header.headerHash,
|
|
1298
|
+
}
|
|
1299
|
+
: {}),
|
|
1279
1300
|
};
|
|
1280
1301
|
});
|
|
1281
1302
|
if (new Set(prepared.map(file => file.devicePath)).size !== prepared.length) {
|
|
@@ -1335,7 +1356,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1335
1356
|
return parseProtocolV2OkppHeader(headerBytes);
|
|
1336
1357
|
}
|
|
1337
1358
|
|
|
1338
|
-
/** Compare
|
|
1359
|
+
/** Compare the downloaded and installed okpkg headers before transferring a resource. */
|
|
1339
1360
|
private async isProtocolV2ResourceBundleUpToDate(
|
|
1340
1361
|
bundle: Pick<
|
|
1341
1362
|
ProtocolV2ResourceBundleSource,
|
|
@@ -1343,7 +1364,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1343
1364
|
>
|
|
1344
1365
|
): Promise<boolean> {
|
|
1345
1366
|
if (this.params?.forcedUpdateRes) return false;
|
|
1346
|
-
if (!bundle.
|
|
1367
|
+
if (!bundle.payloadHash || !bundle.headerHash) return false;
|
|
1347
1368
|
|
|
1348
1369
|
try {
|
|
1349
1370
|
const header = await this.readProtocolV2DeviceFileHeader(bundle.devicePath);
|
|
@@ -1353,14 +1374,10 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1353
1374
|
const cmp = compareProtocolV2Versions(header.version, bundle.version);
|
|
1354
1375
|
if (cmp === undefined || cmp !== 0) return false;
|
|
1355
1376
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
if (bundle.headerHash) {
|
|
1361
|
-
const expected = normalizeProtocolV2Hex(bundle.headerHash);
|
|
1362
|
-
if (expected && header.headerHash !== expected) return false;
|
|
1363
|
-
}
|
|
1377
|
+
const expectedPayloadHash = normalizeProtocolV2Hex(bundle.payloadHash);
|
|
1378
|
+
const expectedHeaderHash = normalizeProtocolV2Hex(bundle.headerHash);
|
|
1379
|
+
if (!expectedPayloadHash || header.payloadHash !== expectedPayloadHash) return false;
|
|
1380
|
+
if (!expectedHeaderHash || header.headerHash !== expectedHeaderHash) return false;
|
|
1364
1381
|
return true;
|
|
1365
1382
|
} catch (error) {
|
|
1366
1383
|
Log.log(`[FirmwareUpdateV4] RESC bundle ${bundle.name} header check failed: `, error);
|
|
@@ -1631,6 +1648,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1631
1648
|
name: bundle.name,
|
|
1632
1649
|
source: await this.openProtocolV2MemorySource(bundle.binary),
|
|
1633
1650
|
devicePath: bundle.devicePath,
|
|
1651
|
+
version: bundle.version,
|
|
1652
|
+
payloadHash: bundle.payloadHash,
|
|
1653
|
+
headerHash: bundle.headerHash,
|
|
1634
1654
|
}))
|
|
1635
1655
|
);
|
|
1636
1656
|
return await this.executeProtocolV2Phases({
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { EFirmwareType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { DataManager } from '../../data-manager';
|
|
4
|
+
|
|
5
|
+
import type { EDeviceType } from '@onekeyfe/hd-shared';
|
|
6
|
+
import type { Device } from '../../device/Device';
|
|
7
|
+
import type {
|
|
8
|
+
DeviceState,
|
|
9
|
+
Features,
|
|
10
|
+
IFirmwareReleaseInfo,
|
|
11
|
+
IProtocolV2FirmwareComponentTarget,
|
|
12
|
+
} from '../../types';
|
|
13
|
+
import type {
|
|
14
|
+
FirmwareReleaseCheckResult,
|
|
15
|
+
ProtocolV2ComponentReleaseInfo,
|
|
16
|
+
ProtocolV2FirmwareReleaseStatus,
|
|
17
|
+
} from '../../types/api/checkAllFirmwareRelease';
|
|
18
|
+
import type { ProtocolV2FirmwareReleasePlan } from '../CheckAllFirmwareRelease';
|
|
19
|
+
|
|
20
|
+
export const PROTOCOL_V2_MAIN_FIRMWARE_TARGETS: readonly IProtocolV2FirmwareComponentTarget[] = [
|
|
21
|
+
'APPLICATION_P1',
|
|
22
|
+
'APPLICATION_P2',
|
|
23
|
+
'SE01',
|
|
24
|
+
'SE02',
|
|
25
|
+
'SE03',
|
|
26
|
+
'SE04',
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
export const PROTOCOL_V2_BLE_TARGETS: readonly IProtocolV2FirmwareComponentTarget[] = [
|
|
30
|
+
'COPROCESSOR',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
export const PROTOCOL_V2_BOOTLOADER_TARGETS: readonly IProtocolV2FirmwareComponentTarget[] = [
|
|
34
|
+
'BOOTLOADER',
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
export type ProtocolV2FirmwareReleaseContext = {
|
|
38
|
+
state: Omit<DeviceState, 'identity'> & {
|
|
39
|
+
identity: Omit<DeviceState['identity'], 'deviceType'> & {
|
|
40
|
+
deviceType: EDeviceType.Pro2 | EDeviceType.Neo;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
features: Features;
|
|
44
|
+
firmwareType: EFirmwareType;
|
|
45
|
+
release: IFirmwareReleaseInfo | undefined;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export async function loadProtocolV2FirmwareReleaseContext({
|
|
49
|
+
device,
|
|
50
|
+
firmwareType: firmwareTypeParam,
|
|
51
|
+
checkFirmwareHash = false,
|
|
52
|
+
methodName,
|
|
53
|
+
}: {
|
|
54
|
+
device: Device;
|
|
55
|
+
firmwareType?: EFirmwareType;
|
|
56
|
+
checkFirmwareHash?: boolean;
|
|
57
|
+
methodName: string;
|
|
58
|
+
}): Promise<ProtocolV2FirmwareReleaseContext> {
|
|
59
|
+
const state = await device.getDeviceState({
|
|
60
|
+
refreshSections: checkFirmwareHash
|
|
61
|
+
? ['identity', 'versions', 'verification']
|
|
62
|
+
: ['identity', 'versions'],
|
|
63
|
+
});
|
|
64
|
+
if (state.identity.deviceType !== 'pro2' && state.identity.deviceType !== 'neo') {
|
|
65
|
+
throw ERRORS.TypedError(
|
|
66
|
+
HardwareErrorCode.DeviceNotSupportMethod,
|
|
67
|
+
`${methodName} requires a Pro2 or Neo device for Protocol V2`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const { features } = device;
|
|
72
|
+
if (!features) {
|
|
73
|
+
throw ERRORS.TypedError(
|
|
74
|
+
HardwareErrorCode.RuntimeError,
|
|
75
|
+
`${methodName} requires initialized device features`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const firmwareType = firmwareTypeParam ?? state.identity.firmwareType ?? EFirmwareType.Universal;
|
|
80
|
+
return {
|
|
81
|
+
state: state as ProtocolV2FirmwareReleaseContext['state'],
|
|
82
|
+
features,
|
|
83
|
+
firmwareType,
|
|
84
|
+
release: DataManager.getFirmwareLatestRelease(features, firmwareType),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function summarizeProtocolV2FirmwareRelease(
|
|
89
|
+
plan: ProtocolV2FirmwareReleasePlan,
|
|
90
|
+
componentTargets: readonly IProtocolV2FirmwareComponentTarget[]
|
|
91
|
+
): ProtocolV2FirmwareReleasePlan {
|
|
92
|
+
const targetSet = new Set<IProtocolV2FirmwareComponentTarget>(componentTargets);
|
|
93
|
+
const components = plan.components.filter(component => targetSet.has(component.componentTarget));
|
|
94
|
+
const targetsToUpdate = Array.from(
|
|
95
|
+
new Set(
|
|
96
|
+
components.flatMap(component =>
|
|
97
|
+
component.status === 'outdated' && component.updateTarget ? [component.updateTarget] : []
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
const hasUpgrade = targetsToUpdate.length > 0;
|
|
102
|
+
const required = !!plan.release?.required && hasUpgrade;
|
|
103
|
+
let status: ProtocolV2FirmwareReleaseStatus = 'valid';
|
|
104
|
+
if (!plan.release || components.length === 0) {
|
|
105
|
+
status = 'unavailable';
|
|
106
|
+
} else if (required) {
|
|
107
|
+
status = 'required';
|
|
108
|
+
} else if (hasUpgrade) {
|
|
109
|
+
status = 'outdated';
|
|
110
|
+
} else if (components.some(component => component.status === 'unknown')) {
|
|
111
|
+
status = 'unknown';
|
|
112
|
+
} else if (components.every(component => component.status === 'unsupported')) {
|
|
113
|
+
status = 'unavailable';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
...plan,
|
|
118
|
+
status,
|
|
119
|
+
hasUpgrade,
|
|
120
|
+
required,
|
|
121
|
+
components,
|
|
122
|
+
targetsToUpdate,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function toProtocolV2FirmwareReleaseInfo({
|
|
127
|
+
plan,
|
|
128
|
+
state,
|
|
129
|
+
release,
|
|
130
|
+
}: {
|
|
131
|
+
plan: ProtocolV2FirmwareReleasePlan;
|
|
132
|
+
state: DeviceState;
|
|
133
|
+
release: FirmwareReleaseCheckResult['release'];
|
|
134
|
+
}): FirmwareReleaseCheckResult {
|
|
135
|
+
return {
|
|
136
|
+
shouldUpdate: plan.hasUpgrade,
|
|
137
|
+
status: plan.status === 'unavailable' ? 'unknown' : plan.status,
|
|
138
|
+
changelog: plan.release ? [plan.release.changelog] : [],
|
|
139
|
+
release,
|
|
140
|
+
bootloaderMode: state.status.mode === 'bootloader' || state.status.mode === 'romloader',
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function getProtocolV2ComponentReleaseInfo(
|
|
145
|
+
plan: ProtocolV2FirmwareReleasePlan,
|
|
146
|
+
componentTarget: IProtocolV2FirmwareComponentTarget
|
|
147
|
+
): ProtocolV2ComponentReleaseInfo | undefined {
|
|
148
|
+
const componentRelease = plan.components.find(
|
|
149
|
+
component => component.componentTarget === componentTarget
|
|
150
|
+
);
|
|
151
|
+
if (!componentRelease || !plan.release) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
const component = plan.release.components?.[componentRelease.configKey];
|
|
155
|
+
if (!component) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
...component,
|
|
160
|
+
protocol: 'V2',
|
|
161
|
+
configKey: componentRelease.configKey,
|
|
162
|
+
componentTarget,
|
|
163
|
+
required: plan.release.required,
|
|
164
|
+
changelog: plan.release.changelog,
|
|
165
|
+
};
|
|
166
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -24,7 +24,6 @@ export { getMethodSupportedProtocols } from './api/utils';
|
|
|
24
24
|
export {
|
|
25
25
|
parseProtocolV2ResourceManifest,
|
|
26
26
|
prepareProtocolV2ResourceFiles,
|
|
27
|
-
resolveProtocolV2ResourceManifestFileUrl,
|
|
28
27
|
selectProtocolV2ResourceManifestFiles,
|
|
29
28
|
} from './protocols/protocol-v2/resources';
|
|
30
29
|
export {
|
|
@@ -37,12 +37,26 @@ export function parseProtocolV2Resources(value: unknown): IProtocolV2Resources |
|
|
|
37
37
|
if (!source || typeof source !== 'object') {
|
|
38
38
|
throw new Error('Invalid Pro2 resources config: source is required');
|
|
39
39
|
}
|
|
40
|
-
const {
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const { archiveUrl, archiveSha256, archiveSize } = source as {
|
|
41
|
+
archiveUrl?: unknown;
|
|
42
|
+
archiveSha256?: unknown;
|
|
43
|
+
archiveSize?: unknown;
|
|
44
|
+
};
|
|
45
|
+
if (typeof archiveUrl !== 'string' || !archiveUrl.startsWith('https://')) {
|
|
46
|
+
throw new Error('Invalid Pro2 resources config: source.archiveUrl must use HTTPS');
|
|
47
|
+
}
|
|
48
|
+
if (typeof archiveSha256 !== 'string' || !/^[0-9a-fA-F]{64}$/.test(archiveSha256)) {
|
|
49
|
+
throw new Error('Invalid Pro2 resources config: source.archiveSha256 must be a SHA-256 digest');
|
|
50
|
+
}
|
|
51
|
+
if (!Number.isSafeInteger(archiveSize) || (archiveSize as number) <= 0) {
|
|
52
|
+
throw new Error('Invalid Pro2 resources config: source.archiveSize must be a positive integer');
|
|
43
53
|
}
|
|
44
54
|
return {
|
|
45
|
-
source: {
|
|
55
|
+
source: {
|
|
56
|
+
archiveUrl,
|
|
57
|
+
archiveSha256: archiveSha256.toLowerCase(),
|
|
58
|
+
archiveSize: archiveSize as number,
|
|
59
|
+
},
|
|
46
60
|
};
|
|
47
61
|
}
|
|
48
62
|
|
|
@@ -194,27 +208,7 @@ export function selectProtocolV2ResourceManifestFiles({
|
|
|
194
208
|
manifest: IProtocolV2ResourceManifest;
|
|
195
209
|
targetsToUpdate: readonly FirmwareUpdateV4Target[];
|
|
196
210
|
}): IProtocolV2ResourceManifestFile[] {
|
|
197
|
-
|
|
198
|
-
return manifest.files.filter(file => {
|
|
199
|
-
if (file.device_path.startsWith('vol0:/bundles/')) {
|
|
200
|
-
return targets.has('resource');
|
|
201
|
-
}
|
|
202
|
-
return targets.has('boot_resources');
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export function resolveProtocolV2ResourceManifestFileUrl({
|
|
207
|
-
manifestUrl,
|
|
208
|
-
archivePath,
|
|
209
|
-
}: {
|
|
210
|
-
manifestUrl: string;
|
|
211
|
-
archivePath: string;
|
|
212
|
-
}): string {
|
|
213
|
-
const url = new URL(assertManifestRelativePath(archivePath, 'archive_path'), manifestUrl);
|
|
214
|
-
if (url.protocol !== 'https:') {
|
|
215
|
-
throw new Error('Invalid Pro2 resource manifest file URL');
|
|
216
|
-
}
|
|
217
|
-
return url.toString();
|
|
211
|
+
return targetsToUpdate.includes('resource') ? [...manifest.files] : [];
|
|
218
212
|
}
|
|
219
213
|
|
|
220
214
|
export function prepareProtocolV2ResourceFiles({
|
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
2
|
import type { CommonParams, Response } from '../params';
|
|
3
|
-
import type {
|
|
4
|
-
DeviceStateVersions,
|
|
5
|
-
Features,
|
|
6
|
-
IDeviceBLEFirmwareStatus,
|
|
7
|
-
IDeviceFirmwareStatus,
|
|
8
|
-
} from '../device';
|
|
3
|
+
import type { DeviceStateVersions, Features, IDeviceFirmwareStatus } from '../device';
|
|
9
4
|
import type {
|
|
10
5
|
IBLEFirmwareReleaseInfo,
|
|
11
6
|
IFirmwareReleaseInfo,
|
|
7
|
+
IProtocolV2FirmwareComponent,
|
|
12
8
|
IProtocolV2FirmwareComponentTarget,
|
|
9
|
+
IProtocolV2ResourceSource,
|
|
13
10
|
} from '../settings';
|
|
14
11
|
import type { FirmwareUpdateV4Target } from './firmwareUpdate';
|
|
15
12
|
import type { FirmwareUpdatePlan, FirmwareUpdatePlanForceTarget } from './firmwareUpdatePlan';
|
|
16
13
|
|
|
17
|
-
export type
|
|
14
|
+
export type ProtocolV2ComponentReleaseInfo = IProtocolV2FirmwareComponent & {
|
|
15
|
+
protocol: 'V2';
|
|
16
|
+
configKey: string;
|
|
17
|
+
componentTarget: IProtocolV2FirmwareComponentTarget;
|
|
18
|
+
required: boolean;
|
|
19
|
+
changelog: IFirmwareReleaseInfo['changelog'];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type FirmwareReleaseCheckResult = {
|
|
18
23
|
shouldUpdate?: boolean;
|
|
19
24
|
status: IDeviceFirmwareStatus;
|
|
20
25
|
changelog?: {
|
|
21
26
|
'zh-CN': string;
|
|
22
27
|
'en-US': string;
|
|
23
28
|
}[];
|
|
24
|
-
release:
|
|
29
|
+
release:
|
|
30
|
+
| IBLEFirmwareReleaseInfo
|
|
31
|
+
| IFirmwareReleaseInfo
|
|
32
|
+
| ProtocolV2ComponentReleaseInfo
|
|
33
|
+
| undefined;
|
|
25
34
|
bootloaderMode?: boolean;
|
|
26
35
|
};
|
|
27
36
|
|
|
37
|
+
export type BridgeReleaseCheckResult = Omit<FirmwareReleaseCheckResult, 'release'> & {
|
|
38
|
+
release: string | undefined;
|
|
39
|
+
};
|
|
40
|
+
|
|
28
41
|
export type ProtocolV2FirmwareComponentReleaseStatus =
|
|
29
42
|
| 'valid'
|
|
30
43
|
| 'outdated'
|
|
@@ -49,10 +62,10 @@ export type ProtocolV2FirmwareComponentRelease = {
|
|
|
49
62
|
};
|
|
50
63
|
|
|
51
64
|
export type AllFirmwareRelease = {
|
|
52
|
-
firmware:
|
|
53
|
-
ble:
|
|
54
|
-
bootloader?:
|
|
55
|
-
bridge?:
|
|
65
|
+
firmware: FirmwareReleaseCheckResult;
|
|
66
|
+
ble: FirmwareReleaseCheckResult;
|
|
67
|
+
bootloader?: FirmwareReleaseCheckResult;
|
|
68
|
+
bridge?: BridgeReleaseCheckResult;
|
|
56
69
|
features?: Features;
|
|
57
70
|
protocol?: 'V1' | 'V2';
|
|
58
71
|
deviceType?: 'pro2' | 'neo';
|
|
@@ -61,7 +74,8 @@ export type AllFirmwareRelease = {
|
|
|
61
74
|
hasUpgrade?: boolean;
|
|
62
75
|
required?: boolean;
|
|
63
76
|
resourceStatus?: 'valid' | 'outdated' | 'unknown';
|
|
64
|
-
|
|
77
|
+
resourceArchive?: IProtocolV2ResourceSource;
|
|
78
|
+
resourcePreparationRequired?: boolean;
|
|
65
79
|
currentVersions?: DeviceStateVersions;
|
|
66
80
|
components?: ProtocolV2FirmwareComponentRelease[];
|
|
67
81
|
targetsToUpdate?: FirmwareUpdateV4Target[];
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import type { IBLEFirmwareReleaseInfo } from '../settings';
|
|
2
1
|
import type { Response } from '../params';
|
|
3
|
-
import type {
|
|
2
|
+
import type { FirmwareReleaseCheckResult } from './checkAllFirmwareRelease';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'zh-CN': string;
|
|
9
|
-
'en-US': string;
|
|
10
|
-
}[];
|
|
11
|
-
release: IBLEFirmwareReleaseInfo;
|
|
12
|
-
bootloaderMode: boolean;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export declare function checkBLEFirmwareRelease(connectId?: string): Response<BleFirmwareRelease>;
|
|
4
|
+
export declare function checkBLEFirmwareRelease(
|
|
5
|
+
connectId?: string
|
|
6
|
+
): Response<FirmwareReleaseCheckResult>;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
2
|
import type { CommonParams, Response } from '../params';
|
|
3
|
+
import type { FirmwareReleaseCheckResult } from './checkAllFirmwareRelease';
|
|
3
4
|
|
|
4
|
-
export type CheckBootloaderReleaseResponse =
|
|
5
|
-
shouldUpdate: boolean;
|
|
6
|
-
status: 'outdated' | 'valid';
|
|
7
|
-
release: string | undefined;
|
|
8
|
-
bootloaderMode: boolean;
|
|
9
|
-
} | null;
|
|
5
|
+
export type CheckBootloaderReleaseResponse = FirmwareReleaseCheckResult;
|
|
10
6
|
|
|
11
7
|
export type CheckBootloaderReleaseParams = {
|
|
12
8
|
willUpdateFirmwareVersion?: string;
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import type { IFirmwareReleaseInfo } from '../settings';
|
|
2
1
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
3
2
|
import type { Response } from '../params';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
type FirmwareRelease = {
|
|
7
|
-
status: IDeviceFirmwareStatus;
|
|
8
|
-
changelog: {
|
|
9
|
-
'en-US': string;
|
|
10
|
-
'zh-CN': string;
|
|
11
|
-
}[];
|
|
12
|
-
release: IFirmwareReleaseInfo;
|
|
13
|
-
bootloaderMode: boolean;
|
|
14
|
-
};
|
|
3
|
+
import type { FirmwareReleaseCheckResult } from './checkAllFirmwareRelease';
|
|
15
4
|
|
|
16
5
|
export type CheckFirmwareReleaseParams = {
|
|
17
6
|
firmwareType?: EFirmwareType;
|
|
@@ -20,4 +9,4 @@ export type CheckFirmwareReleaseParams = {
|
|
|
20
9
|
export declare function checkFirmwareRelease(
|
|
21
10
|
connectId?: string,
|
|
22
11
|
params?: CheckFirmwareReleaseParams
|
|
23
|
-
): Response<
|
|
12
|
+
): Response<FirmwareReleaseCheckResult>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
2
|
import type { Response } from '../params';
|
|
3
|
-
import type {
|
|
3
|
+
import type { FirmwareReleaseCheckResult } from './checkAllFirmwareRelease';
|
|
4
4
|
|
|
5
5
|
export type CheckFirmwareTypeAvailableParams = {
|
|
6
6
|
deviceType: EDeviceType;
|
|
@@ -9,4 +9,4 @@ export type CheckFirmwareTypeAvailableParams = {
|
|
|
9
9
|
|
|
10
10
|
export declare function checkFirmwareTypeAvailable(
|
|
11
11
|
params: CheckFirmwareTypeAvailableParams
|
|
12
|
-
): Response<
|
|
12
|
+
): Response<FirmwareReleaseCheckResult | undefined>;
|
package/src/types/api/export.ts
CHANGED
|
@@ -54,7 +54,12 @@ export type {
|
|
|
54
54
|
ProtocolV2ResourceManifestBinary,
|
|
55
55
|
} from './protocolV2ResourceManifest';
|
|
56
56
|
export type { FirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
|
|
57
|
-
export type {
|
|
57
|
+
export type {
|
|
58
|
+
AllFirmwareRelease,
|
|
59
|
+
BridgeReleaseCheckResult,
|
|
60
|
+
FirmwareReleaseCheckResult,
|
|
61
|
+
ProtocolV2ComponentReleaseInfo,
|
|
62
|
+
} from './checkAllFirmwareRelease';
|
|
58
63
|
export type {
|
|
59
64
|
ProtocolV2FirmwareComponentRelease,
|
|
60
65
|
ProtocolV2FirmwareComponentReleaseStatus,
|
|
@@ -118,7 +118,6 @@ export interface FirmwareUpdateV3Params {
|
|
|
118
118
|
*/
|
|
119
119
|
export type FirmwareUpdateV4Target =
|
|
120
120
|
| 'boot'
|
|
121
|
-
| 'boot_resources'
|
|
122
121
|
| 'app_v1'
|
|
123
122
|
| 'app_v2'
|
|
124
123
|
| 'coprocessor'
|
|
@@ -156,8 +155,8 @@ export interface FirmwareUpdateV4Params {
|
|
|
156
155
|
forcedUpdateRes?: boolean;
|
|
157
156
|
/**
|
|
158
157
|
* Arbitrary Protocol V2 resource files written directly with FilesystemFileWrite.
|
|
159
|
-
* Use this for
|
|
160
|
-
* When provided, these files are authoritative for resource
|
|
158
|
+
* Use this for every file selected from the manifest-driven resource archive.
|
|
159
|
+
* When provided, these files are authoritative for the resource target.
|
|
161
160
|
*/
|
|
162
161
|
resourceFiles?: Array<{
|
|
163
162
|
binary: ArrayBuffer;
|
package/src/types/settings.ts
CHANGED