@onekeyfe/hd-core 1.2.0-alpha.161 → 1.2.0-alpha.162
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__/device-state-events.test.ts +2 -2
- package/__tests__/device-state-mapper.test.ts +11 -2
- package/__tests__/device-utils.test.ts +6 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +13 -3
- package/__tests__/protocol-v2-resources.test.ts +35 -2
- package/__tests__/protocol-v2.test.ts +89 -42
- package/__tests__/search-devices.test.ts +4 -3
- package/dist/api/FirmwareUpdateV4.d.ts +3 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -15
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/index.d.ts +2 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +102 -298
- package/dist/protocols/protocol-v2/resources.d.ts +1 -0
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +75 -179
- package/src/api/SearchDevices.ts +2 -2
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -41
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +10 -6
- package/src/core/index.ts +6 -97
- package/src/device/Device.ts +3 -1
- package/src/device/DeviceStateMapper.ts +2 -2
- package/src/deviceProfile/buildDeviceFeatures.ts +7 -2
- package/src/index.ts +0 -6
- package/src/protocols/protocol-v2/resources.ts +16 -12
- package/src/types/api/firmwareUpdate.ts +1 -1
- package/src/utils/deviceFeaturesCompat.ts +9 -4
- package/src/utils/deviceInfoUtils.ts +3 -1
- package/__tests__/firmware-memory-host.test.ts +0 -126
- package/dist/api/firmware/FirmwareMemoryHost.d.ts +0 -22
- package/dist/api/firmware/FirmwareMemoryHost.d.ts.map +0 -1
- package/src/api/firmware/FirmwareMemoryHost.ts +0 -143
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,WAqBtD,CAAC;AAMF,eAAO,MAAM,gBAAgB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAC3C,CAAC;AAKjC,eAAO,MAAM,iBAAiB,cAAe,mBAAmB,KAAG,MAClC,CAAC;AAKlC,eAAO,MAAM,aAAa,cANmB,mBAAmB,KAAG,MAMrB,CAAC;AAK/C,eAAO,MAAM,cAAc,cAAe,mBAAmB,kBAkB5D,CAAC;AAMF,eAAO,MAAM,qBAAqB,aACtB,mBAAmB,GAAG,SAAS,iCACV,WAAW,GAAG,YAAY,KAAK,aAAa,GAAG,SAAS,KACtF,aAAa,GAAG,SAyBlB,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,mBAAmB,gDACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.162",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.162",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.162",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "f4aa654b350931d68ed9ba3f77c4cc8faa161218"
|
|
50
50
|
}
|
|
@@ -32,11 +32,13 @@ import {
|
|
|
32
32
|
} from '../protocols/protocol-v2';
|
|
33
33
|
import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
|
|
34
34
|
import {
|
|
35
|
+
PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH,
|
|
35
36
|
PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH,
|
|
36
37
|
PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE,
|
|
38
|
+
type ProtocolV2ResourcePackageHeader,
|
|
39
|
+
isProtocolV2ResourceArchiveEntryName,
|
|
37
40
|
parseProtocolV2ResourcePackage,
|
|
38
41
|
parseProtocolV2ResourcePackageHeader,
|
|
39
|
-
type ProtocolV2ResourcePackageHeader,
|
|
40
42
|
} from '../protocols/protocol-v2/resources';
|
|
41
43
|
import {
|
|
42
44
|
getProtocolV2UnknownErrorText,
|
|
@@ -47,20 +49,12 @@ import {
|
|
|
47
49
|
readFirmwareByteSourceFully,
|
|
48
50
|
writeFirmwareByteSource,
|
|
49
51
|
} from './firmware/FirmwareArtifactSource';
|
|
50
|
-
import {
|
|
51
|
-
registerFirmwareUpdateHostBinding,
|
|
52
|
-
resolveFirmwareUpdateHostBinding,
|
|
53
|
-
unregisterFirmwareUpdateHostBinding,
|
|
54
|
-
} from './firmware/FirmwareHostBinding';
|
|
52
|
+
import { resolveFirmwareUpdateHostBinding } from './firmware/FirmwareHostBinding';
|
|
55
53
|
import {
|
|
56
54
|
assertFirmwareUpdatePreparedPlanBinding,
|
|
57
55
|
assertFirmwareUpdatePreparedPlanDeviceIdentity,
|
|
58
|
-
prepareFirmwareUpdatePlan,
|
|
59
56
|
validateFirmwareUpdatePreparedPlan,
|
|
60
57
|
} from './firmware/FirmwareUpdatePreparedPlan';
|
|
61
|
-
import { prepareFirmwareUpdateV4MemoryHost } from './firmware/FirmwareMemoryHost';
|
|
62
|
-
import { buildProtocolV2LocalFirmwareUpdatePlan } from './firmware/FirmwareUpdatePlan';
|
|
63
|
-
|
|
64
58
|
import type {
|
|
65
59
|
FirmwareArtifactReference,
|
|
66
60
|
FirmwareUpdateV4Params,
|
|
@@ -77,11 +71,6 @@ import type {
|
|
|
77
71
|
KnownDevice,
|
|
78
72
|
} from '../types';
|
|
79
73
|
import type { FirmwareByteSource } from './firmware/FirmwareArtifactSource';
|
|
80
|
-
import type {
|
|
81
|
-
FirmwareMemoryArtifact,
|
|
82
|
-
FirmwareMemoryArtifactEntry,
|
|
83
|
-
FirmwareUpdateV4MemoryHost,
|
|
84
|
-
} from './firmware/FirmwareMemoryHost';
|
|
85
74
|
|
|
86
75
|
const Log = getLogger(LoggerNames.Method);
|
|
87
76
|
|
|
@@ -230,7 +219,6 @@ type ProtocolV2ResourceBundleSource = {
|
|
|
230
219
|
|
|
231
220
|
type ProtocolV2LocalResourceArchive = {
|
|
232
221
|
binary: ArrayBuffer;
|
|
233
|
-
materializedEntries: FirmwareMemoryArtifactEntry[];
|
|
234
222
|
resources: Array<{
|
|
235
223
|
entryName: string;
|
|
236
224
|
binary: ArrayBuffer;
|
|
@@ -792,15 +780,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
792
780
|
this.params.resourceArchiveBinary &&
|
|
793
781
|
this.params.targetsToUpdate?.includes('resource')
|
|
794
782
|
) {
|
|
795
|
-
|
|
796
|
-
features: deviceFeatures,
|
|
797
|
-
firmwareType,
|
|
798
|
-
});
|
|
799
|
-
try {
|
|
800
|
-
return await this.runProtocolV2PreparedArtifacts(deviceFeatures, firmwareType);
|
|
801
|
-
} finally {
|
|
802
|
-
localMemoryHost.release();
|
|
803
|
-
}
|
|
783
|
+
return this.runProtocolV2DirectArtifacts({});
|
|
804
784
|
}
|
|
805
785
|
|
|
806
786
|
const hasPreparedComponentArtifacts = Object.values(this.params.componentArtifacts ?? {}).some(
|
|
@@ -813,12 +793,12 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
813
793
|
let fwBinaryMap: ProtocolV2TargetBinary[] = [];
|
|
814
794
|
let bootloaderBinary: ArrayBuffer | null = null;
|
|
815
795
|
let installItems: ProtocolV2InstallItem[] | undefined;
|
|
816
|
-
let
|
|
796
|
+
let explicitInstallItems: ProtocolV2InstallItem[] | undefined;
|
|
817
797
|
try {
|
|
818
798
|
this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
819
799
|
fwBinaryMap = this.collectExplicitTargetBinaries();
|
|
820
800
|
bootloaderBinary = this.prepareBootloaderBinary();
|
|
821
|
-
|
|
801
|
+
explicitInstallItems = this.buildProtocolV2InstallItems({
|
|
822
802
|
bootloaderBinary,
|
|
823
803
|
fwBinaryMap,
|
|
824
804
|
});
|
|
@@ -874,15 +854,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
874
854
|
deviceFeatures,
|
|
875
855
|
firmwareType
|
|
876
856
|
);
|
|
877
|
-
resourceMemoryHost = await this.prepareProtocolV2LocalMemoryHost({
|
|
878
|
-
features: deviceFeatures,
|
|
879
|
-
firmwareType,
|
|
880
|
-
availableInstallItems: installItems ?? explicitInstallItems,
|
|
881
|
-
});
|
|
882
857
|
}
|
|
883
858
|
this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
884
859
|
} catch (err) {
|
|
885
|
-
resourceMemoryHost?.release();
|
|
886
860
|
if (
|
|
887
861
|
typeof err === 'object' &&
|
|
888
862
|
err !== null &&
|
|
@@ -897,12 +871,11 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
897
871
|
throw normalizeFirmwarePreparationError(err);
|
|
898
872
|
}
|
|
899
873
|
|
|
900
|
-
if (
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
874
|
+
if (wantsResources && this.params.resourceArchiveBinary) {
|
|
875
|
+
return this.runProtocolV2DirectArtifacts({
|
|
876
|
+
availableInstallItems: installItems ?? explicitInstallItems,
|
|
877
|
+
announceDownload: false,
|
|
878
|
+
});
|
|
906
879
|
}
|
|
907
880
|
|
|
908
881
|
if (!bootloaderBinary && fwBinaryMap.length === 0 && !installItems?.length) {
|
|
@@ -1055,133 +1028,69 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1055
1028
|
return installSources;
|
|
1056
1029
|
}
|
|
1057
1030
|
|
|
1058
|
-
private async
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
availableInstallItems = this.buildProtocolV2InstallItems({
|
|
1062
|
-
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
1063
|
-
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
1064
|
-
}),
|
|
1031
|
+
private async runProtocolV2DirectArtifacts({
|
|
1032
|
+
availableInstallItems,
|
|
1033
|
+
announceDownload = true,
|
|
1065
1034
|
}: {
|
|
1066
|
-
features: Features;
|
|
1067
|
-
firmwareType: EFirmwareType;
|
|
1068
1035
|
availableInstallItems?: ProtocolV2InstallItem[];
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
);
|
|
1082
|
-
const missingTarget = Array.from(requestedComponentTargets).find(
|
|
1083
|
-
target => !localComponentTargets.has(target)
|
|
1084
|
-
);
|
|
1085
|
-
if (missingTarget) {
|
|
1086
|
-
throw ERRORS.TypedError(
|
|
1087
|
-
HardwareErrorCode.RuntimeError,
|
|
1088
|
-
`Protocol V2 local update has no binary for requested target ${missingTarget}`,
|
|
1089
|
-
{
|
|
1090
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
1091
|
-
artifactName: missingTarget,
|
|
1092
|
-
}
|
|
1036
|
+
announceDownload?: boolean;
|
|
1037
|
+
}) {
|
|
1038
|
+
try {
|
|
1039
|
+
if (announceDownload) {
|
|
1040
|
+
this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
1041
|
+
}
|
|
1042
|
+
const installItems = this.filterProtocolV2LocalInstallItems(
|
|
1043
|
+
availableInstallItems ??
|
|
1044
|
+
this.buildProtocolV2InstallItems({
|
|
1045
|
+
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
1046
|
+
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
1047
|
+
})
|
|
1093
1048
|
);
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1049
|
+
const installSources = await Promise.all(
|
|
1050
|
+
installItems.map(async item => ({
|
|
1051
|
+
fileName: item.fileName,
|
|
1052
|
+
source: await this.openProtocolV2MemorySource(item.binary),
|
|
1053
|
+
targetId: item.targetId,
|
|
1054
|
+
kind: item.kind,
|
|
1055
|
+
}))
|
|
1056
|
+
);
|
|
1057
|
+
const resourceSources = this.params.resourceArchiveBinary
|
|
1058
|
+
? await this.createProtocolV2ResourceSourcesFromArchive(this.params.resourceArchiveBinary)
|
|
1059
|
+
: [];
|
|
1060
|
+
if (installSources.length === 0 && resourceSources.length === 0) {
|
|
1103
1061
|
throw ERRORS.TypedError(
|
|
1104
|
-
HardwareErrorCode.
|
|
1105
|
-
|
|
1106
|
-
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1062
|
+
HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
1063
|
+
'No firmware to update'
|
|
1107
1064
|
);
|
|
1108
1065
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
expectedSize: item.binary.byteLength,
|
|
1116
|
-
expectedSha256: bytesToHex(sha256(new Uint8Array(item.binary))),
|
|
1117
|
-
...(this.params.expectedTargetVersions?.[target]
|
|
1118
|
-
? { targetVersion: this.params.expectedTargetVersions[target] }
|
|
1119
|
-
: {}),
|
|
1066
|
+
if (announceDownload) {
|
|
1067
|
+
this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
1068
|
+
}
|
|
1069
|
+
return await this.executeProtocolV2SourceUpdate({
|
|
1070
|
+
installSources,
|
|
1071
|
+
resourceSources,
|
|
1120
1072
|
});
|
|
1121
|
-
|
|
1073
|
+
} finally {
|
|
1074
|
+
await this.closeProtocolV2PreparedSources();
|
|
1122
1075
|
}
|
|
1076
|
+
}
|
|
1123
1077
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
artifactId: resourceArtifactId,
|
|
1138
|
-
binary: resourceArchive.binary,
|
|
1139
|
-
materializedEntries: resourceArchive.materializedEntries,
|
|
1140
|
-
});
|
|
1141
|
-
|
|
1142
|
-
const plan = buildProtocolV2LocalFirmwareUpdatePlan({
|
|
1143
|
-
features,
|
|
1144
|
-
firmwareType,
|
|
1145
|
-
platform: this.params.platform,
|
|
1146
|
-
artifacts: planArtifacts,
|
|
1147
|
-
});
|
|
1148
|
-
let memoryHost: FirmwareUpdateV4MemoryHost | undefined;
|
|
1149
|
-
try {
|
|
1150
|
-
memoryHost = prepareFirmwareUpdateV4MemoryHost({
|
|
1151
|
-
sdk: {
|
|
1152
|
-
prepareFirmwareUpdatePlan,
|
|
1153
|
-
registerFirmwareUpdateHostBinding,
|
|
1154
|
-
unregisterFirmwareUpdateHostBinding,
|
|
1155
|
-
},
|
|
1156
|
-
plan,
|
|
1157
|
-
artifacts: memoryArtifacts,
|
|
1158
|
-
});
|
|
1159
|
-
const preparedPlan = validateFirmwareUpdatePreparedPlan(memoryHost.preparedPlan);
|
|
1160
|
-
assertFirmwareUpdatePreparedPlanBinding({
|
|
1161
|
-
preparedPlan,
|
|
1162
|
-
executor: 'v4',
|
|
1163
|
-
platform: this.params.platform,
|
|
1164
|
-
scopeTargets: [],
|
|
1165
|
-
bindings: [],
|
|
1166
|
-
});
|
|
1167
|
-
assertFirmwareUpdatePreparedPlanDeviceIdentity({
|
|
1168
|
-
preparedPlan,
|
|
1169
|
-
deviceIdentity: this.protocolV2ExpectedSerialNumber,
|
|
1170
|
-
deviceModel: this.getProtocolV2PreparedPlanDeviceModel(features),
|
|
1078
|
+
private async createProtocolV2ResourceSourcesFromArchive(
|
|
1079
|
+
binary: ArrayBuffer
|
|
1080
|
+
): Promise<ProtocolV2ResourceBundleSource[]> {
|
|
1081
|
+
const archive = await this.prepareProtocolV2LocalResourceArchive(binary);
|
|
1082
|
+
const sources: ProtocolV2ResourceBundleSource[] = [];
|
|
1083
|
+
for (const resource of archive.resources) {
|
|
1084
|
+
sources.push({
|
|
1085
|
+
name: resource.entryName.split('/').pop() ?? resource.entryName,
|
|
1086
|
+
source: await this.openProtocolV2MemorySource(resource.binary),
|
|
1087
|
+
devicePath: resource.header.devicePath,
|
|
1088
|
+
version: resource.header.version,
|
|
1089
|
+
payloadHash: resource.header.payloadHash,
|
|
1090
|
+
headerHash: resource.header.headerHash,
|
|
1171
1091
|
});
|
|
1172
|
-
const hostBinding = resolveFirmwareUpdateHostBinding(
|
|
1173
|
-
memoryHost.hostBindingGeneration,
|
|
1174
|
-
preparedPlan.preparedPlanDigest
|
|
1175
|
-
);
|
|
1176
|
-
this.params.preparedPlan = preparedPlan;
|
|
1177
|
-
this.params.targetsToUpdate = [...preparedPlan.targetsToUpdate] as FirmwareUpdateV4Target[];
|
|
1178
|
-
this.params.artifactReader = hostBinding.artifactReader;
|
|
1179
|
-
this.params.componentArtifacts = undefined;
|
|
1180
|
-
return memoryHost;
|
|
1181
|
-
} catch (error) {
|
|
1182
|
-
memoryHost?.release();
|
|
1183
|
-
throw error;
|
|
1184
1092
|
}
|
|
1093
|
+
return sources;
|
|
1185
1094
|
}
|
|
1186
1095
|
|
|
1187
1096
|
private async prepareProtocolV2LocalResourceArchive(
|
|
@@ -1206,7 +1115,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1206
1115
|
}
|
|
1207
1116
|
const zipEntries = Object.values(zip.files);
|
|
1208
1117
|
const resourceEntries = zipEntries.filter(
|
|
1209
|
-
entry => !entry.dir && entry.name
|
|
1118
|
+
entry => !entry.dir && isProtocolV2ResourceArchiveEntryName(entry.name)
|
|
1210
1119
|
);
|
|
1211
1120
|
if (
|
|
1212
1121
|
resourceEntries.length === 0 ||
|
|
@@ -1220,7 +1129,6 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1220
1129
|
}
|
|
1221
1130
|
|
|
1222
1131
|
let totalSize = 0;
|
|
1223
|
-
const materializedEntries: FirmwareMemoryArtifactEntry[] = [];
|
|
1224
1132
|
const resources: ProtocolV2LocalResourceArchive['resources'] = [];
|
|
1225
1133
|
const devicePaths = new Set<string>();
|
|
1226
1134
|
for (const entry of resourceEntries) {
|
|
@@ -1264,10 +1172,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1264
1172
|
);
|
|
1265
1173
|
}
|
|
1266
1174
|
devicePaths.add(canonicalDevicePath);
|
|
1267
|
-
materializedEntries.push({ entryName: entry.name, binary: fileBinary });
|
|
1268
1175
|
resources.push({ entryName: entry.name, binary: fileBinary, header });
|
|
1269
1176
|
}
|
|
1270
|
-
return { binary,
|
|
1177
|
+
return { binary, resources };
|
|
1271
1178
|
}
|
|
1272
1179
|
|
|
1273
1180
|
private async prepareProtocolV2ResourceSources(): Promise<ProtocolV2ResourceBundleSource[]> {
|
|
@@ -1334,20 +1241,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1334
1241
|
|
|
1335
1242
|
// The verified ZIP bytes are authoritative. Non-okpkg entries are release
|
|
1336
1243
|
// metadata only; each RESOURCE package carries its own device path.
|
|
1337
|
-
|
|
1338
|
-
const sources: ProtocolV2ResourceBundleSource[] = [];
|
|
1339
|
-
for (const resource of verifiedArchive.resources) {
|
|
1340
|
-
const source = await this.openProtocolV2MemorySource(resource.binary);
|
|
1341
|
-
sources.push({
|
|
1342
|
-
name: resource.entryName.split('/').pop() ?? resource.entryName,
|
|
1343
|
-
source,
|
|
1344
|
-
devicePath: resource.header.devicePath,
|
|
1345
|
-
version: resource.header.version,
|
|
1346
|
-
payloadHash: resource.header.payloadHash,
|
|
1347
|
-
headerHash: resource.header.headerHash,
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
return sources;
|
|
1244
|
+
return this.createProtocolV2ResourceSourcesFromArchive(archiveBinary);
|
|
1351
1245
|
}
|
|
1352
1246
|
|
|
1353
1247
|
private async runProtocolV2PreparedArtifacts(
|
|
@@ -1831,6 +1725,12 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1831
1725
|
return `vol0:/${path}`;
|
|
1832
1726
|
}
|
|
1833
1727
|
|
|
1728
|
+
private getProtocolV2ResourceComparePath(devicePath: string) {
|
|
1729
|
+
return isProtocolV2BootResourcePackagePath(devicePath)
|
|
1730
|
+
? PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH
|
|
1731
|
+
: devicePath;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1834
1734
|
private async readProtocolV2DeviceFileHeader(path: string, expectedSize?: number) {
|
|
1835
1735
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
1836
1736
|
const filePath = this.getProtocolV2ResourceFilePath(path);
|
|
@@ -1893,7 +1793,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1893
1793
|
|
|
1894
1794
|
try {
|
|
1895
1795
|
const header = await this.readProtocolV2DeviceFileHeader(
|
|
1896
|
-
bundle.devicePath,
|
|
1796
|
+
this.getProtocolV2ResourceComparePath(bundle.devicePath),
|
|
1897
1797
|
bundle.source.size
|
|
1898
1798
|
);
|
|
1899
1799
|
if (!header) return false;
|
|
@@ -2152,11 +2052,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2152
2052
|
let totalSize = installSources.reduce((total, item) => total + item.source.size, 0);
|
|
2153
2053
|
const resourcesToSync: ProtocolV2ResourceBundleSource[] = [];
|
|
2154
2054
|
for (const resource of resourceSources) {
|
|
2155
|
-
|
|
2156
|
-
// stale staging bytes with the artifact approved by the current PreparedPlan,
|
|
2157
|
-
// even when the mounted final file itself is already current.
|
|
2158
|
-
const requiresFreshStaging = isProtocolV2BootResourcePackagePath(resource.devicePath);
|
|
2159
|
-
if (!requiresFreshStaging && (await this.isProtocolV2ResourceBundleUpToDate(resource))) {
|
|
2055
|
+
if (await this.isProtocolV2ResourceBundleUpToDate(resource)) {
|
|
2160
2056
|
Log.log(`[FirmwareUpdateV4] skip RESC bundle ${resource.name}; already up to date`);
|
|
2161
2057
|
} else {
|
|
2162
2058
|
resourcesToSync.push(resource);
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { canonicalizePro2BleAdvertisementName } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from './BaseMethod';
|
|
4
4
|
import TransportManager from '../data-manager/TransportManager';
|
|
@@ -40,7 +40,7 @@ export default class SearchDevices extends BaseMethod {
|
|
|
40
40
|
seenIds.add(lowerId);
|
|
41
41
|
const rawBleName =
|
|
42
42
|
device.name ?? (device as unknown as { localName?: string }).localName ?? '';
|
|
43
|
-
const bleName =
|
|
43
|
+
const bleName = canonicalizePro2BleAdvertisementName(rawBleName);
|
|
44
44
|
devices.push({
|
|
45
45
|
...device,
|
|
46
46
|
connectId: device.id,
|
|
@@ -654,47 +654,6 @@ const finalizeFirmwareUpdatePlan = ({
|
|
|
654
654
|
});
|
|
655
655
|
};
|
|
656
656
|
|
|
657
|
-
export type ProtocolV2LocalFirmwareUpdatePlanArtifact = {
|
|
658
|
-
artifactId: string;
|
|
659
|
-
target: Exclude<FirmwareUpdateV4Target, 'boot_resources'>;
|
|
660
|
-
container: 'raw' | 'zip';
|
|
661
|
-
logicalName: string;
|
|
662
|
-
expectedSize: number;
|
|
663
|
-
expectedSha256: string;
|
|
664
|
-
targetVersion?: string;
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
export const buildProtocolV2LocalFirmwareUpdatePlan = ({
|
|
668
|
-
features,
|
|
669
|
-
firmwareType,
|
|
670
|
-
platform,
|
|
671
|
-
artifacts,
|
|
672
|
-
}: {
|
|
673
|
-
features: Features;
|
|
674
|
-
firmwareType: EFirmwareType;
|
|
675
|
-
platform: FirmwareUpdatePlatform;
|
|
676
|
-
artifacts: ProtocolV2LocalFirmwareUpdatePlanArtifact[];
|
|
677
|
-
}): FirmwareUpdatePlan => {
|
|
678
|
-
if (artifacts.length === 0) {
|
|
679
|
-
return planError('Protocol V2 local firmware plan has no artifacts');
|
|
680
|
-
}
|
|
681
|
-
const plan = finalizeFirmwareUpdatePlan({
|
|
682
|
-
features,
|
|
683
|
-
firmwareType,
|
|
684
|
-
platform,
|
|
685
|
-
artifacts: artifacts.map(artifact => ({
|
|
686
|
-
...artifact,
|
|
687
|
-
role: artifact.target === 'resource' ? 'resourceBundle' : 'component',
|
|
688
|
-
url: `https://local-firmware.invalid/${encodeURIComponent(artifact.artifactId)}`,
|
|
689
|
-
})),
|
|
690
|
-
targetsToUpdate: artifacts.map(artifact => artifact.target),
|
|
691
|
-
});
|
|
692
|
-
if (plan.executor !== 'v4') {
|
|
693
|
-
return planError('Protocol V2 local firmware plan requires executor v4');
|
|
694
|
-
}
|
|
695
|
-
return plan;
|
|
696
|
-
};
|
|
697
|
-
|
|
698
657
|
export const buildProtocolV2FirmwareUpdatePlan = ({
|
|
699
658
|
features,
|
|
700
659
|
firmwareType,
|
|
@@ -71,6 +71,13 @@ export const getFirmwareUpdateResourceName = (value: unknown): string => {
|
|
|
71
71
|
return resourceName;
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
+
const getPreparedEntryIdentity = (entryName: unknown): string => {
|
|
75
|
+
getFirmwareUpdateResourceName(entryName);
|
|
76
|
+
// Protocol V2 resource ZIPs can ship the same basename from different
|
|
77
|
+
// directories, such as rom/params.okpkg and bootloader/params.okpkg.
|
|
78
|
+
return (entryName as string).toLowerCase();
|
|
79
|
+
};
|
|
80
|
+
|
|
74
81
|
const assertPreparedEntry = (value: unknown): FirmwareUpdatePreparedEntry => {
|
|
75
82
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
76
83
|
return preparedPlanError('Firmware prepared plan entry must be an object');
|
|
@@ -141,11 +148,8 @@ const assertPreparedArtifacts = ({
|
|
|
141
148
|
}
|
|
142
149
|
if (
|
|
143
150
|
materializedEntries &&
|
|
144
|
-
new Set(
|
|
145
|
-
materializedEntries.
|
|
146
|
-
getFirmwareUpdateResourceName(entry.entryName).toLowerCase()
|
|
147
|
-
)
|
|
148
|
-
).size !== materializedEntries.length
|
|
151
|
+
new Set(materializedEntries.map(entry => getPreparedEntryIdentity(entry.entryName))).size !==
|
|
152
|
+
materializedEntries.length
|
|
149
153
|
) {
|
|
150
154
|
return preparedPlanError('Firmware prepared plan contains duplicate entry names');
|
|
151
155
|
}
|
|
@@ -281,7 +285,7 @@ export const validateFirmwareUpdatePreparedPlan = (value: unknown): FirmwareUpda
|
|
|
281
285
|
const materializedEntryNames =
|
|
282
286
|
artifact.materializedEntries?.map(entry => {
|
|
283
287
|
assertPreparedEntry(entry);
|
|
284
|
-
return
|
|
288
|
+
return getPreparedEntryIdentity(entry.entryName);
|
|
285
289
|
}) ?? [];
|
|
286
290
|
if (new Set(materializedEntryNames).size !== materializedEntryNames.length) {
|
|
287
291
|
return preparedPlanError('Firmware prepared plan contains duplicate entry names');
|
package/src/core/index.ts
CHANGED
|
@@ -415,10 +415,6 @@ const onCallDevice = async (
|
|
|
415
415
|
if (method.payload?.onlyConnectBleDevice) {
|
|
416
416
|
preWarmCallbackTask?.resolve();
|
|
417
417
|
Log.debug('Call API - only connect ble device: ', device?.mainId);
|
|
418
|
-
// This early return bypasses the normal-path releaseTask at the end of the
|
|
419
|
-
// call; without it the task leaks and haunts every later queue snapshot
|
|
420
|
-
// and cancel sweep (field log: a completed task lingered for 6 minutes).
|
|
421
|
-
requestQueue.releaseTask(method.responseID);
|
|
422
418
|
return createResponseMessage(method.responseID, true, null);
|
|
423
419
|
}
|
|
424
420
|
|
|
@@ -958,60 +954,7 @@ export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unkn
|
|
|
958
954
|
* If the Bluetooth connection times out, retry up to 6 times
|
|
959
955
|
* @param retryCount - Current retry count (default 0)
|
|
960
956
|
*/
|
|
961
|
-
|
|
962
|
-
// transport that never settles (field case: Electron main lost an IPC reply,
|
|
963
|
-
// "reply was never sent" after 5 minutes) hangs the call forever and cancel()
|
|
964
|
-
// only takes effect at poll checkpoints. Race acquire against a deadline and
|
|
965
|
-
// the caller's abort signal so the hang is bounded and cancel is immediate.
|
|
966
|
-
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
967
|
-
|
|
968
|
-
function raceBleAcquire<T>(acquirePromise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {
|
|
969
|
-
return new Promise<T>((resolve, reject) => {
|
|
970
|
-
let settled = false;
|
|
971
|
-
const settle = (fn: () => void) => {
|
|
972
|
-
if (settled) return;
|
|
973
|
-
settled = true;
|
|
974
|
-
clearTimeout(deadline);
|
|
975
|
-
abortSignal?.removeEventListener('abort', onAbort);
|
|
976
|
-
fn();
|
|
977
|
-
};
|
|
978
|
-
const onAbort = () =>
|
|
979
|
-
settle(() => reject(ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)));
|
|
980
|
-
const deadline = setTimeout(
|
|
981
|
-
() =>
|
|
982
|
-
settle(() =>
|
|
983
|
-
reject(
|
|
984
|
-
ERRORS.TypedError(
|
|
985
|
-
HardwareErrorCode.BleTimeoutError,
|
|
986
|
-
`BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`
|
|
987
|
-
)
|
|
988
|
-
)
|
|
989
|
-
),
|
|
990
|
-
BLE_ACQUIRE_DEADLINE_MS
|
|
991
|
-
);
|
|
992
|
-
// Attach before any early return so a late settlement of acquirePromise
|
|
993
|
-
// is always consumed — an abort or deadline must never leave the acquire
|
|
994
|
-
// rejection unhandled.
|
|
995
|
-
acquirePromise.then(
|
|
996
|
-
value => settle(() => resolve(value)),
|
|
997
|
-
error => settle(() => reject(error))
|
|
998
|
-
);
|
|
999
|
-
if (abortSignal) {
|
|
1000
|
-
if (abortSignal.aborted) {
|
|
1001
|
-
onAbort();
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
abortSignal.addEventListener('abort', onAbort);
|
|
1005
|
-
}
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
async function connectDeviceForBle(
|
|
1010
|
-
method: BaseMethod,
|
|
1011
|
-
device: Device,
|
|
1012
|
-
abortSignal?: AbortSignal,
|
|
1013
|
-
retryCount = 0
|
|
1014
|
-
) {
|
|
957
|
+
async function connectDeviceForBle(method: BaseMethod, device: Device, retryCount = 0) {
|
|
1015
958
|
try {
|
|
1016
959
|
if (device.wasInterruptedByUser()) {
|
|
1017
960
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser);
|
|
@@ -1025,43 +968,9 @@ async function connectDeviceForBle(
|
|
|
1025
968
|
!device.commands ||
|
|
1026
969
|
device.commands.disposed;
|
|
1027
970
|
if (shouldAcquire) {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
// legitimately block on a user-driven system bonding prompt for longer
|
|
1032
|
-
// than any sane deadline. Other envs keep the plain acquire unchanged.
|
|
1033
|
-
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
1034
|
-
// A cancel landing during the retry backoff must not start a new acquire.
|
|
1035
|
-
if (useAcquireGuards && abortSignal?.aborted) {
|
|
1036
|
-
throw ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled);
|
|
1037
|
-
}
|
|
1038
|
-
if (!useAcquireGuards) {
|
|
1039
|
-
await device.acquire(method.payload.connectProtocol, {
|
|
1040
|
-
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1041
|
-
});
|
|
1042
|
-
} else {
|
|
1043
|
-
try {
|
|
1044
|
-
await raceBleAcquire(
|
|
1045
|
-
device.acquire(method.payload.connectProtocol, {
|
|
1046
|
-
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1047
|
-
}),
|
|
1048
|
-
abortSignal
|
|
1049
|
-
);
|
|
1050
|
-
} catch (err) {
|
|
1051
|
-
// A deadline hit means the transport is wedged mid-acquire; drop the
|
|
1052
|
-
// link before the retry so it cold-connects instead of stacking a
|
|
1053
|
-
// second connect onto the half-open one.
|
|
1054
|
-
if (
|
|
1055
|
-
err.errorCode === HardwareErrorCode.BleTimeoutError &&
|
|
1056
|
-
device.mainId &&
|
|
1057
|
-
device.deviceConnector
|
|
1058
|
-
) {
|
|
1059
|
-
await device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
1060
|
-
device.markTransportDisconnected();
|
|
1061
|
-
}
|
|
1062
|
-
throw err;
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
971
|
+
await device.acquire(method.payload.connectProtocol, {
|
|
972
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
973
|
+
});
|
|
1065
974
|
}
|
|
1066
975
|
if (method.payload?.onlyConnectBleDevice) {
|
|
1067
976
|
if (shouldAcquire) {
|
|
@@ -1101,7 +1010,7 @@ async function connectDeviceForBle(
|
|
|
1101
1010
|
const nextRetry = retryCount + 1;
|
|
1102
1011
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
1103
1012
|
await wait(3000);
|
|
1104
|
-
await connectDeviceForBle(method, device,
|
|
1013
|
+
await connectDeviceForBle(method, device, nextRetry);
|
|
1105
1014
|
} else {
|
|
1106
1015
|
throw err;
|
|
1107
1016
|
}
|
|
@@ -1211,7 +1120,7 @@ const ensureConnected = async (
|
|
|
1211
1120
|
if (tryCount === 1) {
|
|
1212
1121
|
device.beginConnectionAttempt();
|
|
1213
1122
|
}
|
|
1214
|
-
await connectDeviceForBle(method, device
|
|
1123
|
+
await connectDeviceForBle(method, device);
|
|
1215
1124
|
}
|
|
1216
1125
|
resolve(device);
|
|
1217
1126
|
return;
|