@onekeyfe/hd-core 1.2.0-alpha.109 → 1.2.0-alpha.110
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 +2 -2
- package/__tests__/device-lifecycle-events.test.ts +1 -1
- package/__tests__/device-state-mapper.test.ts +4 -4
- package/__tests__/device-utils.test.ts +1 -1
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +54 -0
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +89 -36
- package/__tests__/get-device-state.test.ts +8 -8
- package/__tests__/protocol-v2-resources.test.ts +0 -8
- package/__tests__/protocol-v2.test.ts +236 -192
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +3 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/index.d.ts +20 -5
- package/dist/index.js +218 -134
- package/dist/protocols/protocol-v2/features.d.ts +4 -4
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/types/settings.d.ts +19 -4
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV3.ts +23 -16
- package/src/api/FirmwareUpdateV4.ts +174 -84
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
- package/src/api/protocol-v2/DeviceInfoGet.ts +3 -3
- package/src/api/ton/TonSignMessage.ts +1 -1
- package/src/data/messages/messages-protocol-v2.json +14 -31
- package/src/device/DeviceStateMapper.ts +15 -15
- package/src/deviceProfile/buildDeviceFeatures.ts +3 -3
- package/src/protocols/protocol-v2/features.ts +6 -6
- package/src/protocols/protocol-v2/resources.ts +46 -9
- package/src/types/settings.ts +19 -4
package/dist/index.js
CHANGED
|
@@ -27499,10 +27499,9 @@ var nested = {
|
|
|
27499
27499
|
MessageType_FilesystemDirMake: 60809,
|
|
27500
27500
|
MessageType_FilesystemDirRemove: 60810,
|
|
27501
27501
|
MessageType_FilesystemFormat: 60811,
|
|
27502
|
-
|
|
27503
|
-
|
|
27504
|
-
|
|
27505
|
-
MessageType_DeviceFirmwareUpdateStatus: 61003,
|
|
27502
|
+
MessageType_DeviceFirmwareUpdateRequest: 61000,
|
|
27503
|
+
MessageType_DeviceFirmwareUpdateStatusGet: 61001,
|
|
27504
|
+
MessageType_DeviceFirmwareUpdateStatus: 61002,
|
|
27506
27505
|
MessageType_DeviceSessionGet: 61200,
|
|
27507
27506
|
MessageType_DeviceSession: 61201,
|
|
27508
27507
|
MessageType_DeviceSessionAskPin: 61202,
|
|
@@ -38004,7 +38003,7 @@ var nested = {
|
|
|
38004
38003
|
type: "bytes",
|
|
38005
38004
|
id: 1
|
|
38006
38005
|
},
|
|
38007
|
-
|
|
38006
|
+
signing_message: {
|
|
38008
38007
|
type: "bytes",
|
|
38009
38008
|
id: 2
|
|
38010
38009
|
},
|
|
@@ -38898,13 +38897,13 @@ var nested = {
|
|
|
38898
38897
|
type: "string",
|
|
38899
38898
|
id: 2
|
|
38900
38899
|
},
|
|
38901
|
-
|
|
38900
|
+
burn_in_completed: {
|
|
38902
38901
|
type: "bool",
|
|
38903
|
-
id:
|
|
38902
|
+
id: 3
|
|
38904
38903
|
},
|
|
38905
|
-
|
|
38904
|
+
factory_test_completed: {
|
|
38906
38905
|
type: "bool",
|
|
38907
|
-
id:
|
|
38906
|
+
id: 4
|
|
38908
38907
|
},
|
|
38909
38908
|
manufacture_time: {
|
|
38910
38909
|
type: "DeviceFactoryInfoManufactureTime",
|
|
@@ -38992,7 +38991,7 @@ var nested = {
|
|
|
38992
38991
|
}
|
|
38993
38992
|
}
|
|
38994
38993
|
},
|
|
38995
|
-
|
|
38994
|
+
DeviceFirmwareUpdateRequest: {
|
|
38996
38995
|
fields: {
|
|
38997
38996
|
targets: {
|
|
38998
38997
|
rule: "repeated",
|
|
@@ -39001,10 +39000,6 @@ var nested = {
|
|
|
39001
39000
|
}
|
|
39002
39001
|
}
|
|
39003
39002
|
},
|
|
39004
|
-
DeviceFirmwareUpdateRequest: {
|
|
39005
|
-
fields: {
|
|
39006
|
-
}
|
|
39007
|
-
},
|
|
39008
39003
|
DeviceFirmwareUpdateRecord: {
|
|
39009
39004
|
fields: {
|
|
39010
39005
|
target_id: {
|
|
@@ -39186,7 +39181,7 @@ var nested = {
|
|
|
39186
39181
|
type: "bool",
|
|
39187
39182
|
id: 100
|
|
39188
39183
|
},
|
|
39189
|
-
|
|
39184
|
+
fw: {
|
|
39190
39185
|
type: "bool",
|
|
39191
39186
|
id: 200
|
|
39192
39187
|
},
|
|
@@ -39255,7 +39250,7 @@ var nested = {
|
|
|
39255
39250
|
type: "DeviceHardwareInfo",
|
|
39256
39251
|
id: 100
|
|
39257
39252
|
},
|
|
39258
|
-
|
|
39253
|
+
fw: {
|
|
39259
39254
|
type: "DeviceMainMcuInfo",
|
|
39260
39255
|
id: 200
|
|
39261
39256
|
},
|
|
@@ -39797,12 +39792,9 @@ var nested = {
|
|
|
39797
39792
|
id: 1
|
|
39798
39793
|
},
|
|
39799
39794
|
text: {
|
|
39795
|
+
rule: "required",
|
|
39800
39796
|
type: "string",
|
|
39801
39797
|
id: 2
|
|
39802
|
-
},
|
|
39803
|
-
text_id: {
|
|
39804
|
-
type: "uint32",
|
|
39805
|
-
id: 3
|
|
39806
39798
|
}
|
|
39807
39799
|
}
|
|
39808
39800
|
},
|
|
@@ -39833,6 +39825,7 @@ var nested = {
|
|
|
39833
39825
|
ViewSignPage: {
|
|
39834
39826
|
fields: {
|
|
39835
39827
|
title: {
|
|
39828
|
+
rule: "required",
|
|
39836
39829
|
type: "string",
|
|
39837
39830
|
id: 1
|
|
39838
39831
|
},
|
|
@@ -39866,16 +39859,13 @@ var nested = {
|
|
|
39866
39859
|
options: {
|
|
39867
39860
|
"default": "LayoutDefault"
|
|
39868
39861
|
}
|
|
39869
|
-
},
|
|
39870
|
-
title_id: {
|
|
39871
|
-
type: "uint32",
|
|
39872
|
-
id: 8
|
|
39873
39862
|
}
|
|
39874
39863
|
}
|
|
39875
39864
|
},
|
|
39876
39865
|
ViewVerifyPage: {
|
|
39877
39866
|
fields: {
|
|
39878
39867
|
title: {
|
|
39868
|
+
rule: "required",
|
|
39879
39869
|
type: "string",
|
|
39880
39870
|
id: 1
|
|
39881
39871
|
},
|
|
@@ -39900,14 +39890,6 @@ var nested = {
|
|
|
39900
39890
|
value_key: {
|
|
39901
39891
|
type: "uint32",
|
|
39902
39892
|
id: 6
|
|
39903
|
-
},
|
|
39904
|
-
title_id: {
|
|
39905
|
-
type: "uint32",
|
|
39906
|
-
id: 7
|
|
39907
|
-
},
|
|
39908
|
-
chain_id: {
|
|
39909
|
-
type: "uint32",
|
|
39910
|
-
id: 8
|
|
39911
39893
|
}
|
|
39912
39894
|
}
|
|
39913
39895
|
},
|
|
@@ -40754,9 +40736,7 @@ function parseProtocolV2ResourceManifestFile(value, index) {
|
|
|
40754
40736
|
}
|
|
40755
40737
|
const file = value;
|
|
40756
40738
|
const archivePath = assertManifestRelativePath(file.archive_path, `files[${index}].archive_path`);
|
|
40757
|
-
const originalName = file.original_name
|
|
40758
|
-
? (_a = archivePath.split('/').pop()) !== null && _a !== void 0 ? _a : archivePath
|
|
40759
|
-
: assertManifestRelativePath(file.original_name, `files[${index}].original_name`);
|
|
40739
|
+
const originalName = assertManifestRelativePath(file.original_name, `files[${index}].original_name`);
|
|
40760
40740
|
if (originalName.includes('/')) {
|
|
40761
40741
|
throw new Error(`Invalid Pro2 resource manifest files[${index}].original_name`);
|
|
40762
40742
|
}
|
|
@@ -40768,18 +40748,41 @@ function parseProtocolV2ResourceManifestFile(value, index) {
|
|
|
40768
40748
|
throw new Error(`Invalid Pro2 resource manifest files[${index}].size`);
|
|
40769
40749
|
}
|
|
40770
40750
|
const digest = normalizeHex$1(file.sha256, SHA256_HEX_LENGTH, `files[${index}].sha256`);
|
|
40751
|
+
if (file.signed !== true) {
|
|
40752
|
+
throw new Error(`Invalid Pro2 resource manifest files[${index}].signed`);
|
|
40753
|
+
}
|
|
40754
|
+
if (file.sig_algo !== 'ed25519' && file.sig_algo !== 'mldsa65') {
|
|
40755
|
+
throw new Error(`Invalid Pro2 resource manifest files[${index}].sig_algo`);
|
|
40756
|
+
}
|
|
40757
|
+
if (file.payload_version !== null && typeof file.payload_version !== 'string') {
|
|
40758
|
+
throw new Error(`Invalid Pro2 resource manifest files[${index}].payload_version`);
|
|
40759
|
+
}
|
|
40771
40760
|
if (!archivePath.endsWith('.okpkg') || !originalName.endsWith('.okpkg')) {
|
|
40772
40761
|
throw new Error(`Invalid Pro2 resource manifest files[${index}] package extension`);
|
|
40773
40762
|
}
|
|
40774
|
-
return
|
|
40763
|
+
return {
|
|
40764
|
+
archive_path: archivePath,
|
|
40765
|
+
original_name: originalName,
|
|
40766
|
+
device_path: devicePath,
|
|
40767
|
+
size: Number(file.size),
|
|
40768
|
+
sha256: digest,
|
|
40769
|
+
signed: true,
|
|
40770
|
+
sig_algo: file.sig_algo,
|
|
40771
|
+
payload_version: (_a = file.payload_version) !== null && _a !== void 0 ? _a : null,
|
|
40772
|
+
};
|
|
40775
40773
|
}
|
|
40776
40774
|
function parseProtocolV2ResourceManifest(value) {
|
|
40777
40775
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
40778
40776
|
throw new Error('Invalid Pro2 resource manifest');
|
|
40779
40777
|
}
|
|
40780
40778
|
const manifest = value;
|
|
40781
|
-
if (
|
|
40782
|
-
|
|
40779
|
+
if (manifest.schema !== 1 ||
|
|
40780
|
+
manifest.variant !== 'resource' ||
|
|
40781
|
+
manifest.device_root !== 'vol0:' ||
|
|
40782
|
+
manifest.restore_mode !== 'bootloader_update' ||
|
|
40783
|
+
!Array.isArray(manifest.trees) ||
|
|
40784
|
+
!Array.isArray(manifest.files)) {
|
|
40785
|
+
throw new Error('Invalid Pro2 resource manifest contract');
|
|
40783
40786
|
}
|
|
40784
40787
|
const files = manifest.files.map(parseProtocolV2ResourceManifestFile);
|
|
40785
40788
|
const devicePaths = new Set(files.map(file => file.device_path));
|
|
@@ -40792,6 +40795,27 @@ function parseProtocolV2ResourceManifest(value) {
|
|
|
40792
40795
|
throw new Error('Invalid Pro2 resource manifest file set');
|
|
40793
40796
|
}
|
|
40794
40797
|
return {
|
|
40798
|
+
schema: 1,
|
|
40799
|
+
artifact_name: assertManifestString(manifest.artifact_name, 'artifact_name'),
|
|
40800
|
+
release_name: assertManifestString(manifest.release_name, 'release_name'),
|
|
40801
|
+
variant: 'resource',
|
|
40802
|
+
commit: assertManifestString(manifest.commit, 'commit'),
|
|
40803
|
+
short_sha: assertManifestString(manifest.short_sha, 'short_sha'),
|
|
40804
|
+
timestamp_utc: assertManifestString(manifest.timestamp_utc, 'timestamp_utc'),
|
|
40805
|
+
core_version: assertManifestString(manifest.core_version, 'core_version'),
|
|
40806
|
+
key_set: assertManifestString(manifest.key_set, 'key_set'),
|
|
40807
|
+
device_root: 'vol0:',
|
|
40808
|
+
restore_mode: 'bootloader_update',
|
|
40809
|
+
trees: manifest.trees.map((tree, index) => {
|
|
40810
|
+
if (!tree || typeof tree !== 'object') {
|
|
40811
|
+
throw new Error(`Invalid Pro2 resource manifest trees[${index}]`);
|
|
40812
|
+
}
|
|
40813
|
+
const item = tree;
|
|
40814
|
+
return {
|
|
40815
|
+
path: assertManifestRelativePath(item.path, `trees[${index}].path`),
|
|
40816
|
+
device: assertManifestString(item.device, `trees[${index}].device`),
|
|
40817
|
+
};
|
|
40818
|
+
}),
|
|
40795
40819
|
files,
|
|
40796
40820
|
};
|
|
40797
40821
|
}
|
|
@@ -44226,10 +44250,10 @@ const getProtocolV2RuntimeMode = (protocolInfo, deviceInfo) => {
|
|
|
44226
44250
|
return 'normal';
|
|
44227
44251
|
if (binary)
|
|
44228
44252
|
return binary;
|
|
44229
|
-
if (isLegacyProtocolV2ProtocolInfo(protocolInfo) && !((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.
|
|
44230
|
-
if ((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.
|
|
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)
|
|
44231
44255
|
return 'romloader';
|
|
44232
|
-
if ((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.
|
|
44256
|
+
if ((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _d === void 0 ? void 0 : _d.bootloader)
|
|
44233
44257
|
return 'bootloader';
|
|
44234
44258
|
}
|
|
44235
44259
|
return undefined;
|
|
@@ -44239,7 +44263,7 @@ const supportsProtocolV2Message = (protocolInfo, messageType) => protocolInfo.su
|
|
|
44239
44263
|
const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
44240
44264
|
targets: {
|
|
44241
44265
|
hw: true,
|
|
44242
|
-
|
|
44266
|
+
fw: true,
|
|
44243
44267
|
coprocessor: true,
|
|
44244
44268
|
},
|
|
44245
44269
|
types: {
|
|
@@ -44250,7 +44274,7 @@ const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
|
44250
44274
|
const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
|
|
44251
44275
|
targets: {
|
|
44252
44276
|
hw: true,
|
|
44253
|
-
|
|
44277
|
+
fw: true,
|
|
44254
44278
|
coprocessor: true,
|
|
44255
44279
|
se1: true,
|
|
44256
44280
|
se2: true,
|
|
@@ -44265,7 +44289,7 @@ const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
|
|
|
44265
44289
|
const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
|
|
44266
44290
|
targets: {
|
|
44267
44291
|
hw: true,
|
|
44268
|
-
|
|
44292
|
+
fw: true,
|
|
44269
44293
|
coprocessor: true,
|
|
44270
44294
|
se1: true,
|
|
44271
44295
|
se2: true,
|
|
@@ -44532,11 +44556,11 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
|
|
|
44532
44556
|
}
|
|
44533
44557
|
: { mode },
|
|
44534
44558
|
versions: definedEntries({
|
|
44535
|
-
firmware: imageVersion((_d = info.
|
|
44536
|
-
applicationP1: imageVersion((_e = info.
|
|
44537
|
-
applicationP2: imageVersion((_f = info.
|
|
44538
|
-
bootloader: imageVersion((_g = info.
|
|
44539
|
-
board: imageVersion((_h = info.
|
|
44559
|
+
firmware: imageVersion((_d = info.fw) === null || _d === void 0 ? void 0 : _d.application),
|
|
44560
|
+
applicationP1: imageVersion((_e = info.fw) === null || _e === void 0 ? void 0 : _e.application),
|
|
44561
|
+
applicationP2: imageVersion((_f = info.fw) === null || _f === void 0 ? void 0 : _f.application_data),
|
|
44562
|
+
bootloader: imageVersion((_g = info.fw) === null || _g === void 0 ? void 0 : _g.bootloader),
|
|
44563
|
+
board: imageVersion((_h = info.fw) === null || _h === void 0 ? void 0 : _h.romloader),
|
|
44540
44564
|
ble: imageVersion((_j = info.coprocessor) === null || _j === void 0 ? void 0 : _j.application),
|
|
44541
44565
|
se01: imageVersion((_k = info.se1) === null || _k === void 0 ? void 0 : _k.application),
|
|
44542
44566
|
se02: imageVersion((_l = info.se2) === null || _l === void 0 ? void 0 : _l.application),
|
|
@@ -44548,16 +44572,16 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
|
|
|
44548
44572
|
se04Boot: imageVersion((_s = info.se4) === null || _s === void 0 ? void 0 : _s.bootloader),
|
|
44549
44573
|
}),
|
|
44550
44574
|
verification: definedEntries({
|
|
44551
|
-
firmwareBuildId: imageBuildId((_t = info.
|
|
44552
|
-
firmwareHash: imageHash((_u = info.
|
|
44553
|
-
applicationP1BuildId: imageBuildId((_v = info.
|
|
44554
|
-
applicationP1Hash: imageHash((_w = info.
|
|
44555
|
-
applicationP2BuildId: imageBuildId((_x = info.
|
|
44556
|
-
applicationP2Hash: imageHash((_y = info.
|
|
44557
|
-
bootloaderBuildId: imageBuildId((_z = info.
|
|
44558
|
-
bootloaderHash: imageHash((_0 = info.
|
|
44559
|
-
boardBuildId: imageBuildId((_1 = info.
|
|
44560
|
-
boardHash: imageHash((_2 = info.
|
|
44575
|
+
firmwareBuildId: imageBuildId((_t = info.fw) === null || _t === void 0 ? void 0 : _t.application),
|
|
44576
|
+
firmwareHash: imageHash((_u = info.fw) === null || _u === void 0 ? void 0 : _u.application),
|
|
44577
|
+
applicationP1BuildId: imageBuildId((_v = info.fw) === null || _v === void 0 ? void 0 : _v.application),
|
|
44578
|
+
applicationP1Hash: imageHash((_w = info.fw) === null || _w === void 0 ? void 0 : _w.application),
|
|
44579
|
+
applicationP2BuildId: imageBuildId((_x = info.fw) === null || _x === void 0 ? void 0 : _x.application_data),
|
|
44580
|
+
applicationP2Hash: imageHash((_y = info.fw) === null || _y === void 0 ? void 0 : _y.application_data),
|
|
44581
|
+
bootloaderBuildId: imageBuildId((_z = info.fw) === null || _z === void 0 ? void 0 : _z.bootloader),
|
|
44582
|
+
bootloaderHash: imageHash((_0 = info.fw) === null || _0 === void 0 ? void 0 : _0.bootloader),
|
|
44583
|
+
boardBuildId: imageBuildId((_1 = info.fw) === null || _1 === void 0 ? void 0 : _1.romloader),
|
|
44584
|
+
boardHash: imageHash((_2 = info.fw) === null || _2 === void 0 ? void 0 : _2.romloader),
|
|
44561
44585
|
bleBuildId: imageBuildId((_3 = info.coprocessor) === null || _3 === void 0 ? void 0 : _3.application),
|
|
44562
44586
|
bleHash: imageHash((_4 = info.coprocessor) === null || _4 === void 0 ? void 0 : _4.application),
|
|
44563
44587
|
se01BuildId: imageBuildId((_5 = info.se1) === null || _5 === void 0 ? void 0 : _5.application),
|
|
@@ -51294,12 +51318,18 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
51294
51318
|
try {
|
|
51295
51319
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
51296
51320
|
const timeoutMs = 3000;
|
|
51297
|
-
const
|
|
51298
|
-
|
|
51299
|
-
|
|
51300
|
-
|
|
51301
|
-
|
|
51302
|
-
|
|
51321
|
+
const isBrowserWebUsb = DataManager.isBrowserWebUsb(DataManager.getSettings('env'));
|
|
51322
|
+
const getFeaturesPromise = isBrowserWebUsb
|
|
51323
|
+
? typedCall('GetFeatures', 'Features', {}, { timeoutMs })
|
|
51324
|
+
: typedCall('GetFeatures', 'Features', {});
|
|
51325
|
+
const featuresRes = isBrowserWebUsb
|
|
51326
|
+
? yield getFeaturesPromise
|
|
51327
|
+
: yield Promise.race([
|
|
51328
|
+
getFeaturesPromise,
|
|
51329
|
+
new Promise((_, reject) => {
|
|
51330
|
+
setTimeout(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNotResponse, 'GetFeatures timeout', { method: 'GetFeatures', timeoutMs })), timeoutMs);
|
|
51331
|
+
}),
|
|
51332
|
+
]);
|
|
51303
51333
|
getFeaturesTimeoutCount = 0;
|
|
51304
51334
|
const features = buildProtocolV1FeaturesPayload(featuresRes.message, this.device.features);
|
|
51305
51335
|
const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
|
|
@@ -51646,6 +51676,7 @@ const PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT = 90 * 1000;
|
|
|
51646
51676
|
const PROTOCOL_V2_FINAL_RECONNECT_TIMEOUT = 3 * 60 * 1000;
|
|
51647
51677
|
const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
|
|
51648
51678
|
const PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT = 15 * 1000;
|
|
51679
|
+
const PROTOCOL_V2_START_UPDATE_TIMEOUT = 3 * 60 * 1000;
|
|
51649
51680
|
const PROTOCOL_V2_INSTALL_TIMEOUT = 8 * 60 * 1000;
|
|
51650
51681
|
const PROTOCOL_V2_MISSING_TARGET_STATUS_GRACE_TIMEOUT = 30 * 1000;
|
|
51651
51682
|
const PROTOCOL_V2_TARGET_STATUS_PENDING = 0;
|
|
@@ -51668,10 +51699,6 @@ const PROTOCOL_V2_OKPP_HASH_SIZE = 64;
|
|
|
51668
51699
|
const PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES = 1024 * 1024;
|
|
51669
51700
|
const PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT = 512;
|
|
51670
51701
|
const PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES = 256 * 1024 * 1024;
|
|
51671
|
-
const getProtocolV2LocalResourceArchivePath = (entryName) => {
|
|
51672
|
-
const match = entryName.match(/(?:^|\/)((?:bundles\/|loaders\/(?:bootloader|rom)\/).+\.okpkg)$/iu);
|
|
51673
|
-
return match === null || match === void 0 ? void 0 : match[1];
|
|
51674
|
-
};
|
|
51675
51702
|
const PROTOCOL_V2_NEO_UNSUPPORTED_TARGETS = new Set(['se03', 'se04']);
|
|
51676
51703
|
const getProtocolV2ZipEntrySizes = (entry) => {
|
|
51677
51704
|
var _a;
|
|
@@ -51810,12 +51837,36 @@ const isProtocolV2ReconnectProbeError = (error) => {
|
|
|
51810
51837
|
return ((message.includes('device protocol mismatch') && message.includes('expected v2')) ||
|
|
51811
51838
|
message.includes('did not respond to expected protocol'));
|
|
51812
51839
|
};
|
|
51840
|
+
const PROTOCOL_V2_BLE_INSTALL_INTERRUPTION_ERROR_CODES = new Set([
|
|
51841
|
+
hdShared.HardwareErrorCode.BleConnectedError,
|
|
51842
|
+
hdShared.HardwareErrorCode.BleCharacteristicNotifyError,
|
|
51843
|
+
hdShared.HardwareErrorCode.BleForceCleanRunPromise,
|
|
51844
|
+
hdShared.HardwareErrorCode.BleDeviceDisconnected,
|
|
51845
|
+
]);
|
|
51846
|
+
const isProtocolV2BleInstallInterruptionError = (error) => {
|
|
51847
|
+
if (error instanceof hdShared.HardwareError &&
|
|
51848
|
+
PROTOCOL_V2_BLE_INSTALL_INTERRUPTION_ERROR_CODES.has(error.errorCode)) {
|
|
51849
|
+
return true;
|
|
51850
|
+
}
|
|
51851
|
+
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51852
|
+
const compactMessage = message.replace(/\s+/gu, '');
|
|
51853
|
+
return (/react native ble transport (?:released|disconnected)/u.test(message) ||
|
|
51854
|
+
(compactMessage.includes('rxerrorerror6') &&
|
|
51855
|
+
(compactMessage.includes('multiplatformbleadapter') ||
|
|
51856
|
+
compactMessage.includes('multipalformebleadapter'))));
|
|
51857
|
+
};
|
|
51813
51858
|
const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
|
|
51814
51859
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51815
51860
|
return (message.includes('handler not registered') ||
|
|
51816
51861
|
message.includes('message handler not found') ||
|
|
51817
51862
|
message.includes('unsupported message'));
|
|
51818
51863
|
};
|
|
51864
|
+
const isProtocolV2FirmwareUpdateEndpointUnavailable = (error) => {
|
|
51865
|
+
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51866
|
+
return (message.includes('handler not registered') ||
|
|
51867
|
+
message.includes('message handler not found') ||
|
|
51868
|
+
message.includes('unsupported message'));
|
|
51869
|
+
};
|
|
51819
51870
|
const isProtocolV2TerminalInstallStatusError = (error) => {
|
|
51820
51871
|
var _a;
|
|
51821
51872
|
return error instanceof hdShared.HardwareError &&
|
|
@@ -51948,9 +51999,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
51948
51999
|
this.protocolV2HasExplicitTargetSelection = false;
|
|
51949
52000
|
this.protocolV2PreparedSources = [];
|
|
51950
52001
|
this.protocolV2ExecutionInLoader = false;
|
|
52002
|
+
this.protocolV2LegacyDirectUpdate = false;
|
|
51951
52003
|
this.protocolV2BootResourceStagingSafe = false;
|
|
51952
52004
|
this.protocolV2CompletedTargetVersions = new Map();
|
|
51953
52005
|
this.protocolV2FinalStatusVerified = false;
|
|
52006
|
+
this.protocolV2InstallAckReceived = false;
|
|
51954
52007
|
this.protocolV2InstallBaselineVersions = new Map();
|
|
51955
52008
|
}
|
|
51956
52009
|
getSupportedProtocols() {
|
|
@@ -52446,63 +52499,60 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52446
52499
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP contains an unsafe entry path', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52447
52500
|
}
|
|
52448
52501
|
const entries = zipEntries.filter(entry => !entry.dir);
|
|
52449
|
-
if (entries.length === 0) {
|
|
52502
|
+
if (entries.length === 0 || entries.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT + 1) {
|
|
52450
52503
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP entry set is invalid', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52451
52504
|
}
|
|
52452
|
-
|
|
52453
|
-
let
|
|
52454
|
-
|
|
52455
|
-
|
|
52456
|
-
|
|
52457
|
-
|
|
52458
|
-
|
|
52459
|
-
|
|
52460
|
-
|
|
52461
|
-
|
|
52462
|
-
|
|
52463
|
-
|
|
52464
|
-
|
|
52505
|
+
let declaredUncompressedSize = 0;
|
|
52506
|
+
let declaredCompressedSize = 0;
|
|
52507
|
+
for (const entry of entries) {
|
|
52508
|
+
const sizes = getProtocolV2ZipEntrySizes(entry);
|
|
52509
|
+
declaredCompressedSize += sizes.compressedSize;
|
|
52510
|
+
declaredUncompressedSize += sizes.uncompressedSize;
|
|
52511
|
+
const entryLimit = entry.name === 'manifest.json'
|
|
52512
|
+
? PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES
|
|
52513
|
+
: PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES;
|
|
52514
|
+
if (sizes.uncompressedSize > entryLimit ||
|
|
52515
|
+
declaredCompressedSize > binary.byteLength ||
|
|
52516
|
+
declaredUncompressedSize >
|
|
52517
|
+
PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES + PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES) {
|
|
52518
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP declared size exceeds the allowed limit', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52465
52519
|
}
|
|
52466
|
-
let manifestValue;
|
|
52467
|
-
try {
|
|
52468
|
-
manifestValue = JSON.parse(new TextDecoder().decode(manifestBinary));
|
|
52469
|
-
}
|
|
52470
|
-
catch (error) {
|
|
52471
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource manifest is invalid: ${String(error)}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52472
|
-
}
|
|
52473
|
-
selectedFiles = selectProtocolV2ResourceManifestFiles({
|
|
52474
|
-
manifest: parseProtocolV2ResourceManifest(manifestValue),
|
|
52475
|
-
targetsToUpdate: (_a = this.params.targetsToUpdate) !== null && _a !== void 0 ? _a : [],
|
|
52476
|
-
});
|
|
52477
|
-
manifestDirectory = manifestEntry.name.slice(0, -'manifest.json'.length);
|
|
52478
52520
|
}
|
|
52479
|
-
|
|
52480
|
-
|
|
52481
|
-
|
|
52482
|
-
|
|
52483
|
-
|
|
52484
|
-
|
|
52485
|
-
|
|
52486
|
-
|
|
52487
|
-
|
|
52488
|
-
|
|
52489
|
-
|
|
52490
|
-
|
|
52491
|
-
|
|
52492
|
-
|
|
52493
|
-
|
|
52494
|
-
});
|
|
52521
|
+
const manifestEntry = zip.file('manifest.json');
|
|
52522
|
+
if (!manifestEntry) {
|
|
52523
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP has no manifest.json', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52524
|
+
}
|
|
52525
|
+
const manifestBinary = yield manifestEntry.async('arraybuffer');
|
|
52526
|
+
if (manifestBinary.byteLength <= 0 ||
|
|
52527
|
+
manifestBinary.byteLength > PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES) {
|
|
52528
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource manifest size is invalid', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52529
|
+
}
|
|
52530
|
+
let manifestValue;
|
|
52531
|
+
try {
|
|
52532
|
+
manifestValue = JSON.parse(new TextDecoder().decode(manifestBinary));
|
|
52533
|
+
}
|
|
52534
|
+
catch (error) {
|
|
52535
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource manifest is invalid: ${String(error)}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52495
52536
|
}
|
|
52496
|
-
|
|
52497
|
-
|
|
52537
|
+
const manifest = parseProtocolV2ResourceManifest(manifestValue);
|
|
52538
|
+
const selectedFiles = selectProtocolV2ResourceManifestFiles({
|
|
52539
|
+
manifest,
|
|
52540
|
+
targetsToUpdate: (_a = this.params.targetsToUpdate) !== null && _a !== void 0 ? _a : [],
|
|
52541
|
+
});
|
|
52542
|
+
const expectedEntryNames = new Set([
|
|
52543
|
+
'manifest.json',
|
|
52544
|
+
...selectedFiles.map(file => file.archive_path),
|
|
52545
|
+
]);
|
|
52546
|
+
if (entries.length !== expectedEntryNames.size ||
|
|
52547
|
+
entries.some(entry => !expectedEntryNames.has(entry.name))) {
|
|
52548
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP contains an unexpected entry', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52498
52549
|
}
|
|
52499
52550
|
let totalSize = 0;
|
|
52500
|
-
const materializedEntries = [
|
|
52501
|
-
|
|
52551
|
+
const materializedEntries = [
|
|
52552
|
+
{ entryName: 'manifest.json', binary: manifestBinary },
|
|
52553
|
+
];
|
|
52502
52554
|
for (const file of selectedFiles) {
|
|
52503
|
-
const entry =
|
|
52504
|
-
? zip.file(`${manifestDirectory}${file.archive_path}`)
|
|
52505
|
-
: entries.find(candidate => getProtocolV2LocalResourceArchivePath(candidate.name) === file.archive_path);
|
|
52555
|
+
const entry = zip.file(file.archive_path);
|
|
52506
52556
|
if (!entry) {
|
|
52507
52557
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource ZIP is missing ${file.archive_path}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52508
52558
|
}
|
|
@@ -52513,15 +52563,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52513
52563
|
}
|
|
52514
52564
|
const fileBinary = yield entry.async('arraybuffer');
|
|
52515
52565
|
const digest = bytesToHex(sha256.sha256(new Uint8Array(fileBinary)));
|
|
52516
|
-
if (fileBinary.byteLength !== file.size ||
|
|
52517
|
-
(file.sha256 && digest !== file.sha256.toLowerCase())) {
|
|
52566
|
+
if (fileBinary.byteLength !== file.size || digest !== file.sha256.toLowerCase()) {
|
|
52518
52567
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource file does not match manifest: ${file.archive_path}`, { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' });
|
|
52519
52568
|
}
|
|
52520
|
-
normalizedFiles.push(Object.assign(Object.assign({}, file), { sha256: digest }));
|
|
52521
52569
|
materializedEntries.push({ entryName: file.archive_path, binary: fileBinary });
|
|
52522
52570
|
}
|
|
52523
|
-
manifestBinary !== null && manifestBinary !== void 0 ? manifestBinary : (manifestBinary = new TextEncoder().encode(JSON.stringify({ files: normalizedFiles })).buffer);
|
|
52524
|
-
materializedEntries.unshift({ entryName: 'manifest.json', binary: manifestBinary });
|
|
52525
52571
|
return { binary, materializedEntries };
|
|
52526
52572
|
});
|
|
52527
52573
|
}
|
|
@@ -53108,6 +53154,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53108
53154
|
}
|
|
53109
53155
|
return ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.mode) === 'romloader';
|
|
53110
53156
|
}
|
|
53157
|
+
isLegacyProtocolV2Runtime() {
|
|
53158
|
+
var _a, _b;
|
|
53159
|
+
const protocolInfo = (_b = (_a = this.device.state) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2ProtocolInfo;
|
|
53160
|
+
return protocolInfo ? isLegacyProtocolV2ProtocolInfo(protocolInfo) : false;
|
|
53161
|
+
}
|
|
53111
53162
|
rebootProtocolV2ToBootloader() {
|
|
53112
53163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53113
53164
|
try {
|
|
@@ -53130,13 +53181,16 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53130
53181
|
}
|
|
53131
53182
|
enterProtocolV2BootloaderMode() {
|
|
53132
53183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53184
|
+
this.protocolV2LegacyDirectUpdate = false;
|
|
53133
53185
|
if (this.isProtocolV2RomloaderMode()) {
|
|
53134
53186
|
Log$6.debug('Protocol V2 device is in romloader mode; start firmware update directly');
|
|
53187
|
+
this.protocolV2LegacyDirectUpdate = this.isLegacyProtocolV2Runtime();
|
|
53135
53188
|
this.protocolV2ExecutionInLoader = true;
|
|
53136
53189
|
return false;
|
|
53137
53190
|
}
|
|
53138
53191
|
if (this.isProtocolV2BootloaderMode()) {
|
|
53139
53192
|
Log$6.debug('Protocol V2 device is already in bootloader mode, skip reboot');
|
|
53193
|
+
this.protocolV2LegacyDirectUpdate = this.isLegacyProtocolV2Runtime();
|
|
53140
53194
|
this.protocolV2ExecutionInLoader = true;
|
|
53141
53195
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
53142
53196
|
return false;
|
|
@@ -53496,7 +53550,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53496
53550
|
let missingTargetStatusSince;
|
|
53497
53551
|
let missingTargetStatusKey;
|
|
53498
53552
|
let normalModeWithoutInstallEvidenceSince;
|
|
53499
|
-
let installEvidenceObserved =
|
|
53553
|
+
let installEvidenceObserved = this.protocolV2InstallAckReceived;
|
|
53500
53554
|
const resetMissingTargetStatusGrace = () => {
|
|
53501
53555
|
missingTargetStatusSince = undefined;
|
|
53502
53556
|
missingTargetStatusKey = undefined;
|
|
@@ -53511,18 +53565,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53511
53565
|
}
|
|
53512
53566
|
const currentDeviceInfo = deviceInfo;
|
|
53513
53567
|
try {
|
|
53514
|
-
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet',
|
|
53568
|
+
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', {
|
|
53515
53569
|
fields: {
|
|
53516
53570
|
status: true,
|
|
53517
53571
|
payload_version: true,
|
|
53518
53572
|
path: true,
|
|
53519
53573
|
},
|
|
53520
53574
|
}, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
|
|
53521
|
-
if (statusResponse.type === 'Success') {
|
|
53522
|
-
this.protocolV2FinalStatusVerified = true;
|
|
53523
|
-
this.postProgressMessage(100, 'installingFirmware');
|
|
53524
|
-
return;
|
|
53525
|
-
}
|
|
53526
53575
|
const statusTargets = ((_a = statusResponse.message.records) !== null && _a !== void 0 ? _a : []);
|
|
53527
53576
|
if (statusTargets.some(target => {
|
|
53528
53577
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
@@ -53827,12 +53876,46 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53827
53876
|
}
|
|
53828
53877
|
protocolV2StartFirmwareUpdate({ targets, }) {
|
|
53829
53878
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53879
|
+
this.protocolV2InstallAckReceived = false;
|
|
53830
53880
|
this.protocolV2LastRuntimeProbeFeatures = undefined;
|
|
53831
|
-
const
|
|
53832
|
-
|
|
53833
|
-
|
|
53881
|
+
const startUpdate = () => this.device
|
|
53882
|
+
.getCommands()
|
|
53883
|
+
.typedCall('DeviceFirmwareUpdateRequest', 'Success', { targets }, { timeoutMs: PROTOCOL_V2_START_UPDATE_TIMEOUT });
|
|
53884
|
+
let response;
|
|
53885
|
+
try {
|
|
53886
|
+
response = yield startUpdate();
|
|
53887
|
+
this.protocolV2InstallAckReceived = true;
|
|
53888
|
+
}
|
|
53889
|
+
catch (error) {
|
|
53890
|
+
if (this.isBleReconnect() && isProtocolV2BleInstallInterruptionError(error)) {
|
|
53891
|
+
this.throwIfAborted();
|
|
53892
|
+
Log$6.log('[FirmwareUpdateV4] install request interrupted by device reboot; continue status polling: ', error);
|
|
53893
|
+
}
|
|
53894
|
+
else if (this.protocolV2LegacyDirectUpdate &&
|
|
53895
|
+
isProtocolV2FirmwareUpdateEndpointUnavailable(error)) {
|
|
53896
|
+
this.protocolV2LegacyDirectUpdate = false;
|
|
53897
|
+
Log$6.debug('[FirmwareUpdateV4] legacy App does not expose DeviceFirmwareUpdateRequest; rebooting to bootloader');
|
|
53898
|
+
yield this.rebootProtocolV2ToBootloader();
|
|
53899
|
+
try {
|
|
53900
|
+
response = yield startUpdate();
|
|
53901
|
+
this.protocolV2InstallAckReceived = true;
|
|
53902
|
+
}
|
|
53903
|
+
catch (retryError) {
|
|
53904
|
+
if (!(this.isBleReconnect() && isProtocolV2BleInstallInterruptionError(retryError))) {
|
|
53905
|
+
throw retryError;
|
|
53906
|
+
}
|
|
53907
|
+
this.throwIfAborted();
|
|
53908
|
+
Log$6.log('[FirmwareUpdateV4] install request interrupted after legacy reboot; continue status polling: ', retryError);
|
|
53909
|
+
}
|
|
53910
|
+
}
|
|
53911
|
+
else {
|
|
53912
|
+
throw error;
|
|
53913
|
+
}
|
|
53914
|
+
}
|
|
53915
|
+
this.protocolV2LegacyDirectUpdate = false;
|
|
53834
53916
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FirmwareUpdating);
|
|
53835
53917
|
this.postProgressMessage(0, 'installingFirmware');
|
|
53918
|
+
return response;
|
|
53836
53919
|
});
|
|
53837
53920
|
}
|
|
53838
53921
|
protocolV2Reboot(rebootType) {
|
|
@@ -63404,10 +63487,11 @@ class TonSignMessage extends BaseMethod {
|
|
|
63404
63487
|
super(...arguments);
|
|
63405
63488
|
this.initState = null;
|
|
63406
63489
|
this.processTxRequest = (request, data) => __awaiter(this, void 0, void 0, function* () {
|
|
63490
|
+
var _a;
|
|
63407
63491
|
if (!request.init_data_length) {
|
|
63408
63492
|
const deviceType = this.device.getCurrentDeviceType();
|
|
63409
63493
|
const hasClassic = DeviceModelToTypes.model_classic1s.includes(deviceType);
|
|
63410
|
-
const signingMessage = request.signning_message;
|
|
63494
|
+
const signingMessage = (_a = request.signing_message) !== null && _a !== void 0 ? _a : request.signning_message;
|
|
63411
63495
|
const shouldSkipValidation = signingMessage == null;
|
|
63412
63496
|
return Promise.resolve(Object.assign(Object.assign({}, request), { signing_message: signingMessage, skip_validate: hasClassic || shouldSkipValidation }));
|
|
63413
63497
|
}
|