@onekeyfe/hd-core 1.2.0-alpha.105 → 1.2.0-alpha.106
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__/DeviceCommands.test.ts +90 -26
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +0 -2
- package/__tests__/device-pool-state.test.ts +1 -5
- package/__tests__/deviceSettings.test.ts +0 -1
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +145 -0
- package/__tests__/logBlockEvent.test.ts +13 -1
- package/__tests__/protocol-v2.test.ts +447 -122
- package/__tests__/refresh-device-state.test.ts +0 -1
- package/__tests__/search-devices.test.ts +0 -2
- package/dist/api/FirmwareUpdateV4.d.ts +7 -3
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceState.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/firmware/protocolV2Release.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +0 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +251 -184
- package/dist/protocols/protocol-v2/features.d.ts +1 -1
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/types/api/getDeviceState.d.ts +0 -1
- package/dist/types/api/getDeviceState.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +262 -172
- package/src/api/GetDeviceState.ts +0 -1
- package/src/api/SearchDevices.ts +0 -2
- package/src/api/firmware/protocolV2Release.ts +0 -1
- package/src/core/index.ts +6 -6
- package/src/device/Device.ts +11 -48
- package/src/device/DeviceCommands.ts +4 -14
- package/src/device/DevicePool.ts +3 -11
- package/src/events/logBlockEvent.ts +14 -1
- package/src/protocols/protocol-v2/features.ts +9 -2
- package/src/types/api/getDeviceState.ts +0 -2
- package/src/utils/deviceSettings.ts +1 -1
- package/__tests__/protocol-v2-legacy-recovery.test.ts +0 -29
- package/dist/core/protocolV2LegacyRecovery.d.ts +0 -5
- package/dist/core/protocolV2LegacyRecovery.d.ts.map +0 -1
- package/src/core/protocolV2LegacyRecovery.ts +0 -12
package/dist/index.js
CHANGED
|
@@ -41475,6 +41475,11 @@ const LogLabelMethod = new Set([
|
|
|
41475
41475
|
'fileWrite',
|
|
41476
41476
|
'fileRead',
|
|
41477
41477
|
]);
|
|
41478
|
+
const LogPayloadBlockMethod = new Set([
|
|
41479
|
+
'deviceUploadNft',
|
|
41480
|
+
'deviceUploadWallpaper',
|
|
41481
|
+
'uploadPortfolio',
|
|
41482
|
+
]);
|
|
41478
41483
|
const SensitiveLogKeys = new Set([
|
|
41479
41484
|
'devicestate',
|
|
41480
41485
|
'entropy',
|
|
@@ -41531,7 +41536,10 @@ function getLogBlockLabel(message) {
|
|
|
41531
41536
|
return undefined;
|
|
41532
41537
|
}
|
|
41533
41538
|
function getSafeLogPayload(value, blockLabel) {
|
|
41534
|
-
if (blockLabel &&
|
|
41539
|
+
if (blockLabel &&
|
|
41540
|
+
(LogBlockEvent.has(blockLabel) ||
|
|
41541
|
+
LogPayloadBlockMethod.has(blockLabel) ||
|
|
41542
|
+
isSigningMethod(blockLabel))) {
|
|
41535
41543
|
return { method: blockLabel, payload: '[REDACTED]' };
|
|
41536
41544
|
}
|
|
41537
41545
|
const redactedValue = redactLogValue(value, new WeakSet());
|
|
@@ -42465,7 +42473,7 @@ const getAutoShutDownOptions = (deviceType, protocol) => {
|
|
|
42465
42473
|
return withNever([60000, 120000, 300000, 600000], protocol);
|
|
42466
42474
|
case hdShared.EDeviceType.Pro2:
|
|
42467
42475
|
case hdShared.EDeviceType.Neo:
|
|
42468
|
-
return withNever([60000, 120000, 300000, 600000
|
|
42476
|
+
return withNever([60000, 120000, 300000, 600000], protocol);
|
|
42469
42477
|
default:
|
|
42470
42478
|
return [];
|
|
42471
42479
|
}
|
|
@@ -43237,7 +43245,7 @@ class DevicePool extends events.exports {
|
|
|
43237
43245
|
try {
|
|
43238
43246
|
yield device.initialize(initOptions);
|
|
43239
43247
|
if ((initOptions === null || initOptions === void 0 ? void 0 : initOptions.refreshRuntimeState) && device.isProtocolV2()) {
|
|
43240
|
-
yield this._refreshProtocolV2DiscoveryState(device
|
|
43248
|
+
yield this._refreshProtocolV2DiscoveryState(device);
|
|
43241
43249
|
}
|
|
43242
43250
|
}
|
|
43243
43251
|
finally {
|
|
@@ -43254,28 +43262,30 @@ class DevicePool extends events.exports {
|
|
|
43254
43262
|
let refreshError;
|
|
43255
43263
|
yield device.run(() => __awaiter(this, void 0, void 0, function* () {
|
|
43256
43264
|
try {
|
|
43257
|
-
yield this._refreshProtocolV2DiscoveryState(device
|
|
43265
|
+
yield this._refreshProtocolV2DiscoveryState(device);
|
|
43258
43266
|
}
|
|
43259
43267
|
catch (error) {
|
|
43260
43268
|
refreshError = error;
|
|
43261
43269
|
}
|
|
43262
|
-
}),
|
|
43263
|
-
|
|
43264
|
-
:
|
|
43270
|
+
}), {
|
|
43271
|
+
connectProtocol: initOptions.connectProtocol,
|
|
43272
|
+
forceProtocolDetection: initOptions.forceProtocolDetection,
|
|
43273
|
+
});
|
|
43265
43274
|
if (refreshError instanceof Error)
|
|
43266
43275
|
throw refreshError;
|
|
43267
43276
|
if (refreshError)
|
|
43268
43277
|
throw new Error(String(refreshError));
|
|
43269
43278
|
});
|
|
43270
43279
|
}
|
|
43271
|
-
static _refreshProtocolV2DiscoveryState(device
|
|
43280
|
+
static _refreshProtocolV2DiscoveryState(device) {
|
|
43272
43281
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43273
|
-
|
|
43274
|
-
|
|
43275
|
-
|
|
43276
|
-
yield device.getDeviceState(Object.assign({ refreshSections: ['status'] }, stateReadOptions));
|
|
43282
|
+
yield device.getDeviceState({
|
|
43283
|
+
refreshSections: ['status'],
|
|
43284
|
+
});
|
|
43277
43285
|
try {
|
|
43278
|
-
yield device.getDeviceState(
|
|
43286
|
+
yield device.getDeviceState({
|
|
43287
|
+
refreshSections: ['settings'],
|
|
43288
|
+
});
|
|
43279
43289
|
}
|
|
43280
43290
|
catch (error) {
|
|
43281
43291
|
Log$j.debug('Unable to refresh Protocol V2 device label during discovery', error);
|
|
@@ -43717,9 +43727,6 @@ class DeviceCommands {
|
|
|
43717
43727
|
const promise = this.transport.call(this.mainId, type, msg !== null && msg !== void 0 ? msg : {}, options);
|
|
43718
43728
|
this.callPromise = promise;
|
|
43719
43729
|
const res = yield promise;
|
|
43720
|
-
if (!shouldReduceDebug) {
|
|
43721
|
-
LogCore.debug('[DeviceCommands] [call] Received', res.type, hdTransport.getSafeTransportLogPayload(res.message, res.type));
|
|
43722
|
-
}
|
|
43723
43730
|
return res;
|
|
43724
43731
|
}
|
|
43725
43732
|
catch (error) {
|
|
@@ -43812,12 +43819,10 @@ class DeviceCommands {
|
|
|
43812
43819
|
if (!shouldReduceDebugForCall(callType)) {
|
|
43813
43820
|
Log$h.debug('_filterCommonTypes: ', {
|
|
43814
43821
|
request: callType,
|
|
43815
|
-
response:
|
|
43816
|
-
|
|
43817
|
-
|
|
43818
|
-
|
|
43819
|
-
}
|
|
43820
|
-
: res.type,
|
|
43822
|
+
response: {
|
|
43823
|
+
type: res.type,
|
|
43824
|
+
message: hdTransport.getSafeTransportLogPayload(res.message, res.type),
|
|
43825
|
+
},
|
|
43821
43826
|
});
|
|
43822
43827
|
}
|
|
43823
43828
|
}
|
|
@@ -44238,12 +44243,20 @@ const parseProtocolV2BuildFingerprint = (buildFingerprint) => {
|
|
|
44238
44243
|
}
|
|
44239
44244
|
return { binary, version, commit, environment, buildType };
|
|
44240
44245
|
};
|
|
44241
|
-
const getProtocolV2RuntimeMode = (protocolInfo) => {
|
|
44242
|
-
var _a;
|
|
44246
|
+
const getProtocolV2RuntimeMode = (protocolInfo, deviceInfo) => {
|
|
44247
|
+
var _a, _b, _c, _d;
|
|
44243
44248
|
const binary = (_a = parseProtocolV2BuildFingerprint(protocolInfo.build_fingerprint)) === null || _a === void 0 ? void 0 : _a.binary;
|
|
44244
44249
|
if (binary === 'application')
|
|
44245
44250
|
return 'normal';
|
|
44246
|
-
|
|
44251
|
+
if (binary)
|
|
44252
|
+
return binary;
|
|
44253
|
+
if (isLegacyProtocolV2ProtocolInfo(protocolInfo) && !((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.application)) {
|
|
44254
|
+
if ((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.romloader)
|
|
44255
|
+
return 'romloader';
|
|
44256
|
+
if ((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _d === void 0 ? void 0 : _d.bootloader)
|
|
44257
|
+
return 'bootloader';
|
|
44258
|
+
}
|
|
44259
|
+
return undefined;
|
|
44247
44260
|
};
|
|
44248
44261
|
const PROTOCOL_V2_DEVICE_STATUS_GET_MESSAGE_TYPE = 60602;
|
|
44249
44262
|
const supportsProtocolV2Message = (protocolInfo, messageType) => protocolInfo.supported_messages.includes(messageType);
|
|
@@ -45640,10 +45653,7 @@ class Device extends events.exports {
|
|
|
45640
45653
|
commands: this.commands,
|
|
45641
45654
|
timeoutMs: options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs,
|
|
45642
45655
|
});
|
|
45643
|
-
|
|
45644
|
-
? yield this.probeProtocolV2RuntimeState(deviceInfo, options.protocolV2DeviceInfoTimeoutMs, { allowLegacyProtocolV2ProtocolInfo: true })
|
|
45645
|
-
: yield this.probeProtocolV2RuntimeState(deviceInfo, options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs);
|
|
45646
|
-
Log$g.debug('Protocol V2 features:', features);
|
|
45656
|
+
yield this.probeProtocolV2RuntimeState(deviceInfo, options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs);
|
|
45647
45657
|
}
|
|
45648
45658
|
catch (error) {
|
|
45649
45659
|
Log$g.error('Protocol V2 initialization failed:', error);
|
|
@@ -45683,14 +45693,7 @@ class Device extends events.exports {
|
|
|
45683
45693
|
commands: this.commands,
|
|
45684
45694
|
request: getProtocolV2DeviceInfoRequest(),
|
|
45685
45695
|
});
|
|
45686
|
-
|
|
45687
|
-
yield this.probeProtocolV2RuntimeState(deviceInfo, undefined, {
|
|
45688
|
-
allowLegacyProtocolV2ProtocolInfo: true,
|
|
45689
|
-
});
|
|
45690
|
-
}
|
|
45691
|
-
else {
|
|
45692
|
-
yield this.probeProtocolV2RuntimeState(deviceInfo);
|
|
45693
|
-
}
|
|
45696
|
+
yield this.probeProtocolV2RuntimeState(deviceInfo);
|
|
45694
45697
|
refreshedDeviceInfo = deviceInfo;
|
|
45695
45698
|
initializedWithDeviceInfo = true;
|
|
45696
45699
|
}
|
|
@@ -45721,9 +45724,9 @@ class Device extends events.exports {
|
|
|
45721
45724
|
}
|
|
45722
45725
|
if (refresh.has('status') && !initializedWithDeviceInfo) {
|
|
45723
45726
|
const cachedMode = (_c = this.state) === null || _c === void 0 ? void 0 : _c.status.mode;
|
|
45724
|
-
yield this.probeProtocolV2RuntimeState(refreshedDeviceInfo, undefined,
|
|
45725
|
-
|
|
45726
|
-
|
|
45727
|
+
yield this.probeProtocolV2RuntimeState(refreshedDeviceInfo, undefined, {
|
|
45728
|
+
forceRuntimeContextRefresh: cachedMode === 'bootloader' || cachedMode === 'romloader',
|
|
45729
|
+
});
|
|
45727
45730
|
}
|
|
45728
45731
|
if (refresh.has('settings') && ((_d = this.state) === null || _d === void 0 ? void 0 : _d.status.mode) === 'normal') {
|
|
45729
45732
|
const { message } = yield this.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
|
|
@@ -45762,9 +45765,10 @@ class Device extends events.exports {
|
|
|
45762
45765
|
source,
|
|
45763
45766
|
changedKeys: result.changedKeys,
|
|
45764
45767
|
};
|
|
45765
|
-
Log$g.debug('Device state
|
|
45768
|
+
Log$g.debug('Device state updated', {
|
|
45766
45769
|
source,
|
|
45767
|
-
|
|
45770
|
+
revision: result.revision,
|
|
45771
|
+
changedKeyCount: result.changedKeys.length,
|
|
45768
45772
|
});
|
|
45769
45773
|
this.emit(DEVICE.STATE, this, event);
|
|
45770
45774
|
if (result.state.protocol === 'V1') {
|
|
@@ -45786,13 +45790,6 @@ class Device extends events.exports {
|
|
|
45786
45790
|
ensureProtocolV2RuntimeContext(timeoutMs, options) {
|
|
45787
45791
|
var _a, _b, _c, _d;
|
|
45788
45792
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45789
|
-
const assertProtocolInfoAllowed = (protocolInfo) => {
|
|
45790
|
-
if (isLegacyProtocolV2ProtocolInfo(protocolInfo) &&
|
|
45791
|
-
(options === null || options === void 0 ? void 0 : options.allowLegacyProtocolV2ProtocolInfo) !== true) {
|
|
45792
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, 'Legacy Protocol V2 ProtocolInfo is supported only during device discovery and firmware update.');
|
|
45793
|
-
}
|
|
45794
|
-
return protocolInfo;
|
|
45795
|
-
};
|
|
45796
45793
|
const cachedProtocolInfo = (options === null || options === void 0 ? void 0 : options.forceRefresh) === true
|
|
45797
45794
|
? undefined
|
|
45798
45795
|
: (_a = this.protocolV2RuntimeContext) !== null && _a !== void 0 ? _a : (!this.protocolV2StateNeedsReload
|
|
@@ -45800,10 +45797,10 @@ class Device extends events.exports {
|
|
|
45800
45797
|
: undefined);
|
|
45801
45798
|
if (cachedProtocolInfo) {
|
|
45802
45799
|
this.protocolV2RuntimeContext = cachedProtocolInfo;
|
|
45803
|
-
return
|
|
45800
|
+
return cachedProtocolInfo;
|
|
45804
45801
|
}
|
|
45805
45802
|
if (this.protocolV2RuntimeContextPromise) {
|
|
45806
|
-
return
|
|
45803
|
+
return this.protocolV2RuntimeContextPromise;
|
|
45807
45804
|
}
|
|
45808
45805
|
const requestToken = {};
|
|
45809
45806
|
const pendingRequest = (() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -45820,7 +45817,7 @@ class Device extends events.exports {
|
|
|
45820
45817
|
this.protocolV2RuntimeContextRequestToken = requestToken;
|
|
45821
45818
|
this.protocolV2RuntimeContextPromise = pendingRequest;
|
|
45822
45819
|
try {
|
|
45823
|
-
return
|
|
45820
|
+
return yield pendingRequest;
|
|
45824
45821
|
}
|
|
45825
45822
|
finally {
|
|
45826
45823
|
if (this.protocolV2RuntimeContextPromise === pendingRequest) {
|
|
@@ -45837,11 +45834,10 @@ class Device extends events.exports {
|
|
|
45837
45834
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45838
45835
|
const protocolInfo = yield this.ensureProtocolV2RuntimeContext(timeoutMs, {
|
|
45839
45836
|
forceRefresh: options === null || options === void 0 ? void 0 : options.forceRuntimeContextRefresh,
|
|
45840
|
-
allowLegacyProtocolV2ProtocolInfo: options === null || options === void 0 ? void 0 : options.allowLegacyProtocolV2ProtocolInfo,
|
|
45841
45837
|
});
|
|
45842
|
-
const runtimeMode = getProtocolV2RuntimeMode(protocolInfo);
|
|
45843
|
-
const legacyProtocolInfo = isLegacyProtocolV2ProtocolInfo(protocolInfo);
|
|
45844
45838
|
const runtimeDeviceInfo = deviceInfo !== null && deviceInfo !== void 0 ? deviceInfo : (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2DeviceInfo;
|
|
45839
|
+
const runtimeMode = getProtocolV2RuntimeMode(protocolInfo, runtimeDeviceInfo);
|
|
45840
|
+
const legacyProtocolInfo = isLegacyProtocolV2ProtocolInfo(protocolInfo);
|
|
45845
45841
|
const protocolV2DeviceType = runtimeDeviceInfo
|
|
45846
45842
|
? resolveProtocolV2DeviceIdentity((_c = runtimeDeviceInfo.hw) === null || _c === void 0 ? void 0 : _c.Device_type).deviceType
|
|
45847
45843
|
: this.getCurrentDeviceType();
|
|
@@ -46854,7 +46850,6 @@ class SearchDevices extends BaseMethod {
|
|
|
46854
46850
|
connectProtocol: undefined,
|
|
46855
46851
|
forceProtocolDetection: true,
|
|
46856
46852
|
refreshRuntimeState: true,
|
|
46857
|
-
allowLegacyProtocolV2ProtocolInfo: true,
|
|
46858
46853
|
});
|
|
46859
46854
|
deviceList.push(...result.deviceList);
|
|
46860
46855
|
}
|
|
@@ -46938,7 +46933,9 @@ class GetDeviceState extends BaseMethod {
|
|
|
46938
46933
|
}
|
|
46939
46934
|
run() {
|
|
46940
46935
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46941
|
-
const state = yield this.device.getDeviceState(
|
|
46936
|
+
const state = yield this.device.getDeviceState({
|
|
46937
|
+
refreshSections: SCOPE_SECTIONS[this.params.scope],
|
|
46938
|
+
});
|
|
46942
46939
|
if (this.params.scope === 'settings' &&
|
|
46943
46940
|
this.device.isProtocolV2() &&
|
|
46944
46941
|
isLoaderMode(state.status.mode)) {
|
|
@@ -47477,7 +47474,6 @@ function loadProtocolV2FirmwareReleaseContext({ device, firmwareType: firmwareTy
|
|
|
47477
47474
|
refreshSections: checkFirmwareHash
|
|
47478
47475
|
? ['identity', 'versions', 'verification']
|
|
47479
47476
|
: ['identity', 'versions'],
|
|
47480
|
-
allowLegacyProtocolV2ProtocolInfo: true,
|
|
47481
47477
|
});
|
|
47482
47478
|
if (state.identity.deviceType !== 'pro2' && state.identity.deviceType !== 'neo') {
|
|
47483
47479
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportMethod, `${methodName} requires a Pro2 or Neo device for Protocol V2`);
|
|
@@ -51835,6 +51831,16 @@ const isProtocolV2ReconnectProbeError = (error) => {
|
|
|
51835
51831
|
return ((message.includes('device protocol mismatch') && message.includes('expected v2')) ||
|
|
51836
51832
|
message.includes('did not respond to expected protocol'));
|
|
51837
51833
|
};
|
|
51834
|
+
const isProtocolV2BleTransportReleasedError = (error) => {
|
|
51835
|
+
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51836
|
+
const compactMessage = message.replace(/\s+/gu, '');
|
|
51837
|
+
return (message.includes('react native ble transport released') ||
|
|
51838
|
+
message.includes('bledevicedisconnected') ||
|
|
51839
|
+
message.includes('bleconnectederror') ||
|
|
51840
|
+
(compactMessage.includes('rxerrorerror6') &&
|
|
51841
|
+
(compactMessage.includes('multiplatformbleadapter') ||
|
|
51842
|
+
compactMessage.includes('multipalformebleadapter'))));
|
|
51843
|
+
};
|
|
51838
51844
|
const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
|
|
51839
51845
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51840
51846
|
return (message.includes('handler not registered') ||
|
|
@@ -51981,6 +51987,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
51981
51987
|
this.protocolV2BootResourceStagingSafe = false;
|
|
51982
51988
|
this.protocolV2CompletedTargetVersions = new Map();
|
|
51983
51989
|
this.protocolV2FinalStatusVerified = false;
|
|
51990
|
+
this.protocolV2InstallAckReceived = false;
|
|
51991
|
+
this.protocolV2InstallBaselineVersions = new Map();
|
|
51984
51992
|
}
|
|
51985
51993
|
getSupportedProtocols() {
|
|
51986
51994
|
return ['V2'];
|
|
@@ -52158,6 +52166,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52158
52166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52159
52167
|
yield this.captureProtocolV2PhysicalIdentity();
|
|
52160
52168
|
const deviceFeatures = yield this.getProtocolV2DeviceFeatures();
|
|
52169
|
+
this.protocolV2InstallBaselineVersions =
|
|
52170
|
+
this.getProtocolV2ObservableTargetVersions(deviceFeatures);
|
|
52171
|
+
this.protocolV2LastRuntimeProbeFeatures = undefined;
|
|
52161
52172
|
const currentDeviceType = this.device.getCurrentDeviceType();
|
|
52162
52173
|
const capabilityDeviceType = currentDeviceType === hdShared.EDeviceType.Pro2 || currentDeviceType === hdShared.EDeviceType.Neo
|
|
52163
52174
|
? currentDeviceType
|
|
@@ -52166,9 +52177,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52166
52177
|
const deviceFirmwareType = getFirmwareType(deviceFeatures);
|
|
52167
52178
|
const firmwareType = (_a = this.params.firmwareType) !== null && _a !== void 0 ? _a : deviceFirmwareType;
|
|
52168
52179
|
this.validateExpectedTargetVersions();
|
|
52180
|
+
const wantsResources = !!((_b = this.params.targetsToUpdate) === null || _b === void 0 ? void 0 : _b.includes('resource'));
|
|
52169
52181
|
if (!this.params.preparedPlan &&
|
|
52170
52182
|
this.params.resourceArchiveBinary &&
|
|
52171
|
-
((
|
|
52183
|
+
((_c = this.params.targetsToUpdate) === null || _c === void 0 ? void 0 : _c.includes('resource'))) {
|
|
52172
52184
|
const localMemoryHost = yield this.prepareProtocolV2LocalMemoryHost({
|
|
52173
52185
|
features: deviceFeatures,
|
|
52174
52186
|
firmwareType,
|
|
@@ -52180,14 +52192,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52180
52192
|
localMemoryHost.release();
|
|
52181
52193
|
}
|
|
52182
52194
|
}
|
|
52183
|
-
const hasPreparedComponentArtifacts = Object.values((
|
|
52195
|
+
const hasPreparedComponentArtifacts = Object.values((_d = this.params.componentArtifacts) !== null && _d !== void 0 ? _d : {}).some(Boolean);
|
|
52184
52196
|
if (this.params.preparedPlan || hasPreparedComponentArtifacts) {
|
|
52185
52197
|
return this.runProtocolV2PreparedArtifacts(deviceFeatures, firmwareType);
|
|
52186
52198
|
}
|
|
52187
|
-
const wantsResources = !!((_d = this.params.targetsToUpdate) === null || _d === void 0 ? void 0 : _d.includes('resource'));
|
|
52188
52199
|
let fwBinaryMap = [];
|
|
52189
52200
|
let bootloaderBinary = null;
|
|
52190
52201
|
let installItems;
|
|
52202
|
+
let resourceMemoryHost;
|
|
52191
52203
|
try {
|
|
52192
52204
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
52193
52205
|
fwBinaryMap = this.collectExplicitTargetBinaries();
|
|
@@ -52200,20 +52212,19 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52200
52212
|
const needsRemoteFirmware = ((_e = this.params.targetsToUpdate) === null || _e === void 0 ? void 0 : _e.length)
|
|
52201
52213
|
? missingFirmwareTargets.length > 0
|
|
52202
52214
|
: explicitInstallItems.length === 0;
|
|
52203
|
-
|
|
52204
|
-
|
|
52205
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
52206
|
-
});
|
|
52207
|
-
}
|
|
52208
|
-
if (needsRemoteFirmware &&
|
|
52215
|
+
const needsSdkManagedArtifacts = needsRemoteFirmware || wantsResources;
|
|
52216
|
+
if (needsSdkManagedArtifacts &&
|
|
52209
52217
|
(this.params.artifactReader ||
|
|
52210
52218
|
DataManager.getSettings('firmwareManifestMode') === 'external-only')) {
|
|
52211
52219
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 firmware artifacts must be prepared by the external firmware host', {
|
|
52212
52220
|
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
52213
52221
|
});
|
|
52214
52222
|
}
|
|
52215
|
-
if (
|
|
52216
|
-
yield DataManager.forceReloadData(
|
|
52223
|
+
if (needsSdkManagedArtifacts) {
|
|
52224
|
+
yield DataManager.forceReloadData({
|
|
52225
|
+
requireResources: wantsResources,
|
|
52226
|
+
resourceDeviceType: capabilityDeviceType === hdShared.EDeviceType.Neo ? hdShared.EDeviceType.Neo : hdShared.EDeviceType.Pro2,
|
|
52227
|
+
});
|
|
52217
52228
|
}
|
|
52218
52229
|
if (needsRemoteFirmware) {
|
|
52219
52230
|
const remoteBinaries = yield this.prepareRemoteProtocolV2Binaries(firmwareType, deviceFeatures, explicitInstallItems);
|
|
@@ -52233,9 +52244,18 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52233
52244
|
targetId: item.targetId,
|
|
52234
52245
|
}));
|
|
52235
52246
|
}
|
|
52247
|
+
if (wantsResources) {
|
|
52248
|
+
this.params.resourceArchiveBinary = yield this.downloadRemoteProtocolV2ResourceArchive(deviceFeatures);
|
|
52249
|
+
resourceMemoryHost = yield this.prepareProtocolV2LocalMemoryHost({
|
|
52250
|
+
features: deviceFeatures,
|
|
52251
|
+
firmwareType,
|
|
52252
|
+
availableInstallItems: installItems !== null && installItems !== void 0 ? installItems : explicitInstallItems,
|
|
52253
|
+
});
|
|
52254
|
+
}
|
|
52236
52255
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
52237
52256
|
}
|
|
52238
52257
|
catch (err) {
|
|
52258
|
+
resourceMemoryHost === null || resourceMemoryHost === void 0 ? void 0 : resourceMemoryHost.release();
|
|
52239
52259
|
if (typeof err === 'object' &&
|
|
52240
52260
|
err !== null &&
|
|
52241
52261
|
'params' in err &&
|
|
@@ -52247,6 +52267,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52247
52267
|
}
|
|
52248
52268
|
throw normalizeFirmwarePreparationError(err);
|
|
52249
52269
|
}
|
|
52270
|
+
if (resourceMemoryHost) {
|
|
52271
|
+
try {
|
|
52272
|
+
return yield this.runProtocolV2PreparedArtifacts(deviceFeatures, firmwareType, false);
|
|
52273
|
+
}
|
|
52274
|
+
finally {
|
|
52275
|
+
resourceMemoryHost.release();
|
|
52276
|
+
}
|
|
52277
|
+
}
|
|
52250
52278
|
if (!bootloaderBinary && fwBinaryMap.length === 0 && !(installItems === null || installItems === void 0 ? void 0 : installItems.length)) {
|
|
52251
52279
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, 'No firmware to update');
|
|
52252
52280
|
}
|
|
@@ -52346,13 +52374,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52346
52374
|
return installSources;
|
|
52347
52375
|
});
|
|
52348
52376
|
}
|
|
52349
|
-
prepareProtocolV2LocalMemoryHost({ features, firmwareType,
|
|
52377
|
+
prepareProtocolV2LocalMemoryHost({ features, firmwareType, availableInstallItems = this.buildProtocolV2InstallItems({
|
|
52378
|
+
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
52379
|
+
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
52380
|
+
}), }) {
|
|
52350
52381
|
var _a, _b;
|
|
52351
52382
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52352
|
-
const availableInstallItems = this.buildProtocolV2InstallItems({
|
|
52353
|
-
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
52354
|
-
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
52355
|
-
});
|
|
52356
52383
|
const requestedComponentTargets = new Set(((_a = this.params.targetsToUpdate) !== null && _a !== void 0 ? _a : []).filter((target) => target !== 'resource' && target !== 'boot_resources'));
|
|
52357
52384
|
const localComponentTargets = new Set(availableInstallItems.flatMap(item => {
|
|
52358
52385
|
const target = PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID.get(item.targetId);
|
|
@@ -52629,16 +52656,20 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52629
52656
|
return sources;
|
|
52630
52657
|
});
|
|
52631
52658
|
}
|
|
52632
|
-
runProtocolV2PreparedArtifacts(features, firmwareType) {
|
|
52659
|
+
runProtocolV2PreparedArtifacts(features, firmwareType, announceDownload = true) {
|
|
52633
52660
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52634
52661
|
try {
|
|
52635
|
-
|
|
52662
|
+
if (announceDownload) {
|
|
52663
|
+
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
52664
|
+
}
|
|
52636
52665
|
const installSources = yield this.prepareProtocolV2InstallSources(firmwareType, features);
|
|
52637
52666
|
const resourceSources = yield this.prepareProtocolV2ResourceSources();
|
|
52638
52667
|
if (installSources.length === 0 && resourceSources.length === 0) {
|
|
52639
52668
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, 'No firmware to update');
|
|
52640
52669
|
}
|
|
52641
|
-
|
|
52670
|
+
if (announceDownload) {
|
|
52671
|
+
this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
52672
|
+
}
|
|
52642
52673
|
return yield this.executeProtocolV2SourceUpdate({
|
|
52643
52674
|
installSources,
|
|
52644
52675
|
resourceSources,
|
|
@@ -52924,6 +52955,30 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52924
52955
|
return Object.assign(Object.assign({}, target), { binary });
|
|
52925
52956
|
});
|
|
52926
52957
|
}
|
|
52958
|
+
downloadRemoteProtocolV2ResourceArchive(features) {
|
|
52959
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52960
|
+
const deviceType = getDeviceType(features);
|
|
52961
|
+
if (deviceType !== hdShared.EDeviceType.Pro2 && deviceType !== hdShared.EDeviceType.Neo) {
|
|
52962
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 resource archive requires a Pro2 or Neo device');
|
|
52963
|
+
}
|
|
52964
|
+
const source = DataManager.getProtocolV2ResourceSource(deviceType);
|
|
52965
|
+
const expectedSha256 = normalizeProtocolV2Hex(source === null || source === void 0 ? void 0 : source.archiveSha256);
|
|
52966
|
+
if (!(source === null || source === void 0 ? void 0 : source.archiveUrl) ||
|
|
52967
|
+
!Number.isSafeInteger(source.archiveSize) ||
|
|
52968
|
+
source.archiveSize <= 0 ||
|
|
52969
|
+
source.archiveSize > PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES ||
|
|
52970
|
+
!expectedSha256 ||
|
|
52971
|
+
!/^[0-9a-f]{64}$/u.test(expectedSha256)) {
|
|
52972
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 resource archive integrity metadata is invalid', { firmwareUpdateCode: 'FirmwarePlanInvalid' });
|
|
52973
|
+
}
|
|
52974
|
+
const { binary } = yield getSysResourceBinary(source.archiveUrl);
|
|
52975
|
+
if (binary.byteLength !== source.archiveSize ||
|
|
52976
|
+
bytesToHex(sha256.sha256(new Uint8Array(binary))) !== expectedSha256) {
|
|
52977
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 resource archive does not match the remote config', { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' });
|
|
52978
|
+
}
|
|
52979
|
+
return binary;
|
|
52980
|
+
});
|
|
52981
|
+
}
|
|
52927
52982
|
prepareRemoteProtocolV2Binaries(firmwareType, features, explicitInstallItems = []) {
|
|
52928
52983
|
var _a, _b;
|
|
52929
52984
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -53143,7 +53198,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53143
53198
|
timeoutMs: this.getProtocolV2DeviceInfoTimeout(),
|
|
53144
53199
|
});
|
|
53145
53200
|
this.assertProtocolV2DeviceInfoIdentity(deviceInfo);
|
|
53146
|
-
const features = yield this.device.probeProtocolV2RuntimeState(deviceInfo, PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT
|
|
53201
|
+
const features = yield this.device.probeProtocolV2RuntimeState(deviceInfo, PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT);
|
|
53147
53202
|
if ((features === null || features === void 0 ? void 0 : features.mode) === 'bootloader') {
|
|
53148
53203
|
return features;
|
|
53149
53204
|
}
|
|
@@ -53180,81 +53235,18 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53180
53235
|
push(this.params.se04Binary, 'se04.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04);
|
|
53181
53236
|
return entries;
|
|
53182
53237
|
}
|
|
53183
|
-
|
|
53184
|
-
const phases = [];
|
|
53185
|
-
const bootResourceSources = resourceSources.filter(source => isProtocolV2BootResourcePackagePath(source.devicePath));
|
|
53186
|
-
const remainingResourceSources = resourceSources.filter(source => !isProtocolV2BootResourcePackagePath(source.devicePath));
|
|
53187
|
-
if (bootResourceSources.length > 0) {
|
|
53188
|
-
phases.push({
|
|
53189
|
-
kind: 'resource-sync',
|
|
53190
|
-
installSources: [],
|
|
53191
|
-
resourceSources: bootResourceSources,
|
|
53192
|
-
});
|
|
53193
|
-
}
|
|
53194
|
-
const bootloaderSources = installSources.filter(source => source.kind === 'bootloader');
|
|
53195
|
-
if (bootloaderSources.length > 0) {
|
|
53196
|
-
phases.push({
|
|
53197
|
-
kind: 'bootloader-install',
|
|
53198
|
-
installSources: bootloaderSources,
|
|
53199
|
-
resourceSources: [],
|
|
53200
|
-
}, {
|
|
53201
|
-
kind: 'bootloader-verify',
|
|
53202
|
-
installSources: [],
|
|
53203
|
-
resourceSources: [],
|
|
53204
|
-
});
|
|
53205
|
-
}
|
|
53206
|
-
if (remainingResourceSources.length > 0) {
|
|
53207
|
-
phases.push({
|
|
53208
|
-
kind: 'resource-sync',
|
|
53209
|
-
installSources: [],
|
|
53210
|
-
resourceSources: remainingResourceSources,
|
|
53211
|
-
});
|
|
53212
|
-
}
|
|
53213
|
-
const componentSources = installSources.filter(source => source.kind !== 'bootloader');
|
|
53214
|
-
if (componentSources.length > 0) {
|
|
53215
|
-
phases.push({
|
|
53216
|
-
kind: 'component-install',
|
|
53217
|
-
installSources: componentSources,
|
|
53218
|
-
resourceSources: [],
|
|
53219
|
-
});
|
|
53220
|
-
}
|
|
53221
|
-
phases.push({
|
|
53222
|
-
kind: 'final-verify',
|
|
53223
|
-
installSources: [],
|
|
53224
|
-
resourceSources: [],
|
|
53225
|
-
});
|
|
53226
|
-
return phases;
|
|
53227
|
-
}
|
|
53228
|
-
executeProtocolV2Phases({ installSources, resourceSources, }) {
|
|
53238
|
+
executeProtocolV2SourceUpdate({ installSources, resourceSources, }) {
|
|
53229
53239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53230
53240
|
this.protocolV2BootResourceStagingSafe = false;
|
|
53231
|
-
|
|
53232
|
-
|
|
53233
|
-
|
|
53234
|
-
|
|
53235
|
-
|
|
53236
|
-
|
|
53237
|
-
|
|
53238
|
-
}
|
|
53239
|
-
if (phase.kind === 'resource-sync') {
|
|
53240
|
-
yield this.enterProtocolV2BootloaderMode();
|
|
53241
|
-
if (!phase.resourceSources.some(source => isProtocolV2BootResourcePackagePath(source.devicePath))) {
|
|
53242
|
-
yield this.ensureProtocolV2BootResourceStagingIsEmpty();
|
|
53243
|
-
}
|
|
53244
|
-
yield this.executeProtocolV2TransferPhase(phase);
|
|
53245
|
-
}
|
|
53246
|
-
else if (phase.kind === 'bootloader-install' || phase.kind === 'component-install') {
|
|
53247
|
-
yield this.enterProtocolV2BootloaderMode();
|
|
53248
|
-
yield this.ensureProtocolV2BootResourceStagingIsEmpty();
|
|
53249
|
-
yield this.executeProtocolV2TransferPhase(phase);
|
|
53250
|
-
yield this.exitProtocolV2BootloaderToNormal();
|
|
53251
|
-
}
|
|
53252
|
-
else if (phase.kind === 'bootloader-verify') {
|
|
53253
|
-
yield this.waitForProtocolV2FinalFeatures();
|
|
53254
|
-
this.assertExpectedProtocolV2Versions(['boot']);
|
|
53255
|
-
}
|
|
53241
|
+
if (installSources.length > 0 || resourceSources.length > 0) {
|
|
53242
|
+
yield this.enterProtocolV2BootloaderMode();
|
|
53243
|
+
yield this.ensureProtocolV2BootResourceStagingIsEmpty();
|
|
53244
|
+
yield this.executeProtocolV2TransferPhase({
|
|
53245
|
+
installSources,
|
|
53246
|
+
resourceSources,
|
|
53247
|
+
});
|
|
53256
53248
|
}
|
|
53257
|
-
|
|
53249
|
+
return this.completeProtocolV2FinalVerification();
|
|
53258
53250
|
});
|
|
53259
53251
|
}
|
|
53260
53252
|
ensureProtocolV2BootResourceStagingIsEmpty() {
|
|
@@ -53282,14 +53274,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53282
53274
|
this.protocolV2BootResourceStagingSafe = true;
|
|
53283
53275
|
});
|
|
53284
53276
|
}
|
|
53285
|
-
executeProtocolV2SourceUpdate({ installSources, resourceSources, }) {
|
|
53286
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53287
|
-
return this.executeProtocolV2Phases({
|
|
53288
|
-
installSources,
|
|
53289
|
-
resourceSources,
|
|
53290
|
-
});
|
|
53291
|
-
});
|
|
53292
|
-
}
|
|
53293
53277
|
executeProtocolV2Update({ fwBinaryMap, bootloaderBinary, installItems, }) {
|
|
53294
53278
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53295
53279
|
const memoryInstallItems = installItems !== null && installItems !== void 0 ? installItems : this.buildProtocolV2InstallItems({
|
|
@@ -53305,7 +53289,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53305
53289
|
kind: item.kind,
|
|
53306
53290
|
});
|
|
53307
53291
|
})));
|
|
53308
|
-
return yield this.
|
|
53292
|
+
return yield this.executeProtocolV2SourceUpdate({
|
|
53309
53293
|
installSources,
|
|
53310
53294
|
resourceSources: [],
|
|
53311
53295
|
});
|
|
@@ -53506,6 +53490,37 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53506
53490
|
});
|
|
53507
53491
|
return Array.from(expectedTargetIds).filter(targetId => !reportedTargetIds.has(targetId));
|
|
53508
53492
|
}
|
|
53493
|
+
getProtocolV2ObservableTargetVersions(features) {
|
|
53494
|
+
const versions = new Map();
|
|
53495
|
+
versions.set(ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER, getDeviceBootloaderVersion(features).join('.'));
|
|
53496
|
+
const applicationVersion = getDeviceFirmwareVersion(features).join('.');
|
|
53497
|
+
versions.set(ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1, applicationVersion);
|
|
53498
|
+
versions.set(ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P2, applicationVersion);
|
|
53499
|
+
versions.set(ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR, getDeviceBLEFirmwareVersion(features).join('.'));
|
|
53500
|
+
const secureElementVersions = [
|
|
53501
|
+
[ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE01, features.se01Version],
|
|
53502
|
+
[ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE02, features.se02Version],
|
|
53503
|
+
[ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE03, features.se03Version],
|
|
53504
|
+
[ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04, features.se04Version],
|
|
53505
|
+
];
|
|
53506
|
+
secureElementVersions.forEach(([targetId, version]) => {
|
|
53507
|
+
if (version)
|
|
53508
|
+
versions.set(targetId, version);
|
|
53509
|
+
});
|
|
53510
|
+
return versions;
|
|
53511
|
+
}
|
|
53512
|
+
hasProtocolV2InstallVersionChanged(expectedTargetIds) {
|
|
53513
|
+
if (!this.protocolV2LastRuntimeProbeFeatures)
|
|
53514
|
+
return false;
|
|
53515
|
+
const currentVersions = this.getProtocolV2ObservableTargetVersions(this.protocolV2LastRuntimeProbeFeatures);
|
|
53516
|
+
return Array.from(expectedTargetIds).some(targetId => {
|
|
53517
|
+
const previousVersion = this.protocolV2InstallBaselineVersions.get(targetId);
|
|
53518
|
+
const currentVersion = currentVersions.get(targetId);
|
|
53519
|
+
return (previousVersion !== undefined &&
|
|
53520
|
+
currentVersion !== undefined &&
|
|
53521
|
+
previousVersion !== currentVersion);
|
|
53522
|
+
});
|
|
53523
|
+
}
|
|
53509
53524
|
waitForProtocolV2FirmwareUpdateComplete(targets) {
|
|
53510
53525
|
var _a, _b;
|
|
53511
53526
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -53518,11 +53533,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53518
53533
|
let deviceInfo;
|
|
53519
53534
|
let missingTargetStatusSince;
|
|
53520
53535
|
let missingTargetStatusKey;
|
|
53536
|
+
let normalModeWithoutInstallEvidenceSince;
|
|
53537
|
+
let installEvidenceObserved = this.protocolV2InstallAckReceived;
|
|
53521
53538
|
const resetMissingTargetStatusGrace = () => {
|
|
53522
53539
|
missingTargetStatusSince = undefined;
|
|
53523
53540
|
missingTargetStatusKey = undefined;
|
|
53524
53541
|
};
|
|
53525
53542
|
while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
|
|
53543
|
+
this.throwIfAborted();
|
|
53526
53544
|
try {
|
|
53527
53545
|
if (shouldReconnect) {
|
|
53528
53546
|
yield this.reconnectProtocolV2Device();
|
|
@@ -53539,16 +53557,26 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53539
53557
|
},
|
|
53540
53558
|
}, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
|
|
53541
53559
|
const statusTargets = ((_a = statusResponse.message.records) !== null && _a !== void 0 ? _a : []);
|
|
53560
|
+
if (statusTargets.some(target => {
|
|
53561
|
+
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53562
|
+
return targetId !== undefined && expectedTargetIds.has(targetId);
|
|
53563
|
+
})) {
|
|
53564
|
+
installEvidenceObserved = true;
|
|
53565
|
+
normalModeWithoutInstallEvidenceSince = undefined;
|
|
53566
|
+
}
|
|
53542
53567
|
if (this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths)) {
|
|
53543
53568
|
this.protocolV2FinalStatusVerified = true;
|
|
53544
53569
|
return;
|
|
53545
53570
|
}
|
|
53546
|
-
if (statusTargets.length === 0 &&
|
|
53547
|
-
currentDeviceInfo
|
|
53548
|
-
|
|
53549
|
-
|
|
53550
|
-
|
|
53551
|
-
|
|
53571
|
+
if (statusTargets.length === 0 && currentDeviceInfo) {
|
|
53572
|
+
const isNormalMode = yield this.probeProtocolV2NormalMode(currentDeviceInfo);
|
|
53573
|
+
if (isNormalMode &&
|
|
53574
|
+
(installEvidenceObserved ||
|
|
53575
|
+
this.hasProtocolV2InstallVersionChanged(expectedTargetIds))) {
|
|
53576
|
+
Log$6.log('[FirmwareUpdateV4] empty firmware status after confirmed App reboot; update complete');
|
|
53577
|
+
this.postProgressMessage(100, 'installingFirmware');
|
|
53578
|
+
return;
|
|
53579
|
+
}
|
|
53552
53580
|
}
|
|
53553
53581
|
const missingTargetIds = this.getProtocolV2MissingTargetIds(statusTargets, expectedTargetIds);
|
|
53554
53582
|
if (missingTargetIds.length > 0) {
|
|
@@ -53581,12 +53609,27 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53581
53609
|
if (!currentDeviceInfo) {
|
|
53582
53610
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device identity is unavailable during install polling');
|
|
53583
53611
|
}
|
|
53584
|
-
|
|
53612
|
+
const isNormalMode = yield this.probeProtocolV2NormalMode(currentDeviceInfo);
|
|
53613
|
+
if (isNormalMode &&
|
|
53614
|
+
(installEvidenceObserved ||
|
|
53615
|
+
this.hasProtocolV2InstallVersionChanged(expectedTargetIds))) {
|
|
53585
53616
|
Log$6.log('[FirmwareUpdateV4] firmware status endpoint unavailable after confirmed App reboot');
|
|
53586
53617
|
this.postProgressMessage(100, 'installingFirmware');
|
|
53587
53618
|
return;
|
|
53588
53619
|
}
|
|
53589
|
-
|
|
53620
|
+
if (isNormalMode) {
|
|
53621
|
+
const now = Date.now();
|
|
53622
|
+
normalModeWithoutInstallEvidenceSince !== null && normalModeWithoutInstallEvidenceSince !== void 0 ? normalModeWithoutInstallEvidenceSince : (normalModeWithoutInstallEvidenceSince = now);
|
|
53623
|
+
if (now - normalModeWithoutInstallEvidenceSince >=
|
|
53624
|
+
PROTOCOL_V2_MISSING_TARGET_STATUS_GRACE_TIMEOUT) {
|
|
53625
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, 'Protocol V2 device returned to normal mode without install ACK, target status, or version change');
|
|
53626
|
+
}
|
|
53627
|
+
lastError = new Error('Protocol V2 device is in normal mode but installation is not yet confirmed');
|
|
53628
|
+
}
|
|
53629
|
+
else {
|
|
53630
|
+
normalModeWithoutInstallEvidenceSince = undefined;
|
|
53631
|
+
lastError = new Error('Protocol V2 firmware status endpoint is unavailable while the device remains in loader mode');
|
|
53632
|
+
}
|
|
53590
53633
|
}
|
|
53591
53634
|
else {
|
|
53592
53635
|
shouldReconnect = true;
|
|
@@ -53637,7 +53680,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53637
53680
|
}
|
|
53638
53681
|
probeProtocolV2NormalMode(deviceInfo) {
|
|
53639
53682
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53640
|
-
const features = yield this.device.probeProtocolV2RuntimeState(deviceInfo, PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT
|
|
53683
|
+
const features = yield this.device.probeProtocolV2RuntimeState(deviceInfo, PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT);
|
|
53684
|
+
this.protocolV2LastRuntimeProbeFeatures = features;
|
|
53641
53685
|
return features.mode === 'normal' && !features.bootloaderMode;
|
|
53642
53686
|
});
|
|
53643
53687
|
}
|
|
@@ -53690,7 +53734,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53690
53734
|
request: PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
|
|
53691
53735
|
});
|
|
53692
53736
|
this.assertProtocolV2DeviceInfoIdentity(deviceInfo);
|
|
53693
|
-
const features = yield this.device.probeProtocolV2RuntimeState(deviceInfo, PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT
|
|
53737
|
+
const features = yield this.device.probeProtocolV2RuntimeState(deviceInfo, PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT);
|
|
53694
53738
|
if (features.mode === 'normal' && !features.bootloaderMode) {
|
|
53695
53739
|
return features;
|
|
53696
53740
|
}
|
|
@@ -53816,22 +53860,41 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53816
53860
|
}
|
|
53817
53861
|
protocolV2StartFirmwareUpdate({ targets, }) {
|
|
53818
53862
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53863
|
+
this.protocolV2InstallAckReceived = false;
|
|
53864
|
+
this.protocolV2LastRuntimeProbeFeatures = undefined;
|
|
53819
53865
|
const startUpdate = () => this.device
|
|
53820
53866
|
.getCommands()
|
|
53821
53867
|
.typedCall('DeviceFirmwareUpdateRequest', 'Success', { targets }, { timeoutMs: PROTOCOL_V2_START_UPDATE_TIMEOUT });
|
|
53822
53868
|
let response;
|
|
53823
53869
|
try {
|
|
53824
53870
|
response = yield startUpdate();
|
|
53871
|
+
this.protocolV2InstallAckReceived = true;
|
|
53825
53872
|
}
|
|
53826
53873
|
catch (error) {
|
|
53827
|
-
if (
|
|
53828
|
-
|
|
53874
|
+
if (this.isBleReconnect() && isProtocolV2BleTransportReleasedError(error)) {
|
|
53875
|
+
this.throwIfAborted();
|
|
53876
|
+
Log$6.log('[FirmwareUpdateV4] install request interrupted by device reboot; continue status polling: ', error);
|
|
53877
|
+
}
|
|
53878
|
+
else if (this.protocolV2LegacyDirectUpdate &&
|
|
53879
|
+
isProtocolV2FirmwareUpdateEndpointUnavailable(error)) {
|
|
53880
|
+
this.protocolV2LegacyDirectUpdate = false;
|
|
53881
|
+
Log$6.debug('[FirmwareUpdateV4] legacy App does not expose DeviceFirmwareUpdateRequest; rebooting to bootloader');
|
|
53882
|
+
yield this.rebootProtocolV2ToBootloader();
|
|
53883
|
+
try {
|
|
53884
|
+
response = yield startUpdate();
|
|
53885
|
+
this.protocolV2InstallAckReceived = true;
|
|
53886
|
+
}
|
|
53887
|
+
catch (retryError) {
|
|
53888
|
+
if (!(this.isBleReconnect() && isProtocolV2BleTransportReleasedError(retryError))) {
|
|
53889
|
+
throw retryError;
|
|
53890
|
+
}
|
|
53891
|
+
this.throwIfAborted();
|
|
53892
|
+
Log$6.log('[FirmwareUpdateV4] install request interrupted after legacy reboot; continue status polling: ', retryError);
|
|
53893
|
+
}
|
|
53894
|
+
}
|
|
53895
|
+
else {
|
|
53829
53896
|
throw error;
|
|
53830
53897
|
}
|
|
53831
|
-
this.protocolV2LegacyDirectUpdate = false;
|
|
53832
|
-
Log$6.debug('[FirmwareUpdateV4] legacy App does not expose DeviceFirmwareUpdateRequest; rebooting to bootloader');
|
|
53833
|
-
yield this.rebootProtocolV2ToBootloader();
|
|
53834
|
-
response = yield startUpdate();
|
|
53835
53898
|
}
|
|
53836
53899
|
this.protocolV2LegacyDirectUpdate = false;
|
|
53837
53900
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FirmwareUpdating);
|
|
@@ -64919,10 +64982,6 @@ const createUiProgressMessageFilter = (intervalMs = DEFAULT_UI_PROGRESS_INTERVAL
|
|
|
64919
64982
|
};
|
|
64920
64983
|
};
|
|
64921
64984
|
|
|
64922
|
-
const isLegacyProtocolV2FirmwareRecoveryMethod = (method) => (method === null || method === void 0 ? void 0 : method.name) === 'firmwareUpdateV4' ||
|
|
64923
|
-
(method === null || method === void 0 ? void 0 : method.name) === 'checkAllFirmwareRelease' ||
|
|
64924
|
-
((method === null || method === void 0 ? void 0 : method.name) === 'getDeviceState' && method.payload.scope === 'firmware');
|
|
64925
|
-
|
|
64926
64985
|
const Log = getLogger(exports.LoggerNames.Core);
|
|
64927
64986
|
const PRE_INITIALIZE_TTL_MS = 60 * 1000;
|
|
64928
64987
|
const preWarmInflight = new Map();
|
|
@@ -64937,9 +64996,15 @@ function hasDeriveCardano(method) {
|
|
|
64937
64996
|
}
|
|
64938
64997
|
return method.name.startsWith('cardano') || ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.deriveCardano);
|
|
64939
64998
|
}
|
|
64940
|
-
const parseInitOptions = (method) => (
|
|
64941
|
-
?
|
|
64942
|
-
:
|
|
64999
|
+
const parseInitOptions = (method) => ({
|
|
65000
|
+
initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
|
|
65001
|
+
passphraseState: (method === null || method === void 0 ? void 0 : method.payload.useEmptyPassphrase) ? undefined : method === null || method === void 0 ? void 0 : method.payload.passphraseState,
|
|
65002
|
+
deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId,
|
|
65003
|
+
deriveCardano: method && hasDeriveCardano(method),
|
|
65004
|
+
connectProtocol: method === null || method === void 0 ? void 0 : method.payload.connectProtocol,
|
|
65005
|
+
forceProtocolDetection: method === null || method === void 0 ? void 0 : method.payload.forceProtocolDetection,
|
|
65006
|
+
protocolV2DeviceInfoTimeoutMs: method === null || method === void 0 ? void 0 : method.payload.protocolV2DeviceInfoTimeoutMs,
|
|
65007
|
+
});
|
|
64943
65008
|
let _core;
|
|
64944
65009
|
let _deviceList;
|
|
64945
65010
|
let _connector;
|
|
@@ -64963,6 +65028,7 @@ const toError = (error) => {
|
|
|
64963
65028
|
return new Error(String(error));
|
|
64964
65029
|
}
|
|
64965
65030
|
};
|
|
65031
|
+
const isExpectedCompatibilityError = (error) => error instanceof hdShared.HardwareError && error.errorCode === hdShared.HardwareErrorCode.DeviceNotSupportMethod;
|
|
64966
65032
|
const updateMethodRequestContext = (method, updates) => {
|
|
64967
65033
|
if (method.requestContext) {
|
|
64968
65034
|
updateRequestContext(method.requestContext.responseID, updates);
|
|
@@ -65336,7 +65402,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65336
65402
|
return yield task.callPromise.promise;
|
|
65337
65403
|
}
|
|
65338
65404
|
catch (e) {
|
|
65339
|
-
|
|
65405
|
+
if (!isExpectedCompatibilityError(e)) {
|
|
65406
|
+
Log.debug('Device Run Error: ', e);
|
|
65407
|
+
}
|
|
65340
65408
|
completeMethodRequestContext(method, e);
|
|
65341
65409
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
65342
65410
|
}
|
|
@@ -65765,7 +65833,6 @@ const cleanup = () => {
|
|
|
65765
65833
|
const pendingUiPromises = _uiPromises;
|
|
65766
65834
|
_uiPromises = [];
|
|
65767
65835
|
rejectUiPromises(pendingUiPromises, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ActionCancelled, 'UI request was cancelled'));
|
|
65768
|
-
Log.debug('Cleanup...');
|
|
65769
65836
|
};
|
|
65770
65837
|
const removeDeviceListener = (device) => {
|
|
65771
65838
|
device.removeAllListeners();
|