@onekeyfe/hd-core 1.2.0-alpha.106 → 1.2.0-alpha.107
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 +28 -100
- package/__tests__/device-lifecycle-events.test.ts +2 -113
- package/__tests__/device-pool-state.test.ts +0 -25
- package/__tests__/deviceSettings.test.ts +1 -0
- package/__tests__/deviceUploadNft.test.ts +4 -33
- package/__tests__/get-device-state.test.ts +13 -52
- package/__tests__/logBlockEvent.test.ts +1 -13
- package/__tests__/protocol-v2.test.ts +121 -758
- package/__tests__/refresh-device-state.test.ts +1 -3
- package/__tests__/search-devices.test.ts +38 -32
- package/dist/api/FirmwareUpdateV4.d.ts +3 -10
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +1 -1
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +3 -2
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +3 -2
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +2 -7
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +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 +16 -12
- package/dist/index.js +201 -446
- package/dist/protocols/protocol-v2/features.d.ts +1 -9
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +2 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +1 -1
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/pro2Nft.d.ts +0 -7
- package/dist/utils/pro2Nft.d.ts.map +1 -1
- package/package.json +4 -6
- package/src/api/FirmwareUpdateV4.ts +174 -312
- package/src/api/SearchDevices.ts +2 -2
- package/src/api/UploadPortfolio.ts +2 -9
- package/src/api/protocol-v2/DeviceUploadNft.ts +8 -56
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +18 -37
- package/src/api/ton/TonSignMessage.ts +3 -5
- package/src/core/index.ts +2 -6
- package/src/device/Device.ts +31 -53
- package/src/device/DeviceCommands.ts +14 -4
- package/src/device/DevicePool.ts +2 -6
- package/src/events/logBlockEvent.ts +1 -14
- package/src/protocols/protocol-v2/features.ts +2 -19
- package/src/protocols/protocol-v2/index.ts +0 -2
- package/src/types/api/protocolV2.ts +1 -1
- package/src/types/device.ts +2 -1
- package/src/utils/deviceSettings.ts +1 -1
- package/src/utils/pro2Nft.ts +8 -31
- package/__tests__/base64Data.test.ts +0 -70
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +0 -145
- package/__tests__/resourceBase64Boundary.test.ts +0 -48
- package/__tests__/ton-sign-message.test.ts +0 -84
- package/dist/api/helpers/base64Data.d.ts +0 -16
- package/dist/api/helpers/base64Data.d.ts.map +0 -1
- package/src/api/helpers/base64Data.ts +0 -85
package/dist/index.js
CHANGED
|
@@ -13,10 +13,9 @@ var ByteBuffer = require('bytebuffer');
|
|
|
13
13
|
var blake2s = require('@noble/hashes/blake2s');
|
|
14
14
|
var BigNumber = require('bignumber.js');
|
|
15
15
|
var JSZip = require('jszip');
|
|
16
|
-
var buffer = require('buffer');
|
|
17
|
-
var jpegJs = require('jpeg-js');
|
|
18
16
|
var sha3 = require('@noble/hashes/sha3');
|
|
19
17
|
var blake2b = require('@noble/hashes/blake2b');
|
|
18
|
+
var buffer = require('buffer');
|
|
20
19
|
|
|
21
20
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
21
|
|
|
@@ -41475,11 +41474,6 @@ const LogLabelMethod = new Set([
|
|
|
41475
41474
|
'fileWrite',
|
|
41476
41475
|
'fileRead',
|
|
41477
41476
|
]);
|
|
41478
|
-
const LogPayloadBlockMethod = new Set([
|
|
41479
|
-
'deviceUploadNft',
|
|
41480
|
-
'deviceUploadWallpaper',
|
|
41481
|
-
'uploadPortfolio',
|
|
41482
|
-
]);
|
|
41483
41477
|
const SensitiveLogKeys = new Set([
|
|
41484
41478
|
'devicestate',
|
|
41485
41479
|
'entropy',
|
|
@@ -41536,10 +41530,7 @@ function getLogBlockLabel(message) {
|
|
|
41536
41530
|
return undefined;
|
|
41537
41531
|
}
|
|
41538
41532
|
function getSafeLogPayload(value, blockLabel) {
|
|
41539
|
-
if (blockLabel &&
|
|
41540
|
-
(LogBlockEvent.has(blockLabel) ||
|
|
41541
|
-
LogPayloadBlockMethod.has(blockLabel) ||
|
|
41542
|
-
isSigningMethod(blockLabel))) {
|
|
41533
|
+
if (blockLabel && (LogBlockEvent.has(blockLabel) || isSigningMethod(blockLabel))) {
|
|
41543
41534
|
return { method: blockLabel, payload: '[REDACTED]' };
|
|
41544
41535
|
}
|
|
41545
41536
|
const redactedValue = redactLogValue(value, new WeakSet());
|
|
@@ -42473,7 +42464,7 @@ const getAutoShutDownOptions = (deviceType, protocol) => {
|
|
|
42473
42464
|
return withNever([60000, 120000, 300000, 600000], protocol);
|
|
42474
42465
|
case hdShared.EDeviceType.Pro2:
|
|
42475
42466
|
case hdShared.EDeviceType.Neo:
|
|
42476
|
-
return withNever([60000, 120000, 300000, 600000], protocol);
|
|
42467
|
+
return withNever([60000, 120000, 300000, 600000, 1800000], protocol);
|
|
42477
42468
|
default:
|
|
42478
42469
|
return [];
|
|
42479
42470
|
}
|
|
@@ -42732,14 +42723,18 @@ function getCompletePro2NftBasenames(childFiles) {
|
|
|
42732
42723
|
function utf8Length(value) {
|
|
42733
42724
|
return new TextEncoder().encode(value).byteLength;
|
|
42734
42725
|
}
|
|
42735
|
-
function
|
|
42736
|
-
|
|
42737
|
-
|
|
42738
|
-
throw invalidParameter$1('Parameter [image] must contain encoded NFT image data.');
|
|
42726
|
+
function assertImage(name, image, expectedWidth, expectedHeight) {
|
|
42727
|
+
if (image.width !== expectedWidth || image.height !== expectedHeight) {
|
|
42728
|
+
throw invalidParameter$1(`Pro2 NFT ${name} dimensions must be ${expectedWidth}x${expectedHeight}.`);
|
|
42739
42729
|
}
|
|
42740
|
-
if (!(
|
|
42741
|
-
throw invalidParameter$1(
|
|
42730
|
+
if (!(image.rgba instanceof ArrayBuffer) && !ArrayBuffer.isView(image.rgba)) {
|
|
42731
|
+
throw invalidParameter$1(`Parameter [${name}.rgba] must be an ArrayBuffer or Uint8Array.`);
|
|
42742
42732
|
}
|
|
42733
|
+
}
|
|
42734
|
+
function buildPro2NftBundle(options) {
|
|
42735
|
+
const { image, thumbnail, title, subtitle, timestampMs } = options;
|
|
42736
|
+
assertImage('image', image, PRO2_NFT_IMAGE_WIDTH, PRO2_NFT_IMAGE_HEIGHT);
|
|
42737
|
+
assertImage('thumbnail', thumbnail, PRO2_NFT_THUMBNAIL_WIDTH, PRO2_NFT_THUMBNAIL_HEIGHT);
|
|
42743
42738
|
const titleLength = typeof title === 'string' ? utf8Length(title) : 0;
|
|
42744
42739
|
const subtitleLength = typeof subtitle === 'string' ? utf8Length(subtitle) : Number.POSITIVE_INFINITY;
|
|
42745
42740
|
if (titleLength < 1 || titleLength > 63) {
|
|
@@ -42751,15 +42746,17 @@ function buildPro2NftBundleFromEncodedImages(options) {
|
|
|
42751
42746
|
if (!Number.isSafeInteger(timestampMs) || timestampMs <= 0) {
|
|
42752
42747
|
throw invalidParameter$1('Parameter [timestampMs] must be a positive safe integer.');
|
|
42753
42748
|
}
|
|
42749
|
+
const encodedImage = encodePro2Image(Object.assign(Object.assign({}, image), { alphaMode: 'black-background' })).data;
|
|
42750
|
+
const encodedThumbnail = encodePro2Image(Object.assign(Object.assign({}, thumbnail), { alphaMode: 'black-background' })).data;
|
|
42754
42751
|
const metadata = new TextEncoder().encode(JSON.stringify({ title, subtitle }));
|
|
42755
42752
|
if (metadata.byteLength === 0 || metadata.byteLength > 512) {
|
|
42756
42753
|
throw invalidParameter$1('Pro2 NFT metadata must contain 1 to 512 UTF-8 bytes.');
|
|
42757
42754
|
}
|
|
42758
|
-
const hash8 = utils.bytesToHex(blake2s.blake2s(
|
|
42755
|
+
const hash8 = utils.bytesToHex(blake2s.blake2s(encodedImage)).slice(0, 8);
|
|
42759
42756
|
return {
|
|
42760
42757
|
basename: `nft-${hash8}-${timestampMs}`,
|
|
42761
|
-
image,
|
|
42762
|
-
thumbnail,
|
|
42758
|
+
image: encodedImage,
|
|
42759
|
+
thumbnail: encodedThumbnail,
|
|
42763
42760
|
metadata,
|
|
42764
42761
|
};
|
|
42765
42762
|
}
|
|
@@ -43279,13 +43276,9 @@ class DevicePool extends events.exports {
|
|
|
43279
43276
|
}
|
|
43280
43277
|
static _refreshProtocolV2DiscoveryState(device) {
|
|
43281
43278
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43282
|
-
yield device.getDeviceState({
|
|
43283
|
-
refreshSections: ['status'],
|
|
43284
|
-
});
|
|
43279
|
+
yield device.getDeviceState({ refreshSections: ['status'] });
|
|
43285
43280
|
try {
|
|
43286
|
-
yield device.getDeviceState({
|
|
43287
|
-
refreshSections: ['settings'],
|
|
43288
|
-
});
|
|
43281
|
+
yield device.getDeviceState({ refreshSections: ['settings'] });
|
|
43289
43282
|
}
|
|
43290
43283
|
catch (error) {
|
|
43291
43284
|
Log$j.debug('Unable to refresh Protocol V2 device label during discovery', error);
|
|
@@ -43727,6 +43720,9 @@ class DeviceCommands {
|
|
|
43727
43720
|
const promise = this.transport.call(this.mainId, type, msg !== null && msg !== void 0 ? msg : {}, options);
|
|
43728
43721
|
this.callPromise = promise;
|
|
43729
43722
|
const res = yield promise;
|
|
43723
|
+
if (!shouldReduceDebug) {
|
|
43724
|
+
LogCore.debug('[DeviceCommands] [call] Received', res.type, hdTransport.getSafeTransportLogPayload(res.message, res.type));
|
|
43725
|
+
}
|
|
43730
43726
|
return res;
|
|
43731
43727
|
}
|
|
43732
43728
|
catch (error) {
|
|
@@ -43819,10 +43815,12 @@ class DeviceCommands {
|
|
|
43819
43815
|
if (!shouldReduceDebugForCall(callType)) {
|
|
43820
43816
|
Log$h.debug('_filterCommonTypes: ', {
|
|
43821
43817
|
request: callType,
|
|
43822
|
-
response:
|
|
43823
|
-
|
|
43824
|
-
|
|
43825
|
-
|
|
43818
|
+
response: callType === 'DeviceFirmwareUpdateStatusGet'
|
|
43819
|
+
? {
|
|
43820
|
+
type: res.type,
|
|
43821
|
+
message: hdTransport.getSafeTransportLogPayload(res.message, res.type),
|
|
43822
|
+
}
|
|
43823
|
+
: res.type,
|
|
43826
43824
|
});
|
|
43827
43825
|
}
|
|
43828
43826
|
}
|
|
@@ -44228,7 +44226,6 @@ const getProtocolV2SeState = (se) => {
|
|
|
44228
44226
|
}
|
|
44229
44227
|
};
|
|
44230
44228
|
const getProtocolV2SeType = (se) => normalizeEnumValue(hdTransport.DeviceSeType, se === null || se === void 0 ? void 0 : se.type);
|
|
44231
|
-
const isLegacyProtocolV2ProtocolInfo = (protocolInfo) => Object.prototype.hasOwnProperty.call(protocolInfo, 'protobuf_definition');
|
|
44232
44229
|
const parseProtocolV2BuildFingerprint = (buildFingerprint) => {
|
|
44233
44230
|
if (!buildFingerprint)
|
|
44234
44231
|
return null;
|
|
@@ -44243,20 +44240,12 @@ const parseProtocolV2BuildFingerprint = (buildFingerprint) => {
|
|
|
44243
44240
|
}
|
|
44244
44241
|
return { binary, version, commit, environment, buildType };
|
|
44245
44242
|
};
|
|
44246
|
-
const getProtocolV2RuntimeMode = (protocolInfo
|
|
44247
|
-
var _a
|
|
44243
|
+
const getProtocolV2RuntimeMode = (protocolInfo) => {
|
|
44244
|
+
var _a;
|
|
44248
44245
|
const binary = (_a = parseProtocolV2BuildFingerprint(protocolInfo.build_fingerprint)) === null || _a === void 0 ? void 0 : _a.binary;
|
|
44249
44246
|
if (binary === 'application')
|
|
44250
44247
|
return 'normal';
|
|
44251
|
-
|
|
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;
|
|
44248
|
+
return binary;
|
|
44260
44249
|
};
|
|
44261
44250
|
const PROTOCOL_V2_DEVICE_STATUS_GET_MESSAGE_TYPE = 60602;
|
|
44262
44251
|
const supportsProtocolV2Message = (protocolInfo, messageType) => protocolInfo.supported_messages.includes(messageType);
|
|
@@ -45258,7 +45247,6 @@ class Device extends events.exports {
|
|
|
45258
45247
|
yield this.commands.dispose(false);
|
|
45259
45248
|
}
|
|
45260
45249
|
this.commands = new DeviceCommands(this, (_g = this.mainId) !== null && _g !== void 0 ? _g : '');
|
|
45261
|
-
this.invalidateProtocolV2RuntimeState();
|
|
45262
45250
|
}
|
|
45263
45251
|
catch (error) {
|
|
45264
45252
|
if (options === null || options === void 0 ? void 0 : options.forceProtocolDetection) {
|
|
@@ -45653,7 +45641,8 @@ class Device extends events.exports {
|
|
|
45653
45641
|
commands: this.commands,
|
|
45654
45642
|
timeoutMs: options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs,
|
|
45655
45643
|
});
|
|
45656
|
-
yield this.probeProtocolV2RuntimeState(deviceInfo, options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs);
|
|
45644
|
+
const features = yield this.probeProtocolV2RuntimeState(deviceInfo, options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs);
|
|
45645
|
+
Log$g.debug('Protocol V2 features:', features);
|
|
45657
45646
|
}
|
|
45658
45647
|
catch (error) {
|
|
45659
45648
|
Log$g.error('Protocol V2 initialization failed:', error);
|
|
@@ -45675,7 +45664,7 @@ class Device extends events.exports {
|
|
|
45675
45664
|
});
|
|
45676
45665
|
}
|
|
45677
45666
|
getDeviceState(params = {}) {
|
|
45678
|
-
var _a, _b, _c
|
|
45667
|
+
var _a, _b, _c;
|
|
45679
45668
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45680
45669
|
const refresh = new Set((_a = params.refreshSections) !== null && _a !== void 0 ? _a : []);
|
|
45681
45670
|
const getProtocolV2DeviceInfoRequest = () => {
|
|
@@ -45723,12 +45712,9 @@ class Device extends events.exports {
|
|
|
45723
45712
|
}
|
|
45724
45713
|
}
|
|
45725
45714
|
if (refresh.has('status') && !initializedWithDeviceInfo) {
|
|
45726
|
-
|
|
45727
|
-
yield this.probeProtocolV2RuntimeState(refreshedDeviceInfo, undefined, {
|
|
45728
|
-
forceRuntimeContextRefresh: cachedMode === 'bootloader' || cachedMode === 'romloader',
|
|
45729
|
-
});
|
|
45715
|
+
yield this.probeProtocolV2RuntimeState(refreshedDeviceInfo);
|
|
45730
45716
|
}
|
|
45731
|
-
if (refresh.has('settings') && ((
|
|
45717
|
+
if (refresh.has('settings') && ((_c = this.state) === null || _c === void 0 ? void 0 : _c.status.mode) === 'normal') {
|
|
45732
45718
|
const { message } = yield this.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
|
|
45733
45719
|
this.updateState(mapDeviceSettingsToState(message), 'settings-read');
|
|
45734
45720
|
}
|
|
@@ -45765,10 +45751,9 @@ class Device extends events.exports {
|
|
|
45765
45751
|
source,
|
|
45766
45752
|
changedKeys: result.changedKeys,
|
|
45767
45753
|
};
|
|
45768
|
-
Log$g.debug('Device state
|
|
45754
|
+
Log$g.debug('Device state patch committed', {
|
|
45769
45755
|
source,
|
|
45770
|
-
|
|
45771
|
-
changedKeyCount: result.changedKeys.length,
|
|
45756
|
+
keys: result.changedKeys,
|
|
45772
45757
|
});
|
|
45773
45758
|
this.emit(DEVICE.STATE, this, event);
|
|
45774
45759
|
if (result.state.protocol === 'V1') {
|
|
@@ -45787,14 +45772,12 @@ class Device extends events.exports {
|
|
|
45787
45772
|
this.updateState(mapFeaturesToState(normalized), source);
|
|
45788
45773
|
return this.features;
|
|
45789
45774
|
}
|
|
45790
|
-
ensureProtocolV2RuntimeContext(timeoutMs
|
|
45775
|
+
ensureProtocolV2RuntimeContext(timeoutMs) {
|
|
45791
45776
|
var _a, _b, _c, _d;
|
|
45792
45777
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45793
|
-
const cachedProtocolInfo = (
|
|
45794
|
-
? undefined
|
|
45795
|
-
:
|
|
45796
|
-
? (_d = (_c = (_b = this.state) === null || _b === void 0 ? void 0 : _b.raw) === null || _c === void 0 ? void 0 : _c.protocolV2ProtocolInfo) !== null && _d !== void 0 ? _d : undefined
|
|
45797
|
-
: undefined);
|
|
45778
|
+
const cachedProtocolInfo = (_a = this.protocolV2RuntimeContext) !== null && _a !== void 0 ? _a : (!this.protocolV2StateNeedsReload
|
|
45779
|
+
? (_d = (_c = (_b = this.state) === null || _b === void 0 ? void 0 : _b.raw) === null || _c === void 0 ? void 0 : _c.protocolV2ProtocolInfo) !== null && _d !== void 0 ? _d : undefined
|
|
45780
|
+
: undefined);
|
|
45798
45781
|
if (cachedProtocolInfo) {
|
|
45799
45782
|
this.protocolV2RuntimeContext = cachedProtocolInfo;
|
|
45800
45783
|
return cachedProtocolInfo;
|
|
@@ -45829,15 +45812,12 @@ class Device extends events.exports {
|
|
|
45829
45812
|
}
|
|
45830
45813
|
});
|
|
45831
45814
|
}
|
|
45832
|
-
probeProtocolV2RuntimeState(deviceInfo, timeoutMs
|
|
45815
|
+
probeProtocolV2RuntimeState(deviceInfo, timeoutMs) {
|
|
45833
45816
|
var _a, _b, _c;
|
|
45834
45817
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45835
|
-
const protocolInfo = yield this.ensureProtocolV2RuntimeContext(timeoutMs
|
|
45836
|
-
|
|
45837
|
-
});
|
|
45818
|
+
const protocolInfo = yield this.ensureProtocolV2RuntimeContext(timeoutMs);
|
|
45819
|
+
const runtimeMode = getProtocolV2RuntimeMode(protocolInfo);
|
|
45838
45820
|
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);
|
|
45841
45821
|
const protocolV2DeviceType = runtimeDeviceInfo
|
|
45842
45822
|
? resolveProtocolV2DeviceIdentity((_c = runtimeDeviceInfo.hw) === null || _c === void 0 ? void 0 : _c.Device_type).deviceType
|
|
45843
45823
|
: this.getCurrentDeviceType();
|
|
@@ -45846,8 +45826,7 @@ class Device extends events.exports {
|
|
|
45846
45826
|
protocolV2DeviceType !== hdShared.EDeviceType.Neo) {
|
|
45847
45827
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, 'Protocol V2 romloader mode is only supported for Pro2 and Neo.');
|
|
45848
45828
|
}
|
|
45849
|
-
const deviceStatusSupported =
|
|
45850
|
-
supportsProtocolV2Message(protocolInfo, PROTOCOL_V2_DEVICE_STATUS_GET_MESSAGE_TYPE);
|
|
45829
|
+
const deviceStatusSupported = supportsProtocolV2Message(protocolInfo, PROTOCOL_V2_DEVICE_STATUS_GET_MESSAGE_TYPE);
|
|
45851
45830
|
if (runtimeMode === 'bootloader' || runtimeMode === 'romloader') {
|
|
45852
45831
|
return this.updateProtocolV2Features(deviceInfo, null, runtimeMode, protocolInfo);
|
|
45853
45832
|
}
|
|
@@ -45895,7 +45874,8 @@ class Device extends events.exports {
|
|
|
45895
45874
|
const previousStatus = (_d = (_c = this.state) === null || _c === void 0 ? void 0 : _c.raw) === null || _d === void 0 ? void 0 : _d.protocolV2DeviceStatus;
|
|
45896
45875
|
return this.updateProtocolV2Features(previousDeviceInfo, Object.assign(Object.assign({}, previousStatus), status));
|
|
45897
45876
|
}
|
|
45898
|
-
|
|
45877
|
+
markTransportDisconnected() {
|
|
45878
|
+
this.deviceAcquired = false;
|
|
45899
45879
|
if (!this.isProtocolV2())
|
|
45900
45880
|
return;
|
|
45901
45881
|
this.protocolV2StateNeedsReload = true;
|
|
@@ -45904,10 +45884,6 @@ class Device extends events.exports {
|
|
|
45904
45884
|
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
45905
45885
|
this.clearPreInitialized();
|
|
45906
45886
|
}
|
|
45907
|
-
markTransportDisconnected() {
|
|
45908
|
-
this.deviceAcquired = false;
|
|
45909
|
-
this.invalidateProtocolV2RuntimeState();
|
|
45910
|
-
}
|
|
45911
45887
|
invalidateAfterWipe() {
|
|
45912
45888
|
const deviceId = this.getCurrentDeviceId();
|
|
45913
45889
|
if (deviceId) {
|
|
@@ -45917,7 +45893,10 @@ class Device extends events.exports {
|
|
|
45917
45893
|
if (this.originalDescriptor.path !== deviceId) {
|
|
45918
45894
|
deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
|
|
45919
45895
|
}
|
|
45920
|
-
this.
|
|
45896
|
+
this.protocolV2StateNeedsReload = true;
|
|
45897
|
+
this.protocolV2RuntimeContext = undefined;
|
|
45898
|
+
this.protocolV2RuntimeContextPromise = undefined;
|
|
45899
|
+
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
45921
45900
|
}
|
|
45922
45901
|
this.passphraseState = undefined;
|
|
45923
45902
|
this.stateStore = new DeviceStateStore();
|
|
@@ -45927,7 +45906,11 @@ class Device extends events.exports {
|
|
|
45927
45906
|
markProtocolV2Reboot(rebootType) {
|
|
45928
45907
|
if (!this.isProtocolV2())
|
|
45929
45908
|
return;
|
|
45930
|
-
this.
|
|
45909
|
+
this.protocolV2StateNeedsReload = true;
|
|
45910
|
+
this.protocolV2RuntimeContext = undefined;
|
|
45911
|
+
this.protocolV2RuntimeContextPromise = undefined;
|
|
45912
|
+
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
45913
|
+
this.clearPreInitialized();
|
|
45931
45914
|
let loaderMode;
|
|
45932
45915
|
if (rebootType === hdTransport.DeviceRebootType.Bootloader) {
|
|
45933
45916
|
loaderMode = 'bootloader';
|
|
@@ -45983,7 +45966,6 @@ class Device extends events.exports {
|
|
|
45983
45966
|
if (device.features) {
|
|
45984
45967
|
this._updateFeatures(device.features);
|
|
45985
45968
|
}
|
|
45986
|
-
this.invalidateProtocolV2RuntimeState();
|
|
45987
45969
|
}
|
|
45988
45970
|
run(fn, options) {
|
|
45989
45971
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -46838,7 +46820,7 @@ class SearchDevices extends BaseMethod {
|
|
|
46838
46820
|
if (!seenIds.has(lowerId)) {
|
|
46839
46821
|
seenIds.add(lowerId);
|
|
46840
46822
|
const bleName = (_e = (_d = device.name) !== null && _d !== void 0 ? _d : device.localName) !== null && _e !== void 0 ? _e : '';
|
|
46841
|
-
devices.push(Object.assign(Object.assign({}, device), { connectId: device.id, serialNo: null, uuid:
|
|
46823
|
+
devices.push(Object.assign(Object.assign({}, device), { connectId: device.id, serialNo: null, uuid: '', deviceId: null, name: bleName || device.name, deviceType: getDeviceTypeByBleName(bleName) }));
|
|
46842
46824
|
}
|
|
46843
46825
|
}
|
|
46844
46826
|
return devices;
|
|
@@ -51831,26 +51813,12 @@ const isProtocolV2ReconnectProbeError = (error) => {
|
|
|
51831
51813
|
return ((message.includes('device protocol mismatch') && message.includes('expected v2')) ||
|
|
51832
51814
|
message.includes('did not respond to expected protocol'));
|
|
51833
51815
|
};
|
|
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
|
-
};
|
|
51844
51816
|
const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
|
|
51845
51817
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51846
51818
|
return (message.includes('handler not registered') ||
|
|
51847
51819
|
message.includes('message handler not found') ||
|
|
51848
51820
|
message.includes('unsupported message'));
|
|
51849
51821
|
};
|
|
51850
|
-
const isProtocolV2FirmwareUpdateEndpointUnavailable = (error) => {
|
|
51851
|
-
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51852
|
-
return (message.includes('handler not registered') || message.includes('message handler not found'));
|
|
51853
|
-
};
|
|
51854
51822
|
const isProtocolV2TerminalInstallStatusError = (error) => {
|
|
51855
51823
|
var _a;
|
|
51856
51824
|
return error instanceof hdShared.HardwareError &&
|
|
@@ -51983,12 +51951,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
51983
51951
|
this.protocolV2HasExplicitTargetSelection = false;
|
|
51984
51952
|
this.protocolV2PreparedSources = [];
|
|
51985
51953
|
this.protocolV2ExecutionInLoader = false;
|
|
51986
|
-
this.protocolV2LegacyDirectUpdate = false;
|
|
51987
51954
|
this.protocolV2BootResourceStagingSafe = false;
|
|
51988
51955
|
this.protocolV2CompletedTargetVersions = new Map();
|
|
51989
51956
|
this.protocolV2FinalStatusVerified = false;
|
|
51990
|
-
this.protocolV2InstallAckReceived = false;
|
|
51991
|
-
this.protocolV2InstallBaselineVersions = new Map();
|
|
51992
51957
|
}
|
|
51993
51958
|
getSupportedProtocols() {
|
|
51994
51959
|
return ['V2'];
|
|
@@ -52166,9 +52131,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52166
52131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52167
52132
|
yield this.captureProtocolV2PhysicalIdentity();
|
|
52168
52133
|
const deviceFeatures = yield this.getProtocolV2DeviceFeatures();
|
|
52169
|
-
this.protocolV2InstallBaselineVersions =
|
|
52170
|
-
this.getProtocolV2ObservableTargetVersions(deviceFeatures);
|
|
52171
|
-
this.protocolV2LastRuntimeProbeFeatures = undefined;
|
|
52172
52134
|
const currentDeviceType = this.device.getCurrentDeviceType();
|
|
52173
52135
|
const capabilityDeviceType = currentDeviceType === hdShared.EDeviceType.Pro2 || currentDeviceType === hdShared.EDeviceType.Neo
|
|
52174
52136
|
? currentDeviceType
|
|
@@ -52177,10 +52139,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52177
52139
|
const deviceFirmwareType = getFirmwareType(deviceFeatures);
|
|
52178
52140
|
const firmwareType = (_a = this.params.firmwareType) !== null && _a !== void 0 ? _a : deviceFirmwareType;
|
|
52179
52141
|
this.validateExpectedTargetVersions();
|
|
52180
|
-
const wantsResources = !!((_b = this.params.targetsToUpdate) === null || _b === void 0 ? void 0 : _b.includes('resource'));
|
|
52181
52142
|
if (!this.params.preparedPlan &&
|
|
52182
52143
|
this.params.resourceArchiveBinary &&
|
|
52183
|
-
((
|
|
52144
|
+
((_b = this.params.targetsToUpdate) === null || _b === void 0 ? void 0 : _b.includes('resource'))) {
|
|
52184
52145
|
const localMemoryHost = yield this.prepareProtocolV2LocalMemoryHost({
|
|
52185
52146
|
features: deviceFeatures,
|
|
52186
52147
|
firmwareType,
|
|
@@ -52192,14 +52153,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52192
52153
|
localMemoryHost.release();
|
|
52193
52154
|
}
|
|
52194
52155
|
}
|
|
52195
|
-
const hasPreparedComponentArtifacts = Object.values((
|
|
52156
|
+
const hasPreparedComponentArtifacts = Object.values((_c = this.params.componentArtifacts) !== null && _c !== void 0 ? _c : {}).some(Boolean);
|
|
52196
52157
|
if (this.params.preparedPlan || hasPreparedComponentArtifacts) {
|
|
52197
52158
|
return this.runProtocolV2PreparedArtifacts(deviceFeatures, firmwareType);
|
|
52198
52159
|
}
|
|
52160
|
+
const wantsResources = !!((_d = this.params.targetsToUpdate) === null || _d === void 0 ? void 0 : _d.includes('resource'));
|
|
52199
52161
|
let fwBinaryMap = [];
|
|
52200
52162
|
let bootloaderBinary = null;
|
|
52201
52163
|
let installItems;
|
|
52202
|
-
let resourceMemoryHost;
|
|
52203
52164
|
try {
|
|
52204
52165
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
52205
52166
|
fwBinaryMap = this.collectExplicitTargetBinaries();
|
|
@@ -52212,19 +52173,20 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52212
52173
|
const needsRemoteFirmware = ((_e = this.params.targetsToUpdate) === null || _e === void 0 ? void 0 : _e.length)
|
|
52213
52174
|
? missingFirmwareTargets.length > 0
|
|
52214
52175
|
: explicitInstallItems.length === 0;
|
|
52215
|
-
|
|
52216
|
-
|
|
52176
|
+
if (wantsResources) {
|
|
52177
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 resource archive must be provided through a local or external PreparedPlan', {
|
|
52178
|
+
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
52179
|
+
});
|
|
52180
|
+
}
|
|
52181
|
+
if (needsRemoteFirmware &&
|
|
52217
52182
|
(this.params.artifactReader ||
|
|
52218
52183
|
DataManager.getSettings('firmwareManifestMode') === 'external-only')) {
|
|
52219
52184
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 firmware artifacts must be prepared by the external firmware host', {
|
|
52220
52185
|
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
52221
52186
|
});
|
|
52222
52187
|
}
|
|
52223
|
-
if (
|
|
52224
|
-
yield DataManager.forceReloadData(
|
|
52225
|
-
requireResources: wantsResources,
|
|
52226
|
-
resourceDeviceType: capabilityDeviceType === hdShared.EDeviceType.Neo ? hdShared.EDeviceType.Neo : hdShared.EDeviceType.Pro2,
|
|
52227
|
-
});
|
|
52188
|
+
if (needsRemoteFirmware) {
|
|
52189
|
+
yield DataManager.forceReloadData();
|
|
52228
52190
|
}
|
|
52229
52191
|
if (needsRemoteFirmware) {
|
|
52230
52192
|
const remoteBinaries = yield this.prepareRemoteProtocolV2Binaries(firmwareType, deviceFeatures, explicitInstallItems);
|
|
@@ -52244,18 +52206,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52244
52206
|
targetId: item.targetId,
|
|
52245
52207
|
}));
|
|
52246
52208
|
}
|
|
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
|
-
}
|
|
52255
52209
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
52256
52210
|
}
|
|
52257
52211
|
catch (err) {
|
|
52258
|
-
resourceMemoryHost === null || resourceMemoryHost === void 0 ? void 0 : resourceMemoryHost.release();
|
|
52259
52212
|
if (typeof err === 'object' &&
|
|
52260
52213
|
err !== null &&
|
|
52261
52214
|
'params' in err &&
|
|
@@ -52267,14 +52220,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52267
52220
|
}
|
|
52268
52221
|
throw normalizeFirmwarePreparationError(err);
|
|
52269
52222
|
}
|
|
52270
|
-
if (resourceMemoryHost) {
|
|
52271
|
-
try {
|
|
52272
|
-
return yield this.runProtocolV2PreparedArtifacts(deviceFeatures, firmwareType, false);
|
|
52273
|
-
}
|
|
52274
|
-
finally {
|
|
52275
|
-
resourceMemoryHost.release();
|
|
52276
|
-
}
|
|
52277
|
-
}
|
|
52278
52223
|
if (!bootloaderBinary && fwBinaryMap.length === 0 && !(installItems === null || installItems === void 0 ? void 0 : installItems.length)) {
|
|
52279
52224
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, 'No firmware to update');
|
|
52280
52225
|
}
|
|
@@ -52374,12 +52319,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52374
52319
|
return installSources;
|
|
52375
52320
|
});
|
|
52376
52321
|
}
|
|
52377
|
-
prepareProtocolV2LocalMemoryHost({ features, firmwareType,
|
|
52378
|
-
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
52379
|
-
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
52380
|
-
}), }) {
|
|
52322
|
+
prepareProtocolV2LocalMemoryHost({ features, firmwareType, }) {
|
|
52381
52323
|
var _a, _b;
|
|
52382
52324
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52325
|
+
const availableInstallItems = this.buildProtocolV2InstallItems({
|
|
52326
|
+
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
52327
|
+
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
52328
|
+
});
|
|
52383
52329
|
const requestedComponentTargets = new Set(((_a = this.params.targetsToUpdate) !== null && _a !== void 0 ? _a : []).filter((target) => target !== 'resource' && target !== 'boot_resources'));
|
|
52384
52330
|
const localComponentTargets = new Set(availableInstallItems.flatMap(item => {
|
|
52385
52331
|
const target = PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID.get(item.targetId);
|
|
@@ -52656,20 +52602,16 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52656
52602
|
return sources;
|
|
52657
52603
|
});
|
|
52658
52604
|
}
|
|
52659
|
-
runProtocolV2PreparedArtifacts(features, firmwareType
|
|
52605
|
+
runProtocolV2PreparedArtifacts(features, firmwareType) {
|
|
52660
52606
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52661
52607
|
try {
|
|
52662
|
-
|
|
52663
|
-
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
52664
|
-
}
|
|
52608
|
+
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
52665
52609
|
const installSources = yield this.prepareProtocolV2InstallSources(firmwareType, features);
|
|
52666
52610
|
const resourceSources = yield this.prepareProtocolV2ResourceSources();
|
|
52667
52611
|
if (installSources.length === 0 && resourceSources.length === 0) {
|
|
52668
52612
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, 'No firmware to update');
|
|
52669
52613
|
}
|
|
52670
|
-
|
|
52671
|
-
this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
52672
|
-
}
|
|
52614
|
+
this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
52673
52615
|
return yield this.executeProtocolV2SourceUpdate({
|
|
52674
52616
|
installSources,
|
|
52675
52617
|
resourceSources,
|
|
@@ -52955,30 +52897,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52955
52897
|
return Object.assign(Object.assign({}, target), { binary });
|
|
52956
52898
|
});
|
|
52957
52899
|
}
|
|
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
|
-
}
|
|
52982
52900
|
prepareRemoteProtocolV2Binaries(firmwareType, features, explicitInstallItems = []) {
|
|
52983
52901
|
var _a, _b;
|
|
52984
52902
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -53138,13 +53056,19 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53138
53056
|
}
|
|
53139
53057
|
return ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.mode) === 'romloader';
|
|
53140
53058
|
}
|
|
53141
|
-
|
|
53142
|
-
var _a, _b;
|
|
53143
|
-
const protocolInfo = (_b = (_a = this.device.state) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2ProtocolInfo;
|
|
53144
|
-
return protocolInfo ? isLegacyProtocolV2ProtocolInfo(protocolInfo) : false;
|
|
53145
|
-
}
|
|
53146
|
-
rebootProtocolV2ToBootloader() {
|
|
53059
|
+
enterProtocolV2BootloaderMode() {
|
|
53147
53060
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53061
|
+
if (this.isProtocolV2RomloaderMode()) {
|
|
53062
|
+
Log$6.debug('Protocol V2 device is in romloader mode; start firmware update directly');
|
|
53063
|
+
this.protocolV2ExecutionInLoader = true;
|
|
53064
|
+
return false;
|
|
53065
|
+
}
|
|
53066
|
+
if (this.isProtocolV2BootloaderMode()) {
|
|
53067
|
+
Log$6.debug('Protocol V2 device is already in bootloader mode, skip reboot');
|
|
53068
|
+
this.protocolV2ExecutionInLoader = true;
|
|
53069
|
+
this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
53070
|
+
return false;
|
|
53071
|
+
}
|
|
53148
53072
|
try {
|
|
53149
53073
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.AutoRebootToBootloader);
|
|
53150
53074
|
yield this.protocolV2Reboot(hdTransport.DeviceRebootType.Bootloader);
|
|
@@ -53163,25 +53087,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53163
53087
|
}
|
|
53164
53088
|
});
|
|
53165
53089
|
}
|
|
53166
|
-
enterProtocolV2BootloaderMode() {
|
|
53167
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53168
|
-
this.protocolV2LegacyDirectUpdate = false;
|
|
53169
|
-
if (this.isProtocolV2RomloaderMode()) {
|
|
53170
|
-
Log$6.debug('Protocol V2 device is in romloader mode; start firmware update directly');
|
|
53171
|
-
this.protocolV2LegacyDirectUpdate = this.isLegacyProtocolV2Runtime();
|
|
53172
|
-
this.protocolV2ExecutionInLoader = true;
|
|
53173
|
-
return false;
|
|
53174
|
-
}
|
|
53175
|
-
if (this.isProtocolV2BootloaderMode()) {
|
|
53176
|
-
Log$6.debug('Protocol V2 device is already in bootloader mode, skip reboot');
|
|
53177
|
-
this.protocolV2LegacyDirectUpdate = this.isLegacyProtocolV2Runtime();
|
|
53178
|
-
this.protocolV2ExecutionInLoader = true;
|
|
53179
|
-
this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
53180
|
-
return false;
|
|
53181
|
-
}
|
|
53182
|
-
return this.rebootProtocolV2ToBootloader();
|
|
53183
|
-
});
|
|
53184
|
-
}
|
|
53185
53090
|
waitForProtocolV2BootloaderMode(timeout = PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT, retryInterval = 1000) {
|
|
53186
53091
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53187
53092
|
const startTime = Date.now();
|
|
@@ -53235,18 +53140,81 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53235
53140
|
push(this.params.se04Binary, 'se04.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04);
|
|
53236
53141
|
return entries;
|
|
53237
53142
|
}
|
|
53238
|
-
|
|
53143
|
+
buildProtocolV2ExecutionPhases({ installSources, resourceSources, }) {
|
|
53144
|
+
const phases = [];
|
|
53145
|
+
const bootResourceSources = resourceSources.filter(source => isProtocolV2BootResourcePackagePath(source.devicePath));
|
|
53146
|
+
const remainingResourceSources = resourceSources.filter(source => !isProtocolV2BootResourcePackagePath(source.devicePath));
|
|
53147
|
+
if (bootResourceSources.length > 0) {
|
|
53148
|
+
phases.push({
|
|
53149
|
+
kind: 'resource-sync',
|
|
53150
|
+
installSources: [],
|
|
53151
|
+
resourceSources: bootResourceSources,
|
|
53152
|
+
});
|
|
53153
|
+
}
|
|
53154
|
+
const bootloaderSources = installSources.filter(source => source.kind === 'bootloader');
|
|
53155
|
+
if (bootloaderSources.length > 0) {
|
|
53156
|
+
phases.push({
|
|
53157
|
+
kind: 'bootloader-install',
|
|
53158
|
+
installSources: bootloaderSources,
|
|
53159
|
+
resourceSources: [],
|
|
53160
|
+
}, {
|
|
53161
|
+
kind: 'bootloader-verify',
|
|
53162
|
+
installSources: [],
|
|
53163
|
+
resourceSources: [],
|
|
53164
|
+
});
|
|
53165
|
+
}
|
|
53166
|
+
if (remainingResourceSources.length > 0) {
|
|
53167
|
+
phases.push({
|
|
53168
|
+
kind: 'resource-sync',
|
|
53169
|
+
installSources: [],
|
|
53170
|
+
resourceSources: remainingResourceSources,
|
|
53171
|
+
});
|
|
53172
|
+
}
|
|
53173
|
+
const componentSources = installSources.filter(source => source.kind !== 'bootloader');
|
|
53174
|
+
if (componentSources.length > 0) {
|
|
53175
|
+
phases.push({
|
|
53176
|
+
kind: 'component-install',
|
|
53177
|
+
installSources: componentSources,
|
|
53178
|
+
resourceSources: [],
|
|
53179
|
+
});
|
|
53180
|
+
}
|
|
53181
|
+
phases.push({
|
|
53182
|
+
kind: 'final-verify',
|
|
53183
|
+
installSources: [],
|
|
53184
|
+
resourceSources: [],
|
|
53185
|
+
});
|
|
53186
|
+
return phases;
|
|
53187
|
+
}
|
|
53188
|
+
executeProtocolV2Phases({ installSources, resourceSources, }) {
|
|
53239
53189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53240
53190
|
this.protocolV2BootResourceStagingSafe = false;
|
|
53241
|
-
|
|
53242
|
-
|
|
53243
|
-
|
|
53244
|
-
|
|
53245
|
-
|
|
53246
|
-
|
|
53247
|
-
|
|
53191
|
+
const phases = this.buildProtocolV2ExecutionPhases({
|
|
53192
|
+
installSources,
|
|
53193
|
+
resourceSources,
|
|
53194
|
+
});
|
|
53195
|
+
for (const phase of phases) {
|
|
53196
|
+
if (phase.kind === 'final-verify') {
|
|
53197
|
+
return this.completeProtocolV2FinalVerification();
|
|
53198
|
+
}
|
|
53199
|
+
if (phase.kind === 'resource-sync') {
|
|
53200
|
+
yield this.enterProtocolV2BootloaderMode();
|
|
53201
|
+
if (!phase.resourceSources.some(source => isProtocolV2BootResourcePackagePath(source.devicePath))) {
|
|
53202
|
+
yield this.ensureProtocolV2BootResourceStagingIsEmpty();
|
|
53203
|
+
}
|
|
53204
|
+
yield this.executeProtocolV2TransferPhase(phase);
|
|
53205
|
+
}
|
|
53206
|
+
else if (phase.kind === 'bootloader-install' || phase.kind === 'component-install') {
|
|
53207
|
+
yield this.enterProtocolV2BootloaderMode();
|
|
53208
|
+
yield this.ensureProtocolV2BootResourceStagingIsEmpty();
|
|
53209
|
+
yield this.executeProtocolV2TransferPhase(phase);
|
|
53210
|
+
yield this.exitProtocolV2BootloaderToNormal();
|
|
53211
|
+
}
|
|
53212
|
+
else if (phase.kind === 'bootloader-verify') {
|
|
53213
|
+
yield this.waitForProtocolV2FinalFeatures();
|
|
53214
|
+
this.assertExpectedProtocolV2Versions(['boot']);
|
|
53215
|
+
}
|
|
53248
53216
|
}
|
|
53249
|
-
|
|
53217
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 execution has no final verification phase');
|
|
53250
53218
|
});
|
|
53251
53219
|
}
|
|
53252
53220
|
ensureProtocolV2BootResourceStagingIsEmpty() {
|
|
@@ -53274,6 +53242,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53274
53242
|
this.protocolV2BootResourceStagingSafe = true;
|
|
53275
53243
|
});
|
|
53276
53244
|
}
|
|
53245
|
+
executeProtocolV2SourceUpdate({ installSources, resourceSources, }) {
|
|
53246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53247
|
+
return this.executeProtocolV2Phases({
|
|
53248
|
+
installSources,
|
|
53249
|
+
resourceSources,
|
|
53250
|
+
});
|
|
53251
|
+
});
|
|
53252
|
+
}
|
|
53277
53253
|
executeProtocolV2Update({ fwBinaryMap, bootloaderBinary, installItems, }) {
|
|
53278
53254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53279
53255
|
const memoryInstallItems = installItems !== null && installItems !== void 0 ? installItems : this.buildProtocolV2InstallItems({
|
|
@@ -53289,7 +53265,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53289
53265
|
kind: item.kind,
|
|
53290
53266
|
});
|
|
53291
53267
|
})));
|
|
53292
|
-
return yield this.
|
|
53268
|
+
return yield this.executeProtocolV2Phases({
|
|
53293
53269
|
installSources,
|
|
53294
53270
|
resourceSources: [],
|
|
53295
53271
|
});
|
|
@@ -53490,37 +53466,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53490
53466
|
});
|
|
53491
53467
|
return Array.from(expectedTargetIds).filter(targetId => !reportedTargetIds.has(targetId));
|
|
53492
53468
|
}
|
|
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
|
-
}
|
|
53524
53469
|
waitForProtocolV2FirmwareUpdateComplete(targets) {
|
|
53525
53470
|
var _a, _b;
|
|
53526
53471
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -53533,14 +53478,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53533
53478
|
let deviceInfo;
|
|
53534
53479
|
let missingTargetStatusSince;
|
|
53535
53480
|
let missingTargetStatusKey;
|
|
53536
|
-
let normalModeWithoutInstallEvidenceSince;
|
|
53537
|
-
let installEvidenceObserved = this.protocolV2InstallAckReceived;
|
|
53538
53481
|
const resetMissingTargetStatusGrace = () => {
|
|
53539
53482
|
missingTargetStatusSince = undefined;
|
|
53540
53483
|
missingTargetStatusKey = undefined;
|
|
53541
53484
|
};
|
|
53542
53485
|
while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
|
|
53543
|
-
this.throwIfAborted();
|
|
53544
53486
|
try {
|
|
53545
53487
|
if (shouldReconnect) {
|
|
53546
53488
|
yield this.reconnectProtocolV2Device();
|
|
@@ -53557,26 +53499,16 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53557
53499
|
},
|
|
53558
53500
|
}, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
|
|
53559
53501
|
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
|
-
}
|
|
53567
53502
|
if (this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths)) {
|
|
53568
53503
|
this.protocolV2FinalStatusVerified = true;
|
|
53569
53504
|
return;
|
|
53570
53505
|
}
|
|
53571
|
-
if (statusTargets.length === 0 &&
|
|
53572
|
-
|
|
53573
|
-
|
|
53574
|
-
|
|
53575
|
-
|
|
53576
|
-
|
|
53577
|
-
this.postProgressMessage(100, 'installingFirmware');
|
|
53578
|
-
return;
|
|
53579
|
-
}
|
|
53506
|
+
if (statusTargets.length === 0 &&
|
|
53507
|
+
currentDeviceInfo &&
|
|
53508
|
+
(yield this.probeProtocolV2NormalMode(currentDeviceInfo))) {
|
|
53509
|
+
Log$6.log('[FirmwareUpdateV4] empty firmware status after confirmed App reboot; update complete');
|
|
53510
|
+
this.postProgressMessage(100, 'installingFirmware');
|
|
53511
|
+
return;
|
|
53580
53512
|
}
|
|
53581
53513
|
const missingTargetIds = this.getProtocolV2MissingTargetIds(statusTargets, expectedTargetIds);
|
|
53582
53514
|
if (missingTargetIds.length > 0) {
|
|
@@ -53609,27 +53541,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53609
53541
|
if (!currentDeviceInfo) {
|
|
53610
53542
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device identity is unavailable during install polling');
|
|
53611
53543
|
}
|
|
53612
|
-
|
|
53613
|
-
if (isNormalMode &&
|
|
53614
|
-
(installEvidenceObserved ||
|
|
53615
|
-
this.hasProtocolV2InstallVersionChanged(expectedTargetIds))) {
|
|
53544
|
+
if (yield this.probeProtocolV2NormalMode(currentDeviceInfo)) {
|
|
53616
53545
|
Log$6.log('[FirmwareUpdateV4] firmware status endpoint unavailable after confirmed App reboot');
|
|
53617
53546
|
this.postProgressMessage(100, 'installingFirmware');
|
|
53618
53547
|
return;
|
|
53619
53548
|
}
|
|
53620
|
-
|
|
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
|
-
}
|
|
53549
|
+
lastError = new Error('Protocol V2 firmware status endpoint is unavailable while the device remains in loader mode');
|
|
53633
53550
|
}
|
|
53634
53551
|
else {
|
|
53635
53552
|
shouldReconnect = true;
|
|
@@ -53681,7 +53598,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53681
53598
|
probeProtocolV2NormalMode(deviceInfo) {
|
|
53682
53599
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53683
53600
|
const features = yield this.device.probeProtocolV2RuntimeState(deviceInfo, PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT);
|
|
53684
|
-
this.protocolV2LastRuntimeProbeFeatures = features;
|
|
53685
53601
|
return features.mode === 'normal' && !features.bootloaderMode;
|
|
53686
53602
|
});
|
|
53687
53603
|
}
|
|
@@ -53860,43 +53776,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53860
53776
|
}
|
|
53861
53777
|
protocolV2StartFirmwareUpdate({ targets, }) {
|
|
53862
53778
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53863
|
-
|
|
53864
|
-
|
|
53865
|
-
const startUpdate = () => this.device
|
|
53866
|
-
.getCommands()
|
|
53867
|
-
.typedCall('DeviceFirmwareUpdateRequest', 'Success', { targets }, { timeoutMs: PROTOCOL_V2_START_UPDATE_TIMEOUT });
|
|
53868
|
-
let response;
|
|
53869
|
-
try {
|
|
53870
|
-
response = yield startUpdate();
|
|
53871
|
-
this.protocolV2InstallAckReceived = true;
|
|
53872
|
-
}
|
|
53873
|
-
catch (error) {
|
|
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 {
|
|
53896
|
-
throw error;
|
|
53897
|
-
}
|
|
53898
|
-
}
|
|
53899
|
-
this.protocolV2LegacyDirectUpdate = false;
|
|
53779
|
+
const commands = this.device.getCommands();
|
|
53780
|
+
const response = yield commands.typedCall('DeviceFirmwareUpdateRequest', 'Success', { targets }, { timeoutMs: PROTOCOL_V2_START_UPDATE_TIMEOUT });
|
|
53900
53781
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FirmwareUpdating);
|
|
53901
53782
|
this.postProgressMessage(0, 'installingFirmware');
|
|
53902
53783
|
return response;
|
|
@@ -54032,61 +53913,6 @@ class DeviceGetOnboardingStatus extends BaseMethod {
|
|
|
54032
53913
|
}
|
|
54033
53914
|
}
|
|
54034
53915
|
|
|
54035
|
-
const BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
54036
|
-
const JPEG_CONTAINER_OVERHEAD_BYTES = 64 * 1024;
|
|
54037
|
-
const JPEG_MAX_MEMORY_USAGE_IN_MB = 32;
|
|
54038
|
-
const JPEG_MAX_RESOLUTION_IN_MP = 1;
|
|
54039
|
-
function decodeCanonicalBase64({ value, parameterName, maxBytes, }) {
|
|
54040
|
-
if (typeof value !== 'string' || value.length === 0) {
|
|
54041
|
-
throw invalidParameter$1(`Parameter [${parameterName}] must be a non-empty Base64 string.`);
|
|
54042
|
-
}
|
|
54043
|
-
if (value.length > Math.ceil(maxBytes / 3) * 4) {
|
|
54044
|
-
throw invalidParameter$1(`Parameter [${parameterName}] exceeds the maximum supported size.`);
|
|
54045
|
-
}
|
|
54046
|
-
if (value.length % 4 !== 0 || !BASE64_PATTERN.test(value)) {
|
|
54047
|
-
throw invalidParameter$1(`Parameter [${parameterName}] must use canonical Base64 encoding.`);
|
|
54048
|
-
}
|
|
54049
|
-
const decoded = buffer.Buffer.from(value, 'base64');
|
|
54050
|
-
if (decoded.byteLength === 0 || decoded.byteLength > maxBytes) {
|
|
54051
|
-
throw invalidParameter$1(`Parameter [${parameterName}] exceeds the maximum supported size.`);
|
|
54052
|
-
}
|
|
54053
|
-
if (decoded.toString('base64') !== value) {
|
|
54054
|
-
throw invalidParameter$1(`Parameter [${parameterName}] must use canonical Base64 encoding.`);
|
|
54055
|
-
}
|
|
54056
|
-
return Uint8Array.from(decoded);
|
|
54057
|
-
}
|
|
54058
|
-
function decodeJpegBase64ToRgba({ jpegBase64, parameterName, expectedWidth, expectedHeight, }) {
|
|
54059
|
-
const jpegBytes = decodeCanonicalBase64({
|
|
54060
|
-
value: jpegBase64,
|
|
54061
|
-
parameterName,
|
|
54062
|
-
maxBytes: expectedWidth * expectedHeight * 8 + JPEG_CONTAINER_OVERHEAD_BYTES,
|
|
54063
|
-
});
|
|
54064
|
-
if (jpegBytes[0] !== 0xff || jpegBytes[1] !== 0xd8) {
|
|
54065
|
-
throw invalidParameter$1(`Parameter [${parameterName}] must contain a JPEG image.`);
|
|
54066
|
-
}
|
|
54067
|
-
let decoded;
|
|
54068
|
-
try {
|
|
54069
|
-
decoded = jpegJs.decode(jpegBytes, {
|
|
54070
|
-
useTArray: true,
|
|
54071
|
-
formatAsRGBA: true,
|
|
54072
|
-
tolerantDecoding: false,
|
|
54073
|
-
maxResolutionInMP: JPEG_MAX_RESOLUTION_IN_MP,
|
|
54074
|
-
maxMemoryUsageInMB: JPEG_MAX_MEMORY_USAGE_IN_MB,
|
|
54075
|
-
});
|
|
54076
|
-
}
|
|
54077
|
-
catch (_a) {
|
|
54078
|
-
throw invalidParameter$1(`Parameter [${parameterName}] must contain a valid JPEG image.`);
|
|
54079
|
-
}
|
|
54080
|
-
if (decoded.width !== expectedWidth || decoded.height !== expectedHeight) {
|
|
54081
|
-
throw invalidParameter$1(`Parameter [${parameterName}] must contain a ${expectedWidth}x${expectedHeight} JPEG image.`);
|
|
54082
|
-
}
|
|
54083
|
-
const expectedLength = expectedWidth * expectedHeight * 4;
|
|
54084
|
-
if (decoded.data.byteLength !== expectedLength) {
|
|
54085
|
-
throw invalidParameter$1(`Decoded parameter [${parameterName}] must contain ${expectedLength} RGBA bytes.`);
|
|
54086
|
-
}
|
|
54087
|
-
return decoded;
|
|
54088
|
-
}
|
|
54089
|
-
|
|
54090
53916
|
const Log$4 = getLogger(exports.LoggerNames.Core);
|
|
54091
53917
|
const MIN_FILE_CHUNK_SIZE = 64;
|
|
54092
53918
|
const FILE_TRANSFER_RATE_WINDOW_MS = 1000;
|
|
@@ -54363,9 +54189,6 @@ function writeProtocolV2File(options) {
|
|
|
54363
54189
|
|
|
54364
54190
|
const WALLPAPER_DIRECTORY = 'vol1:/wallpapers';
|
|
54365
54191
|
const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
54366
|
-
const DEVICE_SETTINGS_SET_MESSAGE_TYPE = 60412;
|
|
54367
|
-
const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE$2 = 60805;
|
|
54368
|
-
const FILESYSTEM_DIR_MAKE_MESSAGE_TYPE = 60809;
|
|
54369
54192
|
function normalizeFileName(fileName, data) {
|
|
54370
54193
|
if (fileName !== undefined && (!fileName || !SAFE_FILE_NAME.test(fileName))) {
|
|
54371
54194
|
throw invalidParameter$1('Parameter [fileName] may only contain letters, numbers, underscores, hyphens and an optional .bin suffix.');
|
|
@@ -54384,40 +54207,26 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54384
54207
|
return ['V2'];
|
|
54385
54208
|
}
|
|
54386
54209
|
init() {
|
|
54387
|
-
const {
|
|
54210
|
+
const { width, height, rgba, fileName, chunkSize } = this.payload;
|
|
54211
|
+
if (width !== PRO2_WALLPAPER_WIDTH || height !== PRO2_WALLPAPER_HEIGHT) {
|
|
54212
|
+
throw invalidParameter$1(`Pro2 wallpaper dimensions must be ${PRO2_WALLPAPER_WIDTH}x${PRO2_WALLPAPER_HEIGHT}.`);
|
|
54213
|
+
}
|
|
54214
|
+
if (!(rgba instanceof ArrayBuffer) && !ArrayBuffer.isView(rgba)) {
|
|
54215
|
+
throw invalidParameter$1('Parameter [rgba] must be an ArrayBuffer or Uint8Array.');
|
|
54216
|
+
}
|
|
54388
54217
|
if (chunkSize !== undefined && (!Number.isInteger(chunkSize) || chunkSize <= 0)) {
|
|
54389
54218
|
throw invalidParameter$1('Parameter [chunkSize] must be a positive integer.');
|
|
54390
54219
|
}
|
|
54391
|
-
const
|
|
54392
|
-
|
|
54393
|
-
|
|
54394
|
-
|
|
54395
|
-
expectedHeight: PRO2_WALLPAPER_HEIGHT,
|
|
54396
|
-
});
|
|
54397
|
-
this.encoded = encodePro2Wallpaper({
|
|
54398
|
-
width: PRO2_WALLPAPER_WIDTH,
|
|
54399
|
-
height: PRO2_WALLPAPER_HEIGHT,
|
|
54400
|
-
rgba: decoded.data,
|
|
54401
|
-
});
|
|
54220
|
+
const rgbaBytes = rgba instanceof ArrayBuffer
|
|
54221
|
+
? rgba
|
|
54222
|
+
: new Uint8Array(rgba.buffer, rgba.byteOffset, rgba.byteLength);
|
|
54223
|
+
this.encoded = encodePro2Wallpaper({ width, height, rgba: rgbaBytes });
|
|
54402
54224
|
this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
|
|
54403
|
-
this.params = {
|
|
54225
|
+
this.params = { width, height, rgba: rgbaBytes, fileName, chunkSize };
|
|
54404
54226
|
this.unlockPolicy = 'none';
|
|
54405
54227
|
this.skipForceUpdateCheck = true;
|
|
54406
54228
|
this.useDevicePassphraseState = false;
|
|
54407
54229
|
}
|
|
54408
|
-
assertCapabilities() {
|
|
54409
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
54410
|
-
const protocolInfo = yield this.device.ensureProtocolV2RuntimeContext();
|
|
54411
|
-
const requiredMessageTypes = [
|
|
54412
|
-
DEVICE_SETTINGS_SET_MESSAGE_TYPE,
|
|
54413
|
-
FILESYSTEM_FILE_WRITE_MESSAGE_TYPE$2,
|
|
54414
|
-
FILESYSTEM_DIR_MAKE_MESSAGE_TYPE,
|
|
54415
|
-
];
|
|
54416
|
-
if (requiredMessageTypes.some(messageType => !supportsProtocolV2Message(protocolInfo, messageType))) {
|
|
54417
|
-
throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
54418
|
-
}
|
|
54419
|
-
});
|
|
54420
|
-
}
|
|
54421
54230
|
ensureDirectory() {
|
|
54422
54231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54423
54232
|
if (this.directoryReady)
|
|
@@ -54467,7 +54276,6 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54467
54276
|
const { encoded } = this;
|
|
54468
54277
|
if (!encoded)
|
|
54469
54278
|
throw invalidParameter$1('Wallpaper data has not been initialized.');
|
|
54470
|
-
yield this.assertCapabilities();
|
|
54471
54279
|
yield this.ensureDirectory();
|
|
54472
54280
|
yield this.upload();
|
|
54473
54281
|
const response = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
@@ -54492,7 +54300,7 @@ class DeviceUploadNft extends BaseMethod {
|
|
|
54492
54300
|
return ['V2'];
|
|
54493
54301
|
}
|
|
54494
54302
|
init() {
|
|
54495
|
-
const {
|
|
54303
|
+
const { image, thumbnail, title, subtitle, timestampMs = Date.now(), chunkSize = PRO2_NFT_DEFAULT_CHUNK_SIZE, paceMs = PRO2_NFT_DEFAULT_PACE_MS, timeoutMs = PRO2_NFT_DEFAULT_TIMEOUT_MS, } = this.payload;
|
|
54496
54304
|
if (!Number.isInteger(chunkSize) ||
|
|
54497
54305
|
chunkSize < PRO2_NFT_MIN_CHUNK_SIZE ||
|
|
54498
54306
|
chunkSize > PRO2_NFT_MAX_CHUNK_SIZE) {
|
|
@@ -54504,51 +54312,8 @@ class DeviceUploadNft extends BaseMethod {
|
|
|
54504
54312
|
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0) {
|
|
54505
54313
|
throw invalidParameter$1('Parameter [timeoutMs] must be a positive integer.');
|
|
54506
54314
|
}
|
|
54507
|
-
|
|
54508
|
-
|
|
54509
|
-
jpegBase64: imageJpegBase64,
|
|
54510
|
-
parameterName: 'imageJpegBase64',
|
|
54511
|
-
expectedWidth: PRO2_NFT_IMAGE_WIDTH,
|
|
54512
|
-
expectedHeight: PRO2_NFT_IMAGE_HEIGHT,
|
|
54513
|
-
});
|
|
54514
|
-
return encodePro2Image({
|
|
54515
|
-
width: PRO2_NFT_IMAGE_WIDTH,
|
|
54516
|
-
height: PRO2_NFT_IMAGE_HEIGHT,
|
|
54517
|
-
rgba: decoded.data,
|
|
54518
|
-
alphaMode: 'black-background',
|
|
54519
|
-
}).data;
|
|
54520
|
-
})();
|
|
54521
|
-
const encodedThumbnail = (() => {
|
|
54522
|
-
const decoded = decodeJpegBase64ToRgba({
|
|
54523
|
-
jpegBase64: thumbnailJpegBase64,
|
|
54524
|
-
parameterName: 'thumbnailJpegBase64',
|
|
54525
|
-
expectedWidth: PRO2_NFT_THUMBNAIL_WIDTH,
|
|
54526
|
-
expectedHeight: PRO2_NFT_THUMBNAIL_HEIGHT,
|
|
54527
|
-
});
|
|
54528
|
-
return encodePro2Image({
|
|
54529
|
-
width: PRO2_NFT_THUMBNAIL_WIDTH,
|
|
54530
|
-
height: PRO2_NFT_THUMBNAIL_HEIGHT,
|
|
54531
|
-
rgba: decoded.data,
|
|
54532
|
-
alphaMode: 'black-background',
|
|
54533
|
-
}).data;
|
|
54534
|
-
})();
|
|
54535
|
-
this.bundle = buildPro2NftBundleFromEncodedImages({
|
|
54536
|
-
image: encodedImage,
|
|
54537
|
-
thumbnail: encodedThumbnail,
|
|
54538
|
-
title,
|
|
54539
|
-
subtitle,
|
|
54540
|
-
timestampMs,
|
|
54541
|
-
});
|
|
54542
|
-
this.params = {
|
|
54543
|
-
imageJpegBase64,
|
|
54544
|
-
thumbnailJpegBase64,
|
|
54545
|
-
title,
|
|
54546
|
-
subtitle,
|
|
54547
|
-
timestampMs,
|
|
54548
|
-
chunkSize,
|
|
54549
|
-
paceMs,
|
|
54550
|
-
timeoutMs,
|
|
54551
|
-
};
|
|
54315
|
+
this.bundle = buildPro2NftBundle({ image, thumbnail, title, subtitle, timestampMs });
|
|
54316
|
+
this.params = { image, thumbnail, title, subtitle, timestampMs, chunkSize, paceMs, timeoutMs };
|
|
54552
54317
|
this.unlockPolicy = 'none';
|
|
54553
54318
|
this.skipForceUpdateCheck = true;
|
|
54554
54319
|
this.useDevicePassphraseState = false;
|
|
@@ -54691,17 +54456,11 @@ class FileWrite extends BaseMethod {
|
|
|
54691
54456
|
|
|
54692
54457
|
const PORTFOLIO_PENDING_PATH = 'vol1:/portfolio/portfolio.okpkg.pending';
|
|
54693
54458
|
const PORTFOLIO_CHUNK_SIZE = 2048;
|
|
54694
|
-
const PORTFOLIO_PACKAGE_MAX_BYTES = 128 * 1024;
|
|
54695
54459
|
const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE = 60805;
|
|
54696
54460
|
const PORTFOLIO_UPDATE_MESSAGE_TYPE = 61400;
|
|
54697
54461
|
class UploadPortfolio extends FileWrite {
|
|
54698
54462
|
init() {
|
|
54699
|
-
const {
|
|
54700
|
-
const packageBytes = decodeCanonicalBase64({
|
|
54701
|
-
value: packageBase64,
|
|
54702
|
-
parameterName: 'packageBase64',
|
|
54703
|
-
maxBytes: PORTFOLIO_PACKAGE_MAX_BYTES,
|
|
54704
|
-
});
|
|
54463
|
+
const { packageBytes, timeoutMs } = this.payload;
|
|
54705
54464
|
this.payload = Object.assign(Object.assign({}, this.payload), { path: PORTFOLIO_PENDING_PATH, offset: 0, data: packageBytes, chunkSize: PORTFOLIO_CHUNK_SIZE, overwrite: true, append: false, emitProgress: false, timeoutMs });
|
|
54706
54465
|
super.init();
|
|
54707
54466
|
this.unlockPolicy = 'none';
|
|
@@ -63471,13 +63230,11 @@ class TonSignMessage extends BaseMethod {
|
|
|
63471
63230
|
super(...arguments);
|
|
63472
63231
|
this.initState = null;
|
|
63473
63232
|
this.processTxRequest = (request, data) => __awaiter(this, void 0, void 0, function* () {
|
|
63474
|
-
var _a;
|
|
63475
63233
|
if (!request.init_data_length) {
|
|
63476
63234
|
const deviceType = this.device.getCurrentDeviceType();
|
|
63477
63235
|
const hasClassic = DeviceModelToTypes.model_classic1s.includes(deviceType);
|
|
63478
|
-
const
|
|
63479
|
-
|
|
63480
|
-
return Promise.resolve(Object.assign(Object.assign({}, request), { signing_message: signingMessage, skip_validate: hasClassic || shouldSkipValidation }));
|
|
63236
|
+
const hasSigningMessageRepr = request.signning_message == null;
|
|
63237
|
+
return Promise.resolve(Object.assign(Object.assign({}, request), { skip_validate: hasClassic || hasSigningMessageRepr }));
|
|
63481
63238
|
}
|
|
63482
63239
|
const [first, rest] = cutString(data, request.init_data_length * 2);
|
|
63483
63240
|
const response = yield this.device.commands.typedCall('TonTxAck', 'TonSignedMessage', {
|
|
@@ -65028,7 +64785,6 @@ const toError = (error) => {
|
|
|
65028
64785
|
return new Error(String(error));
|
|
65029
64786
|
}
|
|
65030
64787
|
};
|
|
65031
|
-
const isExpectedCompatibilityError = (error) => error instanceof hdShared.HardwareError && error.errorCode === hdShared.HardwareErrorCode.DeviceNotSupportMethod;
|
|
65032
64788
|
const updateMethodRequestContext = (method, updates) => {
|
|
65033
64789
|
if (method.requestContext) {
|
|
65034
64790
|
updateRequestContext(method.requestContext.responseID, updates);
|
|
@@ -65402,9 +65158,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65402
65158
|
return yield task.callPromise.promise;
|
|
65403
65159
|
}
|
|
65404
65160
|
catch (e) {
|
|
65405
|
-
|
|
65406
|
-
Log.debug('Device Run Error: ', e);
|
|
65407
|
-
}
|
|
65161
|
+
Log.debug('Device Run Error: ', e);
|
|
65408
65162
|
completeMethodRequestContext(method, e);
|
|
65409
65163
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
65410
65164
|
}
|
|
@@ -65833,6 +65587,7 @@ const cleanup = () => {
|
|
|
65833
65587
|
const pendingUiPromises = _uiPromises;
|
|
65834
65588
|
_uiPromises = [];
|
|
65835
65589
|
rejectUiPromises(pendingUiPromises, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ActionCancelled, 'UI request was cancelled'));
|
|
65590
|
+
Log.debug('Cleanup...');
|
|
65836
65591
|
};
|
|
65837
65592
|
const removeDeviceListener = (device) => {
|
|
65838
65593
|
device.removeAllListeners();
|