@onekeyfe/hd-core 1.2.0-alpha.0 → 1.2.0-alpha.2

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.
Files changed (68) hide show
  1. package/__tests__/protocol-v2.test.ts +56 -178
  2. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  3. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  4. package/dist/api/FirmwareUpdateV4.d.ts +2 -2
  5. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  6. package/dist/api/GetDeviceInfo.d.ts.map +1 -1
  7. package/dist/api/GetFeatures.d.ts +1 -1
  8. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  9. package/dist/api/device/DeviceUnlock.d.ts +1 -1
  10. package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
  11. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  12. package/dist/api/tron/TronSignMessage.d.ts +0 -1
  13. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  14. package/dist/api/tron/TronSignTransaction.d.ts +0 -1
  15. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  16. package/dist/core/index.d.ts.map +1 -1
  17. package/dist/device/Device.d.ts +10 -15
  18. package/dist/device/Device.d.ts.map +1 -1
  19. package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -0
  20. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
  21. package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -4
  22. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  23. package/dist/deviceProfile/index.d.ts +1 -1
  24. package/dist/deviceProfile/index.d.ts.map +1 -1
  25. package/dist/index.d.ts +571 -496
  26. package/dist/index.js +502 -571
  27. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  28. package/dist/types/api/getDeviceInfo.d.ts +2 -2
  29. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  30. package/dist/types/device.d.ts +87 -8
  31. package/dist/types/device.d.ts.map +1 -1
  32. package/dist/utils/capabilitieUtils.d.ts.map +1 -1
  33. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  34. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  35. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  36. package/dist/utils/findDefectiveBatchDevice.d.ts +1 -1
  37. package/dist/utils/patch.d.ts +1 -1
  38. package/package.json +4 -4
  39. package/src/api/FirmwareUpdateV2.ts +9 -2
  40. package/src/api/FirmwareUpdateV3.ts +2 -1
  41. package/src/api/FirmwareUpdateV4.ts +24 -31
  42. package/src/api/GetDeviceInfo.ts +6 -13
  43. package/src/api/GetOnekeyFeatures.ts +3 -14
  44. package/src/api/GetPassphraseState.ts +2 -2
  45. package/src/api/firmware/bootloaderHelper.ts +3 -2
  46. package/src/api/firmware/getBinary.ts +1 -1
  47. package/src/api/firmware/releaseHelper.ts +3 -3
  48. package/src/api/firmware/uploadFirmware.ts +5 -2
  49. package/src/api/tron/TronSignMessage.ts +0 -1
  50. package/src/api/tron/TronSignTransaction.ts +0 -1
  51. package/src/core/index.ts +3 -7
  52. package/src/data-manager/DataManager.ts +4 -4
  53. package/src/device/Device.ts +74 -240
  54. package/src/device/DevicePool.ts +3 -3
  55. package/src/deviceProfile/buildDeviceFeatures.ts +367 -0
  56. package/src/deviceProfile/buildDeviceProfile.ts +102 -155
  57. package/src/deviceProfile/index.ts +4 -1
  58. package/src/protocols/protocol-v2/features.ts +6 -9
  59. package/src/types/api/getDeviceInfo.ts +2 -2
  60. package/src/types/device.ts +97 -34
  61. package/src/utils/capabilitieUtils.ts +1 -2
  62. package/src/utils/deviceFeaturesUtils.ts +11 -17
  63. package/src/utils/deviceInfoUtils.ts +11 -29
  64. package/src/utils/deviceVersionUtils.ts +7 -25
  65. package/src/utils/findDefectiveBatchDevice.ts +6 -6
  66. package/dist/deviceProfile/legacyFeaturesView.d.ts +0 -5
  67. package/dist/deviceProfile/legacyFeaturesView.d.ts.map +0 -1
  68. package/src/deviceProfile/legacyFeaturesView.ts +0 -123
package/dist/index.js CHANGED
@@ -1202,35 +1202,20 @@ const DeviceTypeToModels = {
1202
1202
  [hdShared.EDeviceType.Unknown]: [],
1203
1203
  };
1204
1204
 
1205
- const existCapability = (features, capability) => { var _a; return (_a = features === null || features === void 0 ? void 0 : features.capabilities) === null || _a === void 0 ? void 0 : _a.includes(capability); };
1205
+ const existCapability = (features, capability) => { var _a; return capability !== undefined && ((_a = features === null || features === void 0 ? void 0 : features.capabilities) === null || _a === void 0 ? void 0 : _a.includes(capability)); };
1206
1206
 
1207
1207
  const getDeviceType = (features) => {
1208
1208
  if (!features || typeof features !== 'object') {
1209
1209
  return hdShared.EDeviceType.Unknown;
1210
1210
  }
1211
- switch (features.onekey_device_type) {
1212
- case 'CLASSIC':
1213
- return hdShared.EDeviceType.Classic;
1214
- case 'CLASSIC1S':
1215
- return hdShared.EDeviceType.Classic1s;
1216
- case 'MINI':
1217
- return hdShared.EDeviceType.Mini;
1218
- case 'TOUCH':
1219
- return hdShared.EDeviceType.Touch;
1220
- case 'PRO':
1221
- return hdShared.EDeviceType.Pro;
1222
- case 'PRO2':
1223
- case 'pro2':
1224
- return hdShared.EDeviceType.Pro2;
1225
- case 'PURE':
1226
- return hdShared.EDeviceType.ClassicPure;
1227
- default:
1228
- if (!lodash.isEmpty(features.onekey_serial_no)) {
1229
- return hdShared.EDeviceType.Unknown;
1230
- }
1211
+ if (features.deviceType) {
1212
+ return features.deviceType;
1213
+ }
1214
+ if (features.model === hdShared.EDeviceType.Pro2 || features.model === 'pro2') {
1215
+ return hdShared.EDeviceType.Pro2;
1231
1216
  }
1232
1217
  const serialNo = getDeviceUUID(features);
1233
- if (lodash.isEmpty(serialNo) && features.bootloader_mode === true && features.model === '1') {
1218
+ if (lodash.isEmpty(serialNo) && features.bootloaderMode === true && features.model === '1') {
1234
1219
  return hdShared.EDeviceType.Classic;
1235
1220
  }
1236
1221
  if (lodash.isEmpty(serialNo))
@@ -1248,6 +1233,8 @@ const getDeviceType = (features) => {
1248
1233
  return hdShared.EDeviceType.Touch;
1249
1234
  if (miniFlag.toLowerCase() === 'pr')
1250
1235
  return hdShared.EDeviceType.Pro;
1236
+ if (miniFlag.toLowerCase() === 'p2')
1237
+ return hdShared.EDeviceType.Pro2;
1251
1238
  return hdShared.EDeviceType.Unknown;
1252
1239
  };
1253
1240
  const getDeviceTypeByBleName = (name) => {
@@ -1270,11 +1257,11 @@ const getDeviceTypeByBleName = (name) => {
1270
1257
  const getDeviceBleName = (features) => {
1271
1258
  if (features == null)
1272
1259
  return null;
1273
- return features.onekey_ble_name || features.ble_name || null;
1260
+ return features.bleName || null;
1274
1261
  };
1275
1262
  const getDeviceUUID = (features) => {
1276
- const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no;
1277
- return serialNo !== null && serialNo !== void 0 ? serialNo : '';
1263
+ var _a;
1264
+ return (_a = features.serialNo) !== null && _a !== void 0 ? _a : '';
1278
1265
  };
1279
1266
  const getDeviceLabel = (features) => {
1280
1267
  if (!features)
@@ -1321,8 +1308,8 @@ const getFirmwareType = (features) => {
1321
1308
  if (!features) {
1322
1309
  return hdShared.EFirmwareType.Universal;
1323
1310
  }
1324
- if (features.fw_vendor === 'OneKey Bitcoin-only') {
1325
- return hdShared.EFirmwareType.BitcoinOnly;
1311
+ if (features.firmwareType) {
1312
+ return features.firmwareType;
1326
1313
  }
1327
1314
  return ((_a = features === null || features === void 0 ? void 0 : features.capabilities) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
1328
1315
  !existCapability(features, hdTransport.Enum_Capability.Capability_Bitcoin_like)
@@ -1331,19 +1318,15 @@ const getFirmwareType = (features) => {
1331
1318
  };
1332
1319
 
1333
1320
  const getDeviceFirmwareVersion = (features) => {
1334
- var _a, _b;
1335
1321
  if (!features)
1336
1322
  return [0, 0, 0];
1337
- if (semver__default["default"].valid(features.onekey_firmware_version)) {
1338
- return (_a = features.onekey_firmware_version) === null || _a === void 0 ? void 0 : _a.split('.');
1339
- }
1340
- if (semver__default["default"].valid(features.onekey_version)) {
1341
- return (_b = features.onekey_version) === null || _b === void 0 ? void 0 : _b.split('.');
1323
+ if (features.firmwareVersion && semver__default["default"].valid(features.firmwareVersion)) {
1324
+ return features.firmwareVersion.split('.').map(Number);
1342
1325
  }
1343
1326
  return [0, 0, 0];
1344
1327
  };
1345
1328
  const getDeviceBLEFirmwareVersion = (features) => {
1346
- const bleVer = (features === null || features === void 0 ? void 0 : features.onekey_ble_version) || (features === null || features === void 0 ? void 0 : features.ble_ver);
1329
+ const bleVer = features === null || features === void 0 ? void 0 : features.bleVersion;
1347
1330
  if (!bleVer) {
1348
1331
  return [0, 0, 0];
1349
1332
  }
@@ -1356,31 +1339,16 @@ const getDeviceBLEFirmwareVersion = (features) => {
1356
1339
  return [0, 0, 0];
1357
1340
  };
1358
1341
  const getDeviceBootloaderVersion = (features) => {
1359
- var _a, _b, _c, _d, _e;
1360
1342
  if (!features)
1361
1343
  return [0, 0, 0];
1362
- if (semver__default["default"].valid(features.onekey_boot_version)) {
1363
- return (_a = features.onekey_boot_version) === null || _a === void 0 ? void 0 : _a.split('.');
1364
- }
1365
- if (!features.bootloader_version) {
1366
- if (features.bootloader_mode) {
1367
- return [
1368
- (_b = features === null || features === void 0 ? void 0 : features.major_version) !== null && _b !== void 0 ? _b : 0,
1369
- (_c = features === null || features === void 0 ? void 0 : features.minor_version) !== null && _c !== void 0 ? _c : 0,
1370
- (_d = features === null || features === void 0 ? void 0 : features.patch_version) !== null && _d !== void 0 ? _d : 0,
1371
- ];
1372
- }
1373
- return [0, 0, 0];
1374
- }
1375
- if (semver__default["default"].valid(features.bootloader_version)) {
1376
- return (_e = features.bootloader_version) === null || _e === void 0 ? void 0 : _e.split('.');
1344
+ if (features.bootloaderVersion && semver__default["default"].valid(features.bootloaderVersion)) {
1345
+ return features.bootloaderVersion.split('.').map(Number);
1377
1346
  }
1378
1347
  return [0, 0, 0];
1379
1348
  };
1380
1349
  const getDeviceBoardloaderVersion = (features) => {
1381
- var _a;
1382
- if (semver__default["default"].valid(features === null || features === void 0 ? void 0 : features.onekey_board_version)) {
1383
- return (_a = features === null || features === void 0 ? void 0 : features.onekey_board_version) === null || _a === void 0 ? void 0 : _a.split('.');
1350
+ if ((features === null || features === void 0 ? void 0 : features.boardVersion) && semver__default["default"].valid(features.boardVersion)) {
1351
+ return features.boardVersion.split('.').map(Number);
1384
1352
  }
1385
1353
  return [0, 0, 0];
1386
1354
  };
@@ -38994,10 +38962,10 @@ DataManager.getFirmwareStatus = (features, firmwareType) => {
38994
38962
  return 'unknown';
38995
38963
  const deviceFirmwareType = getFirmwareType(features);
38996
38964
  const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
38997
- if (features.firmware_present === false) {
38965
+ if (features.firmwarePresent === false) {
38998
38966
  return 'none';
38999
38967
  }
39000
- if (DeviceModelToTypes.model_mini.includes(deviceType) && features.bootloader_mode) {
38968
+ if (DeviceModelToTypes.model_mini.includes(deviceType) && features.bootloaderMode) {
39001
38969
  return 'unknown';
39002
38970
  }
39003
38971
  const firmwareUpdateField = getFirmwareUpdateField({
@@ -39107,8 +39075,8 @@ DataManager.getFirmwareChangelog = (features, firmwareType) => {
39107
39075
  firmwareType,
39108
39076
  });
39109
39077
  const targetDeviceConfigList = (_c = (_b = _a$1.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b[firmwareUpdateField]) !== null && _c !== void 0 ? _c : [];
39110
- if (features.firmware_present === false ||
39111
- (DeviceModelToTypes.model_classic.includes(deviceType) && features.bootloader_mode)) {
39078
+ if (features.firmwarePresent === false ||
39079
+ (DeviceModelToTypes.model_classic.includes(deviceType) && features.bootloaderMode)) {
39112
39080
  return getReleaseChangelog(targetDeviceConfigList, '0.0.0');
39113
39081
  }
39114
39082
  const currentVersion = deviceFirmwareVersion.join('.');
@@ -39247,16 +39215,14 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
39247
39215
  yield device.getFeatures();
39248
39216
  }
39249
39217
  const deviceId = device.getCurrentDeviceId();
39250
- if (deviceId) {
39251
- device.updateInternalState((_a = device.getCurrentPassphraseProtection()) !== null && _a !== void 0 ? _a : false, passphraseState, deviceId, newSession, (_b = device.features) === null || _b === void 0 ? void 0 : _b.session_id);
39252
- }
39218
+ device.updateInternalState((_a = device.getCurrentPassphraseProtection()) !== null && _a !== void 0 ? _a : false, passphraseState, deviceId, newSession, (_b = device.features) === null || _b === void 0 ? void 0 : _b.sessionId);
39253
39219
  return { passphraseState, newSession, unlockedAttachPin };
39254
39220
  });
39255
39221
  const supportProSeriesAttachPinPassphrase = (deviceType, firmwareVersion) => deviceType === hdShared.EDeviceType.Pro && semver__default["default"].gte(firmwareVersion, '4.15.0');
39256
39222
  const getPassphraseState = (device, options) => __awaiter(void 0, void 0, void 0, function* () {
39257
39223
  var _c;
39258
39224
  const { features, commands } = device;
39259
- if (!features && !device.profile)
39225
+ if (!features)
39260
39226
  return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
39261
39227
  const firmwareVersion = (_c = device.getCurrentFirmwareVersionString()) !== null && _c !== void 0 ? _c : '0.0.0';
39262
39228
  const deviceType = device.getCurrentDeviceType();
@@ -39377,11 +39343,8 @@ function fixVersion(version) {
39377
39343
  }
39378
39344
  const fixFeaturesFirmwareVersion = (features) => {
39379
39345
  const tempFeatures = Object.assign({}, features);
39380
- if (tempFeatures.onekey_firmware_version && !semver__default["default"].valid(tempFeatures.onekey_firmware_version)) {
39381
- tempFeatures.onekey_firmware_version = fixVersion(tempFeatures.onekey_firmware_version);
39382
- }
39383
- if (tempFeatures.onekey_version && !semver__default["default"].valid(tempFeatures.onekey_version)) {
39384
- tempFeatures.onekey_version = fixVersion(tempFeatures.onekey_version);
39346
+ if (tempFeatures.firmwareVersion && !semver__default["default"].valid(tempFeatures.firmwareVersion)) {
39347
+ tempFeatures.firmwareVersion = fixVersion(tempFeatures.firmwareVersion);
39385
39348
  }
39386
39349
  return tempFeatures;
39387
39350
  };
@@ -39510,9 +39473,10 @@ function shouldUpdateBootloaderForClassicAndMini({ currentVersion, bootloaderVer
39510
39473
  function isEnteredManuallyBoot(features, updateType) {
39511
39474
  const deviceType = getDeviceType(features);
39512
39475
  const isMini = deviceType === hdShared.EDeviceType.Mini;
39476
+ const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
39513
39477
  const isBoot183ClassicUpBle = updateType === 'firmware' &&
39514
39478
  deviceType === hdShared.EDeviceType.Classic &&
39515
- features.bootloader_version === '1.8.3';
39479
+ bootloaderVersion === '1.8.3';
39516
39480
  return isMini || isBoot183ClassicUpBle;
39517
39481
  }
39518
39482
 
@@ -39971,20 +39935,20 @@ const wait = (ms) => new Promise(resolve => {
39971
39935
  const findDefectiveBatchDevice = (features) => {
39972
39936
  if (!features)
39973
39937
  return;
39974
- const { onekey_serial: onekeySerial, se_ver: seVer } = features;
39975
- if (!onekeySerial)
39938
+ const { serialNo, seVersion } = features;
39939
+ if (!serialNo)
39976
39940
  return;
39977
- const versionNum = +onekeySerial.slice(5);
39941
+ const versionNum = +serialNo.slice(5);
39978
39942
  if (Number.isNaN(versionNum))
39979
39943
  return;
39980
- return versionNum >= 21032200001 && versionNum <= 21032201500 && seVer === '1.1.0.2';
39944
+ return versionNum >= 21032200001 && versionNum <= 21032201500 && seVersion === '1.1.0.2';
39981
39945
  };
39982
39946
  const getDefectiveDeviceInfo = (features) => {
39983
39947
  if (!findDefectiveBatchDevice(features))
39984
39948
  return null;
39985
39949
  const serialNo = getDeviceUUID(features);
39986
39950
  const deviceType = getDeviceType(features);
39987
- const seVersion = features.se_ver;
39951
+ const { seVersion } = features;
39988
39952
  return {
39989
39953
  serialNo,
39990
39954
  seVersion,
@@ -40296,12 +40260,11 @@ class DevicePool extends events.exports {
40296
40260
  });
40297
40261
  }
40298
40262
  static _sendConnectMessage(initOptions) {
40299
- var _a;
40300
40263
  return __awaiter(this, void 0, void 0, function* () {
40301
40264
  for (let i = this.connectedPool.length - 1; i >= 0; i--) {
40302
40265
  const descriptor = this.connectedPool[i];
40303
40266
  const device = yield this._createDevice(descriptor, initOptions);
40304
- Log$f.debug('emit DEVICE.CONNECT: ', (_a = device === null || device === void 0 ? void 0 : device.profile) !== null && _a !== void 0 ? _a : device === null || device === void 0 ? void 0 : device.features);
40267
+ Log$f.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
40305
40268
  this.emitter.emit(DEVICE.CONNECT, device);
40306
40269
  this.connectedPool.splice(i, 1);
40307
40270
  }
@@ -40328,24 +40291,22 @@ class DevicePool extends events.exports {
40328
40291
  return;
40329
40292
  }
40330
40293
  diff.connected.forEach(d => {
40331
- var _a;
40332
40294
  const device = this.getDeviceByPath(d.path);
40333
40295
  if (!device) {
40334
40296
  this._addConnectedDeviceToPool(d);
40335
40297
  return;
40336
40298
  }
40337
- Log$f.debug('emit DEVICE.CONNECT: ', (_a = device.profile) !== null && _a !== void 0 ? _a : device.features);
40299
+ Log$f.debug('emit DEVICE.CONNECT: ', device.features);
40338
40300
  this.emitter.emit(DEVICE.CONNECT, device);
40339
40301
  });
40340
40302
  diff.disconnected.forEach(d => {
40341
- var _a;
40342
40303
  this._removeDeviceFromConnectedPool(d.path);
40343
40304
  const device = this.getDeviceByPath(d.path);
40344
40305
  if (!device) {
40345
40306
  this._addDisconnectedDeviceToPool(d);
40346
40307
  return;
40347
40308
  }
40348
- Log$f.debug('emit DEVICE.DISCONNECT: ', (_a = device.profile) !== null && _a !== void 0 ? _a : device.features);
40309
+ Log$f.debug('emit DEVICE.DISCONNECT: ', device.features);
40349
40310
  this.emitter.emit(DEVICE.DISCONNECT, device);
40350
40311
  });
40351
40312
  }
@@ -41079,28 +41040,6 @@ class DeviceCommands {
41079
41040
  }
41080
41041
  }
41081
41042
 
41082
- const normalizeEnumValue = (enumObject, value) => {
41083
- if (value == null)
41084
- return null;
41085
- if (typeof value === 'string')
41086
- return value;
41087
- const label = enumObject[value];
41088
- return typeof label === 'string' ? label : null;
41089
- };
41090
- const getProtocolV2SeState = (se) => {
41091
- const label = normalizeEnumValue(hdTransport.DevSEState, se === null || se === void 0 ? void 0 : se.state);
41092
- switch (label) {
41093
- case 'BOOT':
41094
- return 'BOOT';
41095
- case 'APP_FACTORY':
41096
- return 'APP_FACTORY';
41097
- case 'APP':
41098
- return 'APP';
41099
- default:
41100
- return null;
41101
- }
41102
- };
41103
- const getProtocolV2SeType = (se) => normalizeEnumValue(hdTransport.DevSeType, se === null || se === void 0 ? void 0 : se.type);
41104
41043
  const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
41105
41044
  targets: {
41106
41045
  hw: true,
@@ -41185,14 +41124,14 @@ function requestProtocolV2DeviceInfo({ commands, timeoutMs = PROTOCOL_V2_DEVICE_
41185
41124
  }
41186
41125
 
41187
41126
  const isMeaningfulVersion = (version) => Boolean(version && version !== '0.0.0');
41188
- const firstVersion = (...versions) => { var _a; return (_a = versions.find(isMeaningfulVersion)) !== null && _a !== void 0 ? _a : null; };
41127
+ const firstMeaningfulVersion$1 = (...versions) => { var _a; return (_a = versions.find(isMeaningfulVersion)) !== null && _a !== void 0 ? _a : null; };
41189
41128
  const versionArrayToString = (version) => {
41190
41129
  if (!version || version.length === 0)
41191
41130
  return null;
41192
41131
  const value = version.join('.');
41193
41132
  return isMeaningfulVersion(value) ? value : null;
41194
41133
  };
41195
- const bytesToHex$1 = (value) => {
41134
+ const bytesToHex$2 = (value) => {
41196
41135
  if (!value)
41197
41136
  return undefined;
41198
41137
  if (typeof value === 'string')
@@ -41207,14 +41146,14 @@ const bytesToHex$1 = (value) => {
41207
41146
  }
41208
41147
  return undefined;
41209
41148
  };
41210
- const getImageVersion = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : null; };
41211
- const getImageBuildId = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
41212
- const getImageHash = (image) => bytesToHex$1(image === null || image === void 0 ? void 0 : image.hash);
41149
+ const getImageVersion$1 = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : null; };
41150
+ const getImageBuildId$1 = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
41151
+ const getImageHash$1 = (image) => bytesToHex$2(image === null || image === void 0 ? void 0 : image.hash);
41213
41152
  const shouldIncludeVerify = (scope) => scope === 'verify' || scope === 'full';
41214
41153
  const getDeviceMode = (features) => {
41215
41154
  if (!features)
41216
41155
  return 'unknown';
41217
- if (features.bootloader_mode === true)
41156
+ if (features.bootloaderMode === true)
41218
41157
  return 'bootloader';
41219
41158
  if (features.initialized === false)
41220
41159
  return 'notInitialized';
@@ -41231,35 +41170,35 @@ const getProtocolV2Mode = (deviceInfo) => {
41231
41170
  return 'normal';
41232
41171
  return 'unknown';
41233
41172
  };
41234
- const normalizeV1Versions = (features, onekeyFeatures) => ({
41235
- firmware: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_firmware_version, versionArrayToString(getDeviceFirmwareVersion(features))),
41236
- bootloader: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_boot_version, versionArrayToString(getDeviceBootloaderVersion(features))),
41237
- board: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_board_version, versionArrayToString(features ? getDeviceBoardloaderVersion(features) : undefined)),
41238
- ble: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_ble_version, features === null || features === void 0 ? void 0 : features.onekey_ble_version, features === null || features === void 0 ? void 0 : features.ble_ver, versionArrayToString(features ? getDeviceBLEFirmwareVersion(features) : undefined)),
41239
- se01: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se01_version, features === null || features === void 0 ? void 0 : features.onekey_se01_version),
41240
- se02: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se02_version, features === null || features === void 0 ? void 0 : features.onekey_se02_version),
41241
- se03: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se03_version, features === null || features === void 0 ? void 0 : features.onekey_se03_version),
41242
- se04: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se04_version, features === null || features === void 0 ? void 0 : features.onekey_se04_version),
41243
- se01Boot: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se01_boot_version, features === null || features === void 0 ? void 0 : features.onekey_se01_boot_version),
41244
- se02Boot: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se02_boot_version, features === null || features === void 0 ? void 0 : features.onekey_se02_boot_version),
41245
- se03Boot: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se03_boot_version, features === null || features === void 0 ? void 0 : features.onekey_se03_boot_version),
41246
- se04Boot: firstVersion(onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se04_boot_version, features === null || features === void 0 ? void 0 : features.onekey_se04_boot_version),
41173
+ const normalizeV1Versions = (features, protocolV1OneKeyFeatures) => ({
41174
+ firmware: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_firmware_version, versionArrayToString(getDeviceFirmwareVersion(features))),
41175
+ bootloader: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_boot_version, versionArrayToString(getDeviceBootloaderVersion(features))),
41176
+ board: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_board_version, versionArrayToString(features ? getDeviceBoardloaderVersion(features) : undefined)),
41177
+ ble: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_ble_version, features === null || features === void 0 ? void 0 : features.bleVersion, versionArrayToString(features ? getDeviceBLEFirmwareVersion(features) : undefined)),
41178
+ se01: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_version, features === null || features === void 0 ? void 0 : features.se01Version),
41179
+ se02: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_version, features === null || features === void 0 ? void 0 : features.se02Version),
41180
+ se03: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_version, features === null || features === void 0 ? void 0 : features.se03Version),
41181
+ se04: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_version, features === null || features === void 0 ? void 0 : features.se04Version),
41182
+ se01Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_boot_version, features === null || features === void 0 ? void 0 : features.se01BootVersion),
41183
+ se02Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_boot_version, features === null || features === void 0 ? void 0 : features.se02BootVersion),
41184
+ se03Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_boot_version, features === null || features === void 0 ? void 0 : features.se03BootVersion),
41185
+ se04Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_boot_version, features === null || features === void 0 ? void 0 : features.se04BootVersion),
41247
41186
  });
41248
41187
  const normalizeV2Versions = (deviceInfo) => {
41249
41188
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
41250
41189
  return ({
41251
- firmware: firstVersion(getImageVersion((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.app)),
41252
- bootloader: firstVersion(getImageVersion((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.boot)),
41253
- board: firstVersion(getImageVersion((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.board)),
41254
- ble: firstVersion(getImageVersion((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _d === void 0 ? void 0 : _d.app)),
41255
- se01: firstVersion(getImageVersion((_e = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _e === void 0 ? void 0 : _e.app)),
41256
- se02: firstVersion(getImageVersion((_f = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _f === void 0 ? void 0 : _f.app)),
41257
- se03: firstVersion(getImageVersion((_g = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _g === void 0 ? void 0 : _g.app)),
41258
- se04: firstVersion(getImageVersion((_h = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _h === void 0 ? void 0 : _h.app)),
41259
- se01Boot: firstVersion(getImageVersion((_j = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _j === void 0 ? void 0 : _j.boot)),
41260
- se02Boot: firstVersion(getImageVersion((_k = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _k === void 0 ? void 0 : _k.boot)),
41261
- se03Boot: firstVersion(getImageVersion((_l = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _l === void 0 ? void 0 : _l.boot)),
41262
- se04Boot: firstVersion(getImageVersion((_m = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _m === void 0 ? void 0 : _m.boot)),
41190
+ firmware: firstMeaningfulVersion$1(getImageVersion$1((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.app)),
41191
+ bootloader: firstMeaningfulVersion$1(getImageVersion$1((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.boot)),
41192
+ board: firstMeaningfulVersion$1(getImageVersion$1((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.board)),
41193
+ ble: firstMeaningfulVersion$1(getImageVersion$1((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _d === void 0 ? void 0 : _d.app)),
41194
+ se01: firstMeaningfulVersion$1(getImageVersion$1((_e = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _e === void 0 ? void 0 : _e.app)),
41195
+ se02: firstMeaningfulVersion$1(getImageVersion$1((_f = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _f === void 0 ? void 0 : _f.app)),
41196
+ se03: firstMeaningfulVersion$1(getImageVersion$1((_g = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _g === void 0 ? void 0 : _g.app)),
41197
+ se04: firstMeaningfulVersion$1(getImageVersion$1((_h = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _h === void 0 ? void 0 : _h.app)),
41198
+ se01Boot: firstMeaningfulVersion$1(getImageVersion$1((_j = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _j === void 0 ? void 0 : _j.boot)),
41199
+ se02Boot: firstMeaningfulVersion$1(getImageVersion$1((_k = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _k === void 0 ? void 0 : _k.boot)),
41200
+ se03Boot: firstMeaningfulVersion$1(getImageVersion$1((_l = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _l === void 0 ? void 0 : _l.boot)),
41201
+ se04Boot: firstMeaningfulVersion$1(getImageVersion$1((_m = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _m === void 0 ? void 0 : _m.boot)),
41263
41202
  });
41264
41203
  };
41265
41204
  const normalizeV1Status = (features) => {
@@ -41267,13 +41206,13 @@ const normalizeV1Status = (features) => {
41267
41206
  return ({
41268
41207
  mode: getDeviceMode(features),
41269
41208
  initialized: (_a = features === null || features === void 0 ? void 0 : features.initialized) !== null && _a !== void 0 ? _a : null,
41270
- bootloaderMode: (_b = features === null || features === void 0 ? void 0 : features.bootloader_mode) !== null && _b !== void 0 ? _b : null,
41209
+ bootloaderMode: (_b = features === null || features === void 0 ? void 0 : features.bootloaderMode) !== null && _b !== void 0 ? _b : null,
41271
41210
  unlocked: (_c = features === null || features === void 0 ? void 0 : features.unlocked) !== null && _c !== void 0 ? _c : null,
41272
- passphraseProtection: (_d = features === null || features === void 0 ? void 0 : features.passphrase_protection) !== null && _d !== void 0 ? _d : null,
41273
- backupRequired: (_e = features === null || features === void 0 ? void 0 : features.needs_backup) !== null && _e !== void 0 ? _e : null,
41274
- noBackup: (_f = features === null || features === void 0 ? void 0 : features.no_backup) !== null && _f !== void 0 ? _f : null,
41211
+ passphraseProtection: (_d = features === null || features === void 0 ? void 0 : features.passphraseProtection) !== null && _d !== void 0 ? _d : null,
41212
+ backupRequired: (_e = features === null || features === void 0 ? void 0 : features.backupRequired) !== null && _e !== void 0 ? _e : null,
41213
+ noBackup: (_f = features === null || features === void 0 ? void 0 : features.noBackup) !== null && _f !== void 0 ? _f : null,
41275
41214
  language: (_g = features === null || features === void 0 ? void 0 : features.language) !== null && _g !== void 0 ? _g : null,
41276
- bleEnabled: (_h = features === null || features === void 0 ? void 0 : features.ble_enable) !== null && _h !== void 0 ? _h : null,
41215
+ bleEnabled: (_h = features === null || features === void 0 ? void 0 : features.bleEnabled) !== null && _h !== void 0 ? _h : null,
41277
41216
  });
41278
41217
  };
41279
41218
  const normalizeV2Status = (deviceInfo) => {
@@ -41290,109 +41229,85 @@ const normalizeV2Status = (deviceInfo) => {
41290
41229
  bleEnabled: (_k = (_j = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _j === void 0 ? void 0 : _j.bt_enable) !== null && _k !== void 0 ? _k : null,
41291
41230
  });
41292
41231
  };
41293
- const normalizeV1Verify = (features, onekeyFeatures) => {
41294
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
41232
+ const normalizeV1Verify = (features, protocolV1OneKeyFeatures) => {
41233
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23;
41295
41234
  return ({
41296
- firmwareBuildId: (_a = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_firmware_build_id) !== null && _a !== void 0 ? _a : features === null || features === void 0 ? void 0 : features.onekey_firmware_build_id,
41297
- firmwareHash: (_b = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_firmware_hash) !== null && _b !== void 0 ? _b : features === null || features === void 0 ? void 0 : features.onekey_firmware_hash,
41298
- bootloaderBuildId: (_c = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_boot_build_id) !== null && _c !== void 0 ? _c : features === null || features === void 0 ? void 0 : features.onekey_boot_build_id,
41299
- bootloaderHash: (_d = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_boot_hash) !== null && _d !== void 0 ? _d : features === null || features === void 0 ? void 0 : features.onekey_boot_hash,
41300
- boardBuildId: (_e = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_board_build_id) !== null && _e !== void 0 ? _e : features === null || features === void 0 ? void 0 : features.onekey_board_build_id,
41301
- boardHash: (_f = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_board_hash) !== null && _f !== void 0 ? _f : features === null || features === void 0 ? void 0 : features.onekey_board_hash,
41302
- bleBuildId: (_g = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_ble_build_id) !== null && _g !== void 0 ? _g : features === null || features === void 0 ? void 0 : features.onekey_ble_build_id,
41303
- bleHash: (_h = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_ble_hash) !== null && _h !== void 0 ? _h : features === null || features === void 0 ? void 0 : features.onekey_ble_hash,
41304
- se01BuildId: (_j = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se01_build_id) !== null && _j !== void 0 ? _j : features === null || features === void 0 ? void 0 : features.onekey_se01_build_id,
41305
- se01Hash: (_k = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se01_hash) !== null && _k !== void 0 ? _k : features === null || features === void 0 ? void 0 : features.onekey_se01_hash,
41306
- se02BuildId: (_l = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se02_build_id) !== null && _l !== void 0 ? _l : features === null || features === void 0 ? void 0 : features.onekey_se02_build_id,
41307
- se02Hash: (_m = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se02_hash) !== null && _m !== void 0 ? _m : features === null || features === void 0 ? void 0 : features.onekey_se02_hash,
41308
- se03BuildId: (_o = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se03_build_id) !== null && _o !== void 0 ? _o : features === null || features === void 0 ? void 0 : features.onekey_se03_build_id,
41309
- se03Hash: (_p = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se03_hash) !== null && _p !== void 0 ? _p : features === null || features === void 0 ? void 0 : features.onekey_se03_hash,
41310
- se04BuildId: (_q = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se04_build_id) !== null && _q !== void 0 ? _q : features === null || features === void 0 ? void 0 : features.onekey_se04_build_id,
41311
- se04Hash: (_r = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se04_hash) !== null && _r !== void 0 ? _r : features === null || features === void 0 ? void 0 : features.onekey_se04_hash,
41312
- se01BootBuildId: (_s = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se01_boot_build_id) !== null && _s !== void 0 ? _s : features === null || features === void 0 ? void 0 : features.onekey_se01_boot_build_id,
41313
- se01BootHash: (_t = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se01_boot_hash) !== null && _t !== void 0 ? _t : features === null || features === void 0 ? void 0 : features.onekey_se01_boot_hash,
41314
- se02BootBuildId: (_u = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se02_boot_build_id) !== null && _u !== void 0 ? _u : features === null || features === void 0 ? void 0 : features.onekey_se02_boot_build_id,
41315
- se02BootHash: (_v = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se02_boot_hash) !== null && _v !== void 0 ? _v : features === null || features === void 0 ? void 0 : features.onekey_se02_boot_hash,
41316
- se03BootBuildId: (_w = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se03_boot_build_id) !== null && _w !== void 0 ? _w : features === null || features === void 0 ? void 0 : features.onekey_se03_boot_build_id,
41317
- se03BootHash: (_x = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se03_boot_hash) !== null && _x !== void 0 ? _x : features === null || features === void 0 ? void 0 : features.onekey_se03_boot_hash,
41318
- se04BootBuildId: (_y = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se04_boot_build_id) !== null && _y !== void 0 ? _y : features === null || features === void 0 ? void 0 : features.onekey_se04_boot_build_id,
41319
- se04BootHash: (_z = onekeyFeatures === null || onekeyFeatures === void 0 ? void 0 : onekeyFeatures.onekey_se04_boot_hash) !== null && _z !== void 0 ? _z : features === null || features === void 0 ? void 0 : features.onekey_se04_boot_hash,
41235
+ firmwareBuildId: (_a = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_firmware_build_id) !== null && _a !== void 0 ? _a : (_b = features === null || features === void 0 ? void 0 : features.verify) === null || _b === void 0 ? void 0 : _b.firmwareBuildId,
41236
+ firmwareHash: (_c = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_firmware_hash) !== null && _c !== void 0 ? _c : (_d = features === null || features === void 0 ? void 0 : features.verify) === null || _d === void 0 ? void 0 : _d.firmwareHash,
41237
+ bootloaderBuildId: (_e = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_boot_build_id) !== null && _e !== void 0 ? _e : (_f = features === null || features === void 0 ? void 0 : features.verify) === null || _f === void 0 ? void 0 : _f.bootloaderBuildId,
41238
+ bootloaderHash: (_g = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_boot_hash) !== null && _g !== void 0 ? _g : (_h = features === null || features === void 0 ? void 0 : features.verify) === null || _h === void 0 ? void 0 : _h.bootloaderHash,
41239
+ boardBuildId: (_j = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_board_build_id) !== null && _j !== void 0 ? _j : (_k = features === null || features === void 0 ? void 0 : features.verify) === null || _k === void 0 ? void 0 : _k.boardBuildId,
41240
+ boardHash: (_l = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_board_hash) !== null && _l !== void 0 ? _l : (_m = features === null || features === void 0 ? void 0 : features.verify) === null || _m === void 0 ? void 0 : _m.boardHash,
41241
+ bleBuildId: (_o = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_ble_build_id) !== null && _o !== void 0 ? _o : (_p = features === null || features === void 0 ? void 0 : features.verify) === null || _p === void 0 ? void 0 : _p.bleBuildId,
41242
+ bleHash: (_q = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_ble_hash) !== null && _q !== void 0 ? _q : (_r = features === null || features === void 0 ? void 0 : features.verify) === null || _r === void 0 ? void 0 : _r.bleHash,
41243
+ se01BuildId: (_s = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_build_id) !== null && _s !== void 0 ? _s : (_t = features === null || features === void 0 ? void 0 : features.verify) === null || _t === void 0 ? void 0 : _t.se01BuildId,
41244
+ se01Hash: (_u = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_hash) !== null && _u !== void 0 ? _u : (_v = features === null || features === void 0 ? void 0 : features.verify) === null || _v === void 0 ? void 0 : _v.se01Hash,
41245
+ se02BuildId: (_w = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_build_id) !== null && _w !== void 0 ? _w : (_x = features === null || features === void 0 ? void 0 : features.verify) === null || _x === void 0 ? void 0 : _x.se02BuildId,
41246
+ se02Hash: (_y = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_hash) !== null && _y !== void 0 ? _y : (_z = features === null || features === void 0 ? void 0 : features.verify) === null || _z === void 0 ? void 0 : _z.se02Hash,
41247
+ se03BuildId: (_0 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_build_id) !== null && _0 !== void 0 ? _0 : (_1 = features === null || features === void 0 ? void 0 : features.verify) === null || _1 === void 0 ? void 0 : _1.se03BuildId,
41248
+ se03Hash: (_2 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_hash) !== null && _2 !== void 0 ? _2 : (_3 = features === null || features === void 0 ? void 0 : features.verify) === null || _3 === void 0 ? void 0 : _3.se03Hash,
41249
+ se04BuildId: (_4 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_build_id) !== null && _4 !== void 0 ? _4 : (_5 = features === null || features === void 0 ? void 0 : features.verify) === null || _5 === void 0 ? void 0 : _5.se04BuildId,
41250
+ se04Hash: (_6 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_hash) !== null && _6 !== void 0 ? _6 : (_7 = features === null || features === void 0 ? void 0 : features.verify) === null || _7 === void 0 ? void 0 : _7.se04Hash,
41251
+ se01BootBuildId: (_8 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_boot_build_id) !== null && _8 !== void 0 ? _8 : (_9 = features === null || features === void 0 ? void 0 : features.verify) === null || _9 === void 0 ? void 0 : _9.se01BootBuildId,
41252
+ se01BootHash: (_10 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_boot_hash) !== null && _10 !== void 0 ? _10 : (_11 = features === null || features === void 0 ? void 0 : features.verify) === null || _11 === void 0 ? void 0 : _11.se01BootHash,
41253
+ se02BootBuildId: (_12 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_boot_build_id) !== null && _12 !== void 0 ? _12 : (_13 = features === null || features === void 0 ? void 0 : features.verify) === null || _13 === void 0 ? void 0 : _13.se02BootBuildId,
41254
+ se02BootHash: (_14 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_boot_hash) !== null && _14 !== void 0 ? _14 : (_15 = features === null || features === void 0 ? void 0 : features.verify) === null || _15 === void 0 ? void 0 : _15.se02BootHash,
41255
+ se03BootBuildId: (_16 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_boot_build_id) !== null && _16 !== void 0 ? _16 : (_17 = features === null || features === void 0 ? void 0 : features.verify) === null || _17 === void 0 ? void 0 : _17.se03BootBuildId,
41256
+ se03BootHash: (_18 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_boot_hash) !== null && _18 !== void 0 ? _18 : (_19 = features === null || features === void 0 ? void 0 : features.verify) === null || _19 === void 0 ? void 0 : _19.se03BootHash,
41257
+ se04BootBuildId: (_20 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_boot_build_id) !== null && _20 !== void 0 ? _20 : (_21 = features === null || features === void 0 ? void 0 : features.verify) === null || _21 === void 0 ? void 0 : _21.se04BootBuildId,
41258
+ se04BootHash: (_22 = protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_boot_hash) !== null && _22 !== void 0 ? _22 : (_23 = features === null || features === void 0 ? void 0 : features.verify) === null || _23 === void 0 ? void 0 : _23.se04BootHash,
41320
41259
  });
41321
41260
  };
41322
41261
  const normalizeV2Verify = (deviceInfo) => {
41323
41262
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
41324
41263
  return ({
41325
- firmwareBuildId: getImageBuildId((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.app),
41326
- firmwareHash: getImageHash((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.app),
41327
- bootloaderBuildId: getImageBuildId((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.boot),
41328
- bootloaderHash: getImageHash((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _d === void 0 ? void 0 : _d.boot),
41329
- boardBuildId: getImageBuildId((_e = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _e === void 0 ? void 0 : _e.board),
41330
- boardHash: getImageHash((_f = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _f === void 0 ? void 0 : _f.board),
41331
- bleBuildId: getImageBuildId((_g = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _g === void 0 ? void 0 : _g.app),
41332
- bleHash: getImageHash((_h = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _h === void 0 ? void 0 : _h.app),
41333
- se01BuildId: getImageBuildId((_j = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _j === void 0 ? void 0 : _j.app),
41334
- se01Hash: getImageHash((_k = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _k === void 0 ? void 0 : _k.app),
41335
- se02BuildId: getImageBuildId((_l = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _l === void 0 ? void 0 : _l.app),
41336
- se02Hash: getImageHash((_m = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _m === void 0 ? void 0 : _m.app),
41337
- se03BuildId: getImageBuildId((_o = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _o === void 0 ? void 0 : _o.app),
41338
- se03Hash: getImageHash((_p = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _p === void 0 ? void 0 : _p.app),
41339
- se04BuildId: getImageBuildId((_q = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _q === void 0 ? void 0 : _q.app),
41340
- se04Hash: getImageHash((_r = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _r === void 0 ? void 0 : _r.app),
41341
- se01BootBuildId: getImageBuildId((_s = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _s === void 0 ? void 0 : _s.boot),
41342
- se01BootHash: getImageHash((_t = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _t === void 0 ? void 0 : _t.boot),
41343
- se02BootBuildId: getImageBuildId((_u = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _u === void 0 ? void 0 : _u.boot),
41344
- se02BootHash: getImageHash((_v = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _v === void 0 ? void 0 : _v.boot),
41345
- se03BootBuildId: getImageBuildId((_w = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _w === void 0 ? void 0 : _w.boot),
41346
- se03BootHash: getImageHash((_x = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _x === void 0 ? void 0 : _x.boot),
41347
- se04BootBuildId: getImageBuildId((_y = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _y === void 0 ? void 0 : _y.boot),
41348
- se04BootHash: getImageHash((_z = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _z === void 0 ? void 0 : _z.boot),
41264
+ firmwareBuildId: getImageBuildId$1((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.app),
41265
+ firmwareHash: getImageHash$1((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.app),
41266
+ bootloaderBuildId: getImageBuildId$1((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.boot),
41267
+ bootloaderHash: getImageHash$1((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _d === void 0 ? void 0 : _d.boot),
41268
+ boardBuildId: getImageBuildId$1((_e = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _e === void 0 ? void 0 : _e.board),
41269
+ boardHash: getImageHash$1((_f = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _f === void 0 ? void 0 : _f.board),
41270
+ bleBuildId: getImageBuildId$1((_g = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _g === void 0 ? void 0 : _g.app),
41271
+ bleHash: getImageHash$1((_h = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _h === void 0 ? void 0 : _h.app),
41272
+ se01BuildId: getImageBuildId$1((_j = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _j === void 0 ? void 0 : _j.app),
41273
+ se01Hash: getImageHash$1((_k = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _k === void 0 ? void 0 : _k.app),
41274
+ se02BuildId: getImageBuildId$1((_l = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _l === void 0 ? void 0 : _l.app),
41275
+ se02Hash: getImageHash$1((_m = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _m === void 0 ? void 0 : _m.app),
41276
+ se03BuildId: getImageBuildId$1((_o = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _o === void 0 ? void 0 : _o.app),
41277
+ se03Hash: getImageHash$1((_p = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _p === void 0 ? void 0 : _p.app),
41278
+ se04BuildId: getImageBuildId$1((_q = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _q === void 0 ? void 0 : _q.app),
41279
+ se04Hash: getImageHash$1((_r = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _r === void 0 ? void 0 : _r.app),
41280
+ se01BootBuildId: getImageBuildId$1((_s = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _s === void 0 ? void 0 : _s.boot),
41281
+ se01BootHash: getImageHash$1((_t = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _t === void 0 ? void 0 : _t.boot),
41282
+ se02BootBuildId: getImageBuildId$1((_u = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _u === void 0 ? void 0 : _u.boot),
41283
+ se02BootHash: getImageHash$1((_v = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _v === void 0 ? void 0 : _v.boot),
41284
+ se03BootBuildId: getImageBuildId$1((_w = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _w === void 0 ? void 0 : _w.boot),
41285
+ se03BootHash: getImageHash$1((_x = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _x === void 0 ? void 0 : _x.boot),
41286
+ se04BootBuildId: getImageBuildId$1((_y = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _y === void 0 ? void 0 : _y.boot),
41287
+ se04BootHash: getImageHash$1((_z = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _z === void 0 ? void 0 : _z.boot),
41349
41288
  });
41350
41289
  };
41351
- const normalizeRaw = ({ features, onekeyFeatures, protocolV2DeviceInfo, }) => (Object.assign(Object.assign(Object.assign({}, (features ? { features } : {})), (onekeyFeatures ? { onekeyFeatures } : {})), (protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {})));
41352
- const mergeV1Features = (features, onekeyFeatures) => {
41353
- if (!features && !onekeyFeatures)
41354
- return undefined;
41355
- const _a = onekeyFeatures !== null && onekeyFeatures !== void 0 ? onekeyFeatures : {}, { onekey_device_type: onekeyDeviceType, onekey_se_type: onekeySeType, onekey_se01_state: onekeySe01State, onekey_se02_state: onekeySe02State, onekey_se03_state: onekeySe03State, onekey_se04_state: onekeySe04State } = _a, restOnekeyFeatures = __rest(_a, ["onekey_device_type", "onekey_se_type", "onekey_se01_state", "onekey_se02_state", "onekey_se03_state", "onekey_se04_state"]);
41356
- const toEnumName = (enumObject, value) => {
41357
- if (value == null || typeof value === 'string')
41358
- return value;
41359
- const label = enumObject[value];
41360
- return typeof label === 'string' ? label : String(value);
41361
- };
41362
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (features !== null && features !== void 0 ? features : {})), restOnekeyFeatures), (onekeyDeviceType !== undefined
41363
- ? { onekey_device_type: toEnumName(hdTransport.OneKeyDeviceType, onekeyDeviceType) }
41364
- : {})), (onekeySeType !== undefined
41365
- ? { onekey_se_type: toEnumName(hdTransport.OneKeySeType, onekeySeType) }
41366
- : {})), (onekeySe01State !== undefined
41367
- ? { onekey_se01_state: toEnumName(hdTransport.OneKeySEState, onekeySe01State) }
41368
- : {})), (onekeySe02State !== undefined
41369
- ? { onekey_se02_state: toEnumName(hdTransport.OneKeySEState, onekeySe02State) }
41370
- : {})), (onekeySe03State !== undefined
41371
- ? { onekey_se03_state: toEnumName(hdTransport.OneKeySEState, onekeySe03State) }
41372
- : {})), (onekeySe04State !== undefined
41373
- ? { onekey_se04_state: toEnumName(hdTransport.OneKeySEState, onekeySe04State) }
41374
- : {}));
41375
- };
41376
- function buildProfileFromProtocolV1({ protocol = 'V1', features, onekeyFeatures, sources = ['features'], scope = 'basic', includeRaw = false, }) {
41377
- const sourceFeatures = mergeV1Features(features, onekeyFeatures);
41378
- const verify = normalizeV1Verify(sourceFeatures, onekeyFeatures);
41290
+ const normalizeRaw = ({ features, protocolV1OneKeyFeatures, protocolV2DeviceInfo, }) => (Object.assign(Object.assign(Object.assign({}, (features ? { features } : {})), (protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {})), (protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {})));
41291
+ function buildProfileFromProtocolV1({ protocol = 'V1', features, protocolV1OneKeyFeatures, sources = ['features'], scope = 'basic', includeRaw = false, }) {
41292
+ const sourceFeatures = features;
41293
+ const verify = normalizeV1Verify(sourceFeatures, protocolV1OneKeyFeatures);
41379
41294
  return Object.assign(Object.assign({ protocol,
41380
- sources, deviceType: getDeviceType(sourceFeatures), firmwareType: getFirmwareType(sourceFeatures), deviceId: (sourceFeatures === null || sourceFeatures === void 0 ? void 0 : sourceFeatures.device_id) || (sourceFeatures ? getDeviceUUID(sourceFeatures) : ''), serialNo: sourceFeatures ? getDeviceUUID(sourceFeatures) : '', label: getDeviceLabel(sourceFeatures), bleName: getDeviceBleName(sourceFeatures), status: normalizeV1Status(sourceFeatures), versions: normalizeV1Versions(sourceFeatures, onekeyFeatures) }, (shouldIncludeVerify(scope) ? { verify } : {})), (includeRaw
41295
+ sources, deviceType: getDeviceType(sourceFeatures), firmwareType: getFirmwareType(sourceFeatures), deviceId: (sourceFeatures === null || sourceFeatures === void 0 ? void 0 : sourceFeatures.deviceId) || (sourceFeatures ? getDeviceUUID(sourceFeatures) : ''), serialNo: sourceFeatures ? getDeviceUUID(sourceFeatures) : '', label: getDeviceLabel(sourceFeatures), bleName: getDeviceBleName(sourceFeatures), status: normalizeV1Status(sourceFeatures), versions: normalizeV1Versions(sourceFeatures, protocolV1OneKeyFeatures) }, (shouldIncludeVerify(scope) ? { verify } : {})), (includeRaw
41381
41296
  ? {
41382
41297
  raw: normalizeRaw({
41383
41298
  features,
41384
- onekeyFeatures,
41299
+ protocolV1OneKeyFeatures,
41385
41300
  }),
41386
41301
  }
41387
41302
  : {}));
41388
41303
  }
41389
- function buildProfileFromProtocolV2({ deviceInfo, sources = ['deviceInfo'], scope = 'basic', includeRaw = false, fallbackSerialNo, }) {
41304
+ function buildProfileFromProtocolV2({ deviceInfo, sources = ['deviceInfo'], scope = 'basic', includeRaw = false, }) {
41390
41305
  var _a, _b, _c, _d, _e;
41391
- const serialNo = ((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.hw) === null || _a === void 0 ? void 0 : _a.serial_no) || fallbackSerialNo || '';
41306
+ const serialNo = ((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.hw) === null || _a === void 0 ? void 0 : _a.serial_no) || '';
41392
41307
  const label = (_c = (_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : null;
41393
41308
  const bleName = (_e = (_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _d === void 0 ? void 0 : _d.adv_name) !== null && _e !== void 0 ? _e : null;
41394
41309
  const verify = normalizeV2Verify(deviceInfo);
41395
- return Object.assign(Object.assign({ protocol: 'V2', sources, deviceType: hdShared.EDeviceType.Pro2, firmwareType: hdShared.EFirmwareType.Universal, deviceId: serialNo, serialNo,
41310
+ return Object.assign(Object.assign({ protocol: 'V2', sources, deviceType: hdShared.EDeviceType.Pro2, firmwareType: hdShared.EFirmwareType.Universal, deviceId: '', serialNo,
41396
41311
  label,
41397
41312
  bleName, status: normalizeV2Status(deviceInfo), versions: normalizeV2Versions(deviceInfo) }, (shouldIncludeVerify(scope) ? { verify } : {})), (includeRaw
41398
41313
  ? {
@@ -41403,104 +41318,278 @@ function buildProfileFromProtocolV2({ deviceInfo, sources = ['deviceInfo'], scop
41403
41318
  : {}));
41404
41319
  }
41405
41320
 
41406
- const parseProtocolV2Version = (version) => {
41407
- if (!version)
41408
- return [0, 0, 0];
41409
- const [major = 0, minor = 0, patch = 0] = version.split('.').map(part => Number(part) || 0);
41410
- return [major, minor, patch];
41321
+ const getImageVersion = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : null; };
41322
+ const bytesToHex$1 = (value) => {
41323
+ if (!value)
41324
+ return undefined;
41325
+ if (typeof value === 'string')
41326
+ return value;
41327
+ if (value instanceof Uint8Array) {
41328
+ return Array.from(value)
41329
+ .map(byte => byte.toString(16).padStart(2, '0'))
41330
+ .join('');
41331
+ }
41332
+ if (Array.isArray(value)) {
41333
+ return value.map(byte => Number(byte).toString(16).padStart(2, '0')).join('');
41334
+ }
41335
+ return undefined;
41336
+ };
41337
+ const getImageBuildId = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
41338
+ const getImageHash = (image) => bytesToHex$1(image === null || image === void 0 ? void 0 : image.hash);
41339
+ const firstValue = (...values) => values.find(value => value !== undefined && value !== null);
41340
+ const firstMeaningfulVersion = (...versions) => { var _a; return (_a = versions.find(version => Boolean(version && version !== '0.0.0'))) !== null && _a !== void 0 ? _a : null; };
41341
+ const versionFromParts = (major, minor, patch) => [major, minor, patch].map(part => Number(part) || 0).join('.');
41342
+ const getProtocolV1Mode = (features) => {
41343
+ if (features.bootloader_mode === true)
41344
+ return 'bootloader';
41345
+ if (features.initialized === false)
41346
+ return 'notInitialized';
41347
+ if (features.initialized === true)
41348
+ return 'normal';
41349
+ return 'unknown';
41350
+ };
41351
+ const getProtocolV1DeviceType = (features) => {
41352
+ const onekeyDeviceType = features.onekey_device_type;
41353
+ switch (onekeyDeviceType) {
41354
+ case 'CLASSIC':
41355
+ return hdShared.EDeviceType.Classic;
41356
+ case 'CLASSIC1S':
41357
+ return hdShared.EDeviceType.Classic1s;
41358
+ case 'MINI':
41359
+ return hdShared.EDeviceType.Mini;
41360
+ case 'TOUCH':
41361
+ return hdShared.EDeviceType.Touch;
41362
+ case 'PRO':
41363
+ return hdShared.EDeviceType.Pro;
41364
+ case 'PRO2':
41365
+ case 'pro2':
41366
+ return hdShared.EDeviceType.Pro2;
41367
+ case 'PURE':
41368
+ return hdShared.EDeviceType.ClassicPure;
41369
+ }
41370
+ const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
41371
+ const prefix = serialNo.slice(0, 2).toLowerCase();
41372
+ if (prefix === 'bi' || prefix === 'cl')
41373
+ return hdShared.EDeviceType.Classic;
41374
+ if (prefix === 'cp')
41375
+ return hdShared.EDeviceType.ClassicPure;
41376
+ if (prefix === 'mi')
41377
+ return hdShared.EDeviceType.Mini;
41378
+ if (prefix === 'tc')
41379
+ return hdShared.EDeviceType.Touch;
41380
+ if (prefix === 'pr')
41381
+ return hdShared.EDeviceType.Pro;
41382
+ if (prefix === 'p2')
41383
+ return hdShared.EDeviceType.Pro2;
41384
+ if (!serialNo && features.bootloader_mode === true && features.model === '1') {
41385
+ return hdShared.EDeviceType.Classic;
41386
+ }
41387
+ return hdShared.EDeviceType.Unknown;
41388
+ };
41389
+ const getProtocolV1FirmwareType = (features) => {
41390
+ if (features.fw_vendor === 'OneKey Bitcoin-only')
41391
+ return hdShared.EFirmwareType.BitcoinOnly;
41392
+ return hdShared.EFirmwareType.Universal;
41393
+ };
41394
+ const getProtocolV1Label = (features, deviceType, bleName) => {
41395
+ if (features.label)
41396
+ return features.label;
41397
+ if (bleName)
41398
+ return bleName;
41399
+ if (deviceType === hdShared.EDeviceType.Unknown)
41400
+ return null;
41401
+ if (deviceType === hdShared.EDeviceType.ClassicPure)
41402
+ return 'OneKey Classic 1S';
41403
+ return `OneKey ${deviceType.charAt(0).toUpperCase()}${deviceType.slice(1)}`;
41411
41404
  };
41412
- const buildProtocolV2GetFeaturesPayload = (profile, deviceInfo) => {
41413
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17;
41414
- const firmwareVersion = profile.versions.firmware;
41415
- const [fwMajor, fwMinor, fwPatch] = parseProtocolV2Version(firmwareVersion);
41405
+ const buildProtocolV1FeaturesPayload = (protocolV1Features, previous) => {
41406
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
41407
+ const features = protocolV1Features;
41408
+ const firmwareVersion = firstMeaningfulVersion(features.onekey_firmware_version, features.onekey_version, versionFromParts(features.major_version, features.minor_version, features.patch_version));
41409
+ const bootloaderVersion = firstMeaningfulVersion(features.onekey_boot_version, features.bootloader_version, features.bootloader_mode
41410
+ ? versionFromParts(features.major_version, features.minor_version, features.patch_version)
41411
+ : null);
41412
+ const boardVersion = firstMeaningfulVersion(features.onekey_board_version, features.boardloader_version);
41413
+ const bleVersion = firstMeaningfulVersion(features.onekey_ble_version, features.ble_ver);
41414
+ const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
41415
+ const bleName = features.onekey_ble_name || features.ble_name || null;
41416
+ const deviceType = getProtocolV1DeviceType(features);
41417
+ const sessionId = (_b = (_a = features.session_id) !== null && _a !== void 0 ? _a : previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _b !== void 0 ? _b : null;
41416
41418
  return {
41417
- vendor: 'onekey.so',
41418
- major_version: fwMajor,
41419
- minor_version: fwMinor,
41420
- patch_version: fwPatch,
41421
- bootloader_mode: false,
41422
- device_id: profile.deviceId,
41423
- pin_protection: null,
41424
- passphrase_protection: profile.status.passphraseProtection,
41425
- language: profile.status.language,
41426
- label: profile.label,
41427
- initialized: (_a = profile.status.initialized) !== null && _a !== void 0 ? _a : false,
41428
- revision: null,
41429
- bootloader_hash: null,
41430
- imported: null,
41431
- unlocked: false,
41432
- firmware_present: false,
41433
- needs_backup: profile.status.backupRequired,
41434
- flags: null,
41419
+ protocol: 'V1',
41420
+ protocolVersion: (_d = (_c = features.protocol_version) !== null && _c !== void 0 ? _c : previous === null || previous === void 0 ? void 0 : previous.protocolVersion) !== null && _d !== void 0 ? _d : 1,
41421
+ deviceType,
41422
+ firmwareType: getProtocolV1FirmwareType(features),
41423
+ model: (_e = features.model) !== null && _e !== void 0 ? _e : null,
41424
+ vendor: (_f = features.vendor) !== null && _f !== void 0 ? _f : null,
41425
+ deviceId: (_g = features.device_id) !== null && _g !== void 0 ? _g : null,
41426
+ serialNo,
41427
+ label: getProtocolV1Label(features, deviceType, bleName),
41428
+ bleName,
41429
+ capabilities: (_h = features.capabilities) !== null && _h !== void 0 ? _h : [],
41430
+ mode: getProtocolV1Mode(features),
41431
+ initialized: (_j = features.initialized) !== null && _j !== void 0 ? _j : null,
41432
+ bootloaderMode: (_k = features.bootloader_mode) !== null && _k !== void 0 ? _k : null,
41433
+ unlocked: (_l = features.unlocked) !== null && _l !== void 0 ? _l : true,
41434
+ firmwarePresent: (_m = features.firmware_present) !== null && _m !== void 0 ? _m : null,
41435
+ passphraseProtection: (_o = features.passphrase_protection) !== null && _o !== void 0 ? _o : null,
41436
+ pinProtection: (_p = features.pin_protection) !== null && _p !== void 0 ? _p : null,
41437
+ backupRequired: (_q = features.needs_backup) !== null && _q !== void 0 ? _q : null,
41438
+ noBackup: (_r = features.no_backup) !== null && _r !== void 0 ? _r : null,
41439
+ unfinishedBackup: (_s = features.unfinished_backup) !== null && _s !== void 0 ? _s : null,
41440
+ recoveryMode: (_t = features.recovery_mode) !== null && _t !== void 0 ? _t : null,
41441
+ language: (_u = features.language) !== null && _u !== void 0 ? _u : null,
41442
+ bleEnabled: (_v = features.ble_enable) !== null && _v !== void 0 ? _v : null,
41443
+ sdCardPresent: (_w = features.sd_card_present) !== null && _w !== void 0 ? _w : null,
41444
+ sdProtection: (_x = features.sd_protection) !== null && _x !== void 0 ? _x : null,
41445
+ wipeCodeProtection: (_y = features.wipe_code_protection) !== null && _y !== void 0 ? _y : null,
41446
+ passphraseAlwaysOnDevice: (_z = features.passphrase_always_on_device) !== null && _z !== void 0 ? _z : null,
41447
+ safetyChecks: (_0 = features.safety_checks) !== null && _0 !== void 0 ? _0 : null,
41448
+ autoLockDelayMs: (_1 = features.auto_lock_delay_ms) !== null && _1 !== void 0 ? _1 : null,
41449
+ displayRotation: (_2 = features.display_rotation) !== null && _2 !== void 0 ? _2 : null,
41450
+ experimentalFeatures: (_3 = features.experimental_features) !== null && _3 !== void 0 ? _3 : null,
41451
+ firmwareVersion,
41452
+ bootloaderVersion,
41453
+ boardVersion,
41454
+ bleVersion,
41455
+ se01Version: firstMeaningfulVersion(features.onekey_se01_version),
41456
+ se02Version: firstMeaningfulVersion(features.onekey_se02_version),
41457
+ se03Version: firstMeaningfulVersion(features.onekey_se03_version),
41458
+ se04Version: firstMeaningfulVersion(features.onekey_se04_version),
41459
+ se01BootVersion: firstMeaningfulVersion(features.onekey_se01_boot_version),
41460
+ se02BootVersion: firstMeaningfulVersion(features.onekey_se02_boot_version),
41461
+ se03BootVersion: firstMeaningfulVersion(features.onekey_se03_boot_version),
41462
+ se04BootVersion: firstMeaningfulVersion(features.onekey_se04_boot_version),
41463
+ seVersion: (_4 = features.se_ver) !== null && _4 !== void 0 ? _4 : null,
41464
+ verify: {
41465
+ firmwareBuildId: features.onekey_firmware_build_id,
41466
+ firmwareHash: features.onekey_firmware_hash,
41467
+ bootloaderBuildId: features.onekey_boot_build_id,
41468
+ bootloaderHash: features.onekey_boot_hash,
41469
+ boardBuildId: features.onekey_board_build_id,
41470
+ boardHash: features.onekey_board_hash,
41471
+ bleBuildId: features.onekey_ble_build_id,
41472
+ bleHash: features.onekey_ble_hash,
41473
+ se01BuildId: features.onekey_se01_build_id,
41474
+ se01Hash: features.onekey_se01_hash,
41475
+ se02BuildId: features.onekey_se02_build_id,
41476
+ se02Hash: features.onekey_se02_hash,
41477
+ se03BuildId: features.onekey_se03_build_id,
41478
+ se03Hash: features.onekey_se03_hash,
41479
+ se04BuildId: features.onekey_se04_build_id,
41480
+ se04Hash: features.onekey_se04_hash,
41481
+ se01BootBuildId: features.onekey_se01_boot_build_id,
41482
+ se01BootHash: features.onekey_se01_boot_hash,
41483
+ se02BootBuildId: features.onekey_se02_boot_build_id,
41484
+ se02BootHash: features.onekey_se02_boot_hash,
41485
+ se03BootBuildId: features.onekey_se03_boot_build_id,
41486
+ se03BootHash: features.onekey_se03_boot_hash,
41487
+ se04BootBuildId: features.onekey_se04_boot_build_id,
41488
+ se04BootHash: features.onekey_se04_boot_hash,
41489
+ },
41490
+ sessionId,
41491
+ raw: {
41492
+ protocolV1Features: protocolV1Features,
41493
+ },
41494
+ };
41495
+ };
41496
+ const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
41497
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77;
41498
+ const info = deviceInfo;
41499
+ const fwApplication = firstValue((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application, (_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.app);
41500
+ const fwBootloader = firstValue((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.bootloader, (_d = info === null || info === void 0 ? void 0 : info.fw) === null || _d === void 0 ? void 0 : _d.boot);
41501
+ const fwBoard = firstValue((_e = info === null || info === void 0 ? void 0 : info.fw) === null || _e === void 0 ? void 0 : _e.application_data, (_f = info === null || info === void 0 ? void 0 : info.fw) === null || _f === void 0 ? void 0 : _f.board);
41502
+ const bleApplication = firstValue((_g = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _g === void 0 ? void 0 : _g.application, (_h = info === null || info === void 0 ? void 0 : info.bt) === null || _h === void 0 ? void 0 : _h.app);
41503
+ const firmwareVersion = firstMeaningfulVersion(getImageVersion(fwApplication), previous === null || previous === void 0 ? void 0 : previous.firmwareVersion);
41504
+ const bootloaderVersion = firstMeaningfulVersion(getImageVersion(fwBootloader), previous === null || previous === void 0 ? void 0 : previous.bootloaderVersion);
41505
+ const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), previous === null || previous === void 0 ? void 0 : previous.boardVersion);
41506
+ const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication), previous === null || previous === void 0 ? void 0 : previous.bleVersion);
41507
+ const serialNo = (_k = firstValue((_j = info === null || info === void 0 ? void 0 : info.hw) === null || _j === void 0 ? void 0 : _j.serial_no, previous === null || previous === void 0 ? void 0 : previous.serialNo)) !== null && _k !== void 0 ? _k : '';
41508
+ const label = (_m = firstValue((_l = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _l === void 0 ? void 0 : _l.label, previous === null || previous === void 0 ? void 0 : previous.label)) !== null && _m !== void 0 ? _m : null;
41509
+ const bleName = firstValue((_o = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _o === void 0 ? void 0 : _o.bt_adv_name, (_p = info === null || info === void 0 ? void 0 : info.bt) === null || _p === void 0 ? void 0 : _p.adv_name, previous === null || previous === void 0 ? void 0 : previous.bleName);
41510
+ const initialized = (_r = firstValue((_q = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _q === void 0 ? void 0 : _q.init_states, previous === null || previous === void 0 ? void 0 : previous.initialized)) !== null && _r !== void 0 ? _r : null;
41511
+ const passphraseProtection = (_t = firstValue((_s = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _s === void 0 ? void 0 : _s.passphrase_protection, previous === null || previous === void 0 ? void 0 : previous.passphraseProtection)) !== null && _t !== void 0 ? _t : null;
41512
+ const language = (_v = firstValue((_u = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _u === void 0 ? void 0 : _u.language, previous === null || previous === void 0 ? void 0 : previous.language)) !== null && _v !== void 0 ? _v : null;
41513
+ const backupRequired = (_x = firstValue((_w = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _w === void 0 ? void 0 : _w.backup_required, previous === null || previous === void 0 ? void 0 : previous.backupRequired)) !== null && _x !== void 0 ? _x : null;
41514
+ const bleEnabled = firstValue((_y = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _y === void 0 ? void 0 : _y.bt_enable, previous === null || previous === void 0 ? void 0 : previous.bleEnabled);
41515
+ return {
41516
+ protocol: 'V2',
41517
+ protocolVersion: (_0 = (_z = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.protocol_version) !== null && _z !== void 0 ? _z : previous === null || previous === void 0 ? void 0 : previous.protocolVersion) !== null && _0 !== void 0 ? _0 : null,
41518
+ deviceType: hdShared.EDeviceType.Pro2,
41519
+ firmwareType: (_1 = previous === null || previous === void 0 ? void 0 : previous.firmwareType) !== null && _1 !== void 0 ? _1 : hdShared.EFirmwareType.Universal,
41435
41520
  model: 'pro2',
41436
- fw_major: fwMajor,
41437
- fw_minor: fwMinor,
41438
- fw_patch: fwPatch,
41439
- fw_vendor: null,
41440
- unfinished_backup: null,
41441
- no_backup: null,
41442
- recovery_mode: null,
41521
+ vendor: 'onekey.so',
41522
+ deviceId: null,
41523
+ serialNo,
41524
+ label,
41525
+ bleName: bleName !== null && bleName !== void 0 ? bleName : null,
41443
41526
  capabilities: [],
41444
- backup_type: null,
41445
- sd_card_present: null,
41446
- sd_protection: null,
41447
- wipe_code_protection: null,
41448
- session_id: null,
41449
- passphrase_always_on_device: null,
41450
- safety_checks: null,
41451
- auto_lock_delay_ms: null,
41452
- display_rotation: null,
41453
- experimental_features: null,
41454
- protocol_version: (_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.protocol_version) !== null && _b !== void 0 ? _b : null,
41455
- onekey_device_type: hdShared.EDeviceType.Pro2,
41456
- onekey_serial_no: profile.serialNo,
41457
- serial_no: profile.serialNo,
41458
- ble_enable: (_c = profile.status.bleEnabled) !== null && _c !== void 0 ? _c : undefined,
41459
- onekey_ble_name: (_d = profile.bleName) !== null && _d !== void 0 ? _d : undefined,
41460
- ble_name: (_e = profile.bleName) !== null && _e !== void 0 ? _e : undefined,
41461
- onekey_firmware_version: firmwareVersion !== null && firmwareVersion !== void 0 ? firmwareVersion : undefined,
41462
- onekey_firmware_build_id: (_f = profile.verify) === null || _f === void 0 ? void 0 : _f.firmwareBuildId,
41463
- onekey_firmware_hash: (_g = profile.verify) === null || _g === void 0 ? void 0 : _g.firmwareHash,
41464
- onekey_boot_version: (_h = profile.versions.bootloader) !== null && _h !== void 0 ? _h : undefined,
41465
- bootloader_version: (_j = profile.versions.bootloader) !== null && _j !== void 0 ? _j : undefined,
41466
- onekey_boot_build_id: (_k = profile.verify) === null || _k === void 0 ? void 0 : _k.bootloaderBuildId,
41467
- onekey_boot_hash: (_l = profile.verify) === null || _l === void 0 ? void 0 : _l.bootloaderHash,
41468
- onekey_board_version: (_m = profile.versions.board) !== null && _m !== void 0 ? _m : undefined,
41469
- onekey_board_build_id: (_o = profile.verify) === null || _o === void 0 ? void 0 : _o.boardBuildId,
41470
- onekey_board_hash: (_p = profile.verify) === null || _p === void 0 ? void 0 : _p.boardHash,
41471
- onekey_ble_version: (_q = profile.versions.ble) !== null && _q !== void 0 ? _q : undefined,
41472
- ble_ver: (_r = profile.versions.ble) !== null && _r !== void 0 ? _r : undefined,
41473
- onekey_ble_build_id: (_s = profile.verify) === null || _s === void 0 ? void 0 : _s.bleBuildId,
41474
- onekey_ble_hash: (_t = profile.verify) === null || _t === void 0 ? void 0 : _t.bleHash,
41475
- onekey_se_type: getProtocolV2SeType(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1),
41476
- onekey_se01_version: (_u = profile.versions.se01) !== null && _u !== void 0 ? _u : undefined,
41477
- onekey_se01_hash: (_v = profile.verify) === null || _v === void 0 ? void 0 : _v.se01Hash,
41478
- onekey_se01_build_id: (_w = profile.verify) === null || _w === void 0 ? void 0 : _w.se01BuildId,
41479
- onekey_se01_boot_version: (_x = profile.versions.se01Boot) !== null && _x !== void 0 ? _x : undefined,
41480
- onekey_se01_boot_hash: (_y = profile.verify) === null || _y === void 0 ? void 0 : _y.se01BootHash,
41481
- onekey_se01_boot_build_id: (_z = profile.verify) === null || _z === void 0 ? void 0 : _z.se01BootBuildId,
41482
- onekey_se01_state: getProtocolV2SeState(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1),
41483
- onekey_se02_version: (_0 = profile.versions.se02) !== null && _0 !== void 0 ? _0 : undefined,
41484
- onekey_se02_hash: (_1 = profile.verify) === null || _1 === void 0 ? void 0 : _1.se02Hash,
41485
- onekey_se02_build_id: (_2 = profile.verify) === null || _2 === void 0 ? void 0 : _2.se02BuildId,
41486
- onekey_se02_boot_version: (_3 = profile.versions.se02Boot) !== null && _3 !== void 0 ? _3 : undefined,
41487
- onekey_se02_boot_hash: (_4 = profile.verify) === null || _4 === void 0 ? void 0 : _4.se02BootHash,
41488
- onekey_se02_boot_build_id: (_5 = profile.verify) === null || _5 === void 0 ? void 0 : _5.se02BootBuildId,
41489
- onekey_se02_state: getProtocolV2SeState(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2),
41490
- onekey_se03_version: (_6 = profile.versions.se03) !== null && _6 !== void 0 ? _6 : undefined,
41491
- onekey_se03_hash: (_7 = profile.verify) === null || _7 === void 0 ? void 0 : _7.se03Hash,
41492
- onekey_se03_build_id: (_8 = profile.verify) === null || _8 === void 0 ? void 0 : _8.se03BuildId,
41493
- onekey_se03_boot_version: (_9 = profile.versions.se03Boot) !== null && _9 !== void 0 ? _9 : undefined,
41494
- onekey_se03_boot_hash: (_10 = profile.verify) === null || _10 === void 0 ? void 0 : _10.se03BootHash,
41495
- onekey_se03_boot_build_id: (_11 = profile.verify) === null || _11 === void 0 ? void 0 : _11.se03BootBuildId,
41496
- onekey_se03_state: getProtocolV2SeState(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3),
41497
- onekey_se04_version: (_12 = profile.versions.se04) !== null && _12 !== void 0 ? _12 : undefined,
41498
- onekey_se04_hash: (_13 = profile.verify) === null || _13 === void 0 ? void 0 : _13.se04Hash,
41499
- onekey_se04_build_id: (_14 = profile.verify) === null || _14 === void 0 ? void 0 : _14.se04BuildId,
41500
- onekey_se04_boot_version: (_15 = profile.versions.se04Boot) !== null && _15 !== void 0 ? _15 : undefined,
41501
- onekey_se04_boot_hash: (_16 = profile.verify) === null || _16 === void 0 ? void 0 : _16.se04BootHash,
41502
- onekey_se04_boot_build_id: (_17 = profile.verify) === null || _17 === void 0 ? void 0 : _17.se04BootBuildId,
41503
- onekey_se04_state: getProtocolV2SeState(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4),
41527
+ mode: initialized === false ? 'notInitialized' : initialized === true ? 'normal' : 'unknown',
41528
+ initialized,
41529
+ bootloaderMode: false,
41530
+ unlocked: (_2 = previous === null || previous === void 0 ? void 0 : previous.unlocked) !== null && _2 !== void 0 ? _2 : null,
41531
+ firmwarePresent: (_3 = previous === null || previous === void 0 ? void 0 : previous.firmwarePresent) !== null && _3 !== void 0 ? _3 : null,
41532
+ passphraseProtection,
41533
+ pinProtection: null,
41534
+ backupRequired,
41535
+ noBackup: null,
41536
+ unfinishedBackup: null,
41537
+ recoveryMode: null,
41538
+ language,
41539
+ bleEnabled: bleEnabled !== null && bleEnabled !== void 0 ? bleEnabled : null,
41540
+ sdCardPresent: null,
41541
+ sdProtection: null,
41542
+ wipeCodeProtection: null,
41543
+ passphraseAlwaysOnDevice: null,
41544
+ safetyChecks: null,
41545
+ autoLockDelayMs: null,
41546
+ displayRotation: null,
41547
+ experimentalFeatures: null,
41548
+ firmwareVersion,
41549
+ bootloaderVersion,
41550
+ boardVersion,
41551
+ bleVersion,
41552
+ se01Version: firstMeaningfulVersion(getImageVersion((_4 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _4 === void 0 ? void 0 : _4.app), previous === null || previous === void 0 ? void 0 : previous.se01Version),
41553
+ se02Version: firstMeaningfulVersion(getImageVersion((_5 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _5 === void 0 ? void 0 : _5.app), previous === null || previous === void 0 ? void 0 : previous.se02Version),
41554
+ se03Version: firstMeaningfulVersion(getImageVersion((_6 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _6 === void 0 ? void 0 : _6.app), previous === null || previous === void 0 ? void 0 : previous.se03Version),
41555
+ se04Version: firstMeaningfulVersion(getImageVersion((_7 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _7 === void 0 ? void 0 : _7.app), previous === null || previous === void 0 ? void 0 : previous.se04Version),
41556
+ se01BootVersion: firstMeaningfulVersion(getImageVersion((_8 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _8 === void 0 ? void 0 : _8.boot), previous === null || previous === void 0 ? void 0 : previous.se01BootVersion),
41557
+ se02BootVersion: firstMeaningfulVersion(getImageVersion((_9 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _9 === void 0 ? void 0 : _9.boot), previous === null || previous === void 0 ? void 0 : previous.se02BootVersion),
41558
+ se03BootVersion: firstMeaningfulVersion(getImageVersion((_10 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _10 === void 0 ? void 0 : _10.boot), previous === null || previous === void 0 ? void 0 : previous.se03BootVersion),
41559
+ se04BootVersion: firstMeaningfulVersion(getImageVersion((_11 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _11 === void 0 ? void 0 : _11.boot), previous === null || previous === void 0 ? void 0 : previous.se04BootVersion),
41560
+ seVersion: (_12 = previous === null || previous === void 0 ? void 0 : previous.seVersion) !== null && _12 !== void 0 ? _12 : null,
41561
+ verify: {
41562
+ firmwareBuildId: (_13 = getImageBuildId(fwApplication)) !== null && _13 !== void 0 ? _13 : (_14 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _14 === void 0 ? void 0 : _14.firmwareBuildId,
41563
+ firmwareHash: (_15 = getImageHash(fwApplication)) !== null && _15 !== void 0 ? _15 : (_16 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _16 === void 0 ? void 0 : _16.firmwareHash,
41564
+ bootloaderBuildId: (_17 = getImageBuildId(fwBootloader)) !== null && _17 !== void 0 ? _17 : (_18 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _18 === void 0 ? void 0 : _18.bootloaderBuildId,
41565
+ bootloaderHash: (_19 = getImageHash(fwBootloader)) !== null && _19 !== void 0 ? _19 : (_20 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _20 === void 0 ? void 0 : _20.bootloaderHash,
41566
+ boardBuildId: (_21 = getImageBuildId(fwBoard)) !== null && _21 !== void 0 ? _21 : (_22 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _22 === void 0 ? void 0 : _22.boardBuildId,
41567
+ boardHash: (_23 = getImageHash(fwBoard)) !== null && _23 !== void 0 ? _23 : (_24 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _24 === void 0 ? void 0 : _24.boardHash,
41568
+ bleBuildId: (_25 = getImageBuildId(bleApplication)) !== null && _25 !== void 0 ? _25 : (_26 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _26 === void 0 ? void 0 : _26.bleBuildId,
41569
+ bleHash: (_27 = getImageHash(bleApplication)) !== null && _27 !== void 0 ? _27 : (_28 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _28 === void 0 ? void 0 : _28.bleHash,
41570
+ se01BuildId: (_30 = getImageBuildId((_29 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _29 === void 0 ? void 0 : _29.app)) !== null && _30 !== void 0 ? _30 : (_31 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _31 === void 0 ? void 0 : _31.se01BuildId,
41571
+ se01Hash: (_33 = getImageHash((_32 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _32 === void 0 ? void 0 : _32.app)) !== null && _33 !== void 0 ? _33 : (_34 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _34 === void 0 ? void 0 : _34.se01Hash,
41572
+ se02BuildId: (_36 = getImageBuildId((_35 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _35 === void 0 ? void 0 : _35.app)) !== null && _36 !== void 0 ? _36 : (_37 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _37 === void 0 ? void 0 : _37.se02BuildId,
41573
+ se02Hash: (_39 = getImageHash((_38 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _38 === void 0 ? void 0 : _38.app)) !== null && _39 !== void 0 ? _39 : (_40 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _40 === void 0 ? void 0 : _40.se02Hash,
41574
+ se03BuildId: (_42 = getImageBuildId((_41 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _41 === void 0 ? void 0 : _41.app)) !== null && _42 !== void 0 ? _42 : (_43 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _43 === void 0 ? void 0 : _43.se03BuildId,
41575
+ se03Hash: (_45 = getImageHash((_44 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _44 === void 0 ? void 0 : _44.app)) !== null && _45 !== void 0 ? _45 : (_46 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _46 === void 0 ? void 0 : _46.se03Hash,
41576
+ se04BuildId: (_48 = getImageBuildId((_47 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _47 === void 0 ? void 0 : _47.app)) !== null && _48 !== void 0 ? _48 : (_49 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _49 === void 0 ? void 0 : _49.se04BuildId,
41577
+ se04Hash: (_51 = getImageHash((_50 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _50 === void 0 ? void 0 : _50.app)) !== null && _51 !== void 0 ? _51 : (_52 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _52 === void 0 ? void 0 : _52.se04Hash,
41578
+ se01BootBuildId: (_54 = getImageBuildId((_53 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _53 === void 0 ? void 0 : _53.boot)) !== null && _54 !== void 0 ? _54 : (_55 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _55 === void 0 ? void 0 : _55.se01BootBuildId,
41579
+ se01BootHash: (_57 = getImageHash((_56 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _56 === void 0 ? void 0 : _56.boot)) !== null && _57 !== void 0 ? _57 : (_58 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _58 === void 0 ? void 0 : _58.se01BootHash,
41580
+ se02BootBuildId: (_60 = getImageBuildId((_59 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _59 === void 0 ? void 0 : _59.boot)) !== null && _60 !== void 0 ? _60 : (_61 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _61 === void 0 ? void 0 : _61.se02BootBuildId,
41581
+ se02BootHash: (_63 = getImageHash((_62 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _62 === void 0 ? void 0 : _62.boot)) !== null && _63 !== void 0 ? _63 : (_64 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _64 === void 0 ? void 0 : _64.se02BootHash,
41582
+ se03BootBuildId: (_66 = getImageBuildId((_65 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _65 === void 0 ? void 0 : _65.boot)) !== null && _66 !== void 0 ? _66 : (_67 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _67 === void 0 ? void 0 : _67.se03BootBuildId,
41583
+ se03BootHash: (_69 = getImageHash((_68 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _68 === void 0 ? void 0 : _68.boot)) !== null && _69 !== void 0 ? _69 : (_70 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _70 === void 0 ? void 0 : _70.se03BootHash,
41584
+ se04BootBuildId: (_72 = getImageBuildId((_71 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _71 === void 0 ? void 0 : _71.boot)) !== null && _72 !== void 0 ? _72 : (_73 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _73 === void 0 ? void 0 : _73.se04BootBuildId,
41585
+ se04BootHash: (_75 = getImageHash((_74 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _74 === void 0 ? void 0 : _74.boot)) !== null && _75 !== void 0 ? _75 : (_76 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _76 === void 0 ? void 0 : _76.se04BootHash,
41586
+ },
41587
+ sessionId: (_77 = previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _77 !== void 0 ? _77 : null,
41588
+ passphraseState: previous === null || previous === void 0 ? void 0 : previous.passphraseState,
41589
+ unlockedAttachPin: previous === null || previous === void 0 ? void 0 : previous.unlockedAttachPin,
41590
+ raw: {
41591
+ protocolV2DeviceInfo: deviceInfo,
41592
+ },
41504
41593
  };
41505
41594
  };
41506
41595
 
@@ -41510,35 +41599,12 @@ const parseRunOptions = (options) => {
41510
41599
  return options;
41511
41600
  };
41512
41601
  const Log$c = getLogger(exports.LoggerNames.Device);
41513
- const profileVersionToArray = (version) => {
41514
- if (!version)
41515
- return null;
41516
- return version.split('.').map(part => Number(part) || 0);
41517
- };
41518
41602
  const deviceSessionCache = {};
41519
41603
  function preloadSessionCache(deviceId, passphraseState, sessionId) {
41520
41604
  const key = `${deviceId}@${passphraseState}`;
41521
41605
  deviceSessionCache[key] = sessionId;
41522
41606
  }
41523
41607
  class Device extends events.exports {
41524
- getFeaturesProfile() {
41525
- if (!this.features)
41526
- return undefined;
41527
- const protocol = this.originalDescriptor.protocolType === 'V2' ? 'V2' : 'V1';
41528
- return buildProfileFromProtocolV1({
41529
- protocol,
41530
- features: this.features,
41531
- onekeyFeatures: this.features,
41532
- sources: ['features'],
41533
- scope: 'verify',
41534
- });
41535
- }
41536
- get profile() {
41537
- return this.getFeaturesProfile();
41538
- }
41539
- set profile(profile) {
41540
- this.updateProfile(profile);
41541
- }
41542
41608
  constructor(descriptor, sdkInstanceId) {
41543
41609
  super();
41544
41610
  this.deviceConnector = null;
@@ -41588,8 +41654,7 @@ class Device extends events.exports {
41588
41654
  label: label || 'OneKey',
41589
41655
  mode: this.getMode(),
41590
41656
  features,
41591
- profile: this.profile,
41592
- sessionId: (_c = (_b = this.features) === null || _b === void 0 ? void 0 : _b.session_id) !== null && _c !== void 0 ? _c : null,
41657
+ sessionId: (_c = (_b = this.features) === null || _b === void 0 ? void 0 : _b.sessionId) !== null && _c !== void 0 ? _c : null,
41593
41658
  firmwareVersion: this.getFirmwareVersion(),
41594
41659
  bleFirmwareVersion: this.getBLEFirmwareVersion(),
41595
41660
  unavailableCapabilities: this.unavailableCapabilities,
@@ -41755,60 +41820,40 @@ class Device extends events.exports {
41755
41820
  return this.getProtocol() === 'V2';
41756
41821
  }
41757
41822
  getCurrentDeviceType() {
41758
- var _a, _b;
41759
- return (_b = (_a = this.profile) === null || _a === void 0 ? void 0 : _a.deviceType) !== null && _b !== void 0 ? _b : getDeviceType(this.features);
41823
+ return getDeviceType(this.features);
41760
41824
  }
41761
41825
  getCurrentDeviceId() {
41762
41826
  var _a;
41763
- if (this.profile) {
41764
- return this.profile.deviceId || undefined;
41765
- }
41766
- return ((_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id) || undefined;
41827
+ return ((_a = this.features) === null || _a === void 0 ? void 0 : _a.deviceId) || undefined;
41767
41828
  }
41768
41829
  getCurrentSerialNo() {
41769
- if (this.profile) {
41770
- return this.profile.serialNo || '';
41771
- }
41772
41830
  return this.features ? getDeviceUUID(this.features) : '';
41773
41831
  }
41774
41832
  getCurrentBleName() {
41775
- var _a, _b, _c, _d;
41776
- if (this.isProtocolV2())
41777
- return (_b = (_a = this.profile) === null || _a === void 0 ? void 0 : _a.bleName) !== null && _b !== void 0 ? _b : null;
41778
- return (_d = (_c = this.profile) === null || _c === void 0 ? void 0 : _c.bleName) !== null && _d !== void 0 ? _d : getDeviceBleName(this.features);
41833
+ return getDeviceBleName(this.features);
41779
41834
  }
41780
41835
  getCurrentLabel() {
41781
- var _a, _b, _c, _d;
41782
- if (this.isProtocolV2())
41783
- return (_b = (_a = this.profile) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : null;
41784
- return (_d = (_c = this.profile) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : getDeviceLabel(this.features);
41836
+ return getDeviceLabel(this.features);
41785
41837
  }
41786
41838
  getCurrentPassphraseProtection() {
41787
41839
  var _a;
41788
- if (this.profile) {
41789
- return this.profile.status.passphraseProtection;
41790
- }
41791
- return (_a = this.features) === null || _a === void 0 ? void 0 : _a.passphrase_protection;
41840
+ return (_a = this.features) === null || _a === void 0 ? void 0 : _a.passphraseProtection;
41792
41841
  }
41793
41842
  getCurrentFirmwareType() {
41794
- var _a, _b;
41795
- return (_b = (_a = this.profile) === null || _a === void 0 ? void 0 : _a.firmwareType) !== null && _b !== void 0 ? _b : getFirmwareType(this.features);
41843
+ return getFirmwareType(this.features);
41796
41844
  }
41797
41845
  getCurrentFirmwareVersionString() {
41798
- var _a, _b, _c;
41799
- return (_b = (_a = this.profile) === null || _a === void 0 ? void 0 : _a.versions.firmware) !== null && _b !== void 0 ? _b : (_c = getDeviceFirmwareVersion(this.features)) === null || _c === void 0 ? void 0 : _c.join('.');
41846
+ var _a;
41847
+ return (_a = getDeviceFirmwareVersion(this.features)) === null || _a === void 0 ? void 0 : _a.join('.');
41800
41848
  }
41801
41849
  getCurrentBLEFirmwareVersionString() {
41802
- var _a;
41803
- if ((_a = this.profile) === null || _a === void 0 ? void 0 : _a.versions.ble)
41804
- return this.profile.versions.ble;
41805
41850
  if (!this.features)
41806
41851
  return undefined;
41807
41852
  return getDeviceBLEFirmwareVersion(this.features).join('.');
41808
41853
  }
41809
41854
  getCurrentSafetyChecks() {
41810
41855
  var _a;
41811
- return (_a = this.features) === null || _a === void 0 ? void 0 : _a.safety_checks;
41856
+ return (_a = this.features) === null || _a === void 0 ? void 0 : _a.safetyChecks;
41812
41857
  }
41813
41858
  getCurrentMethodVersionRange(getVersionRange) {
41814
41859
  var _a;
@@ -41880,11 +41925,20 @@ class Device extends events.exports {
41880
41925
  }
41881
41926
  return deviceId;
41882
41927
  }
41928
+ getSessionCacheDeviceKey(_deviceId) {
41929
+ const deviceId = _deviceId || this.getCurrentDeviceId();
41930
+ if (deviceId)
41931
+ return deviceId;
41932
+ if (this.isProtocolV2()) {
41933
+ return this.originalDescriptor.path || this.originalDescriptor.id;
41934
+ }
41935
+ return undefined;
41936
+ }
41883
41937
  getInternalState(_deviceId) {
41884
- var _a, _b;
41938
+ var _a;
41885
41939
  Log$c.debug('getInternalState session cache: ', deviceSessionCache);
41886
- Log$c.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `profile.deviceId: ${(_b = this.profile) === null || _b === void 0 ? void 0 : _b.deviceId}`, `passphraseState: ${this.passphraseState}`);
41887
- const deviceId = _deviceId || this.getCurrentDeviceId();
41940
+ Log$c.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.deviceId: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.deviceId}`, `passphraseState: ${this.passphraseState}`);
41941
+ const deviceId = this.getSessionCacheDeviceKey(_deviceId);
41888
41942
  if (!deviceId)
41889
41943
  return undefined;
41890
41944
  if (!this.passphraseState)
@@ -41894,26 +41948,30 @@ class Device extends events.exports {
41894
41948
  }
41895
41949
  updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
41896
41950
  Log$c.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `sessionId: ${sessionId}`, `featuresSessionId: ${featuresSessionId}`);
41951
+ const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
41952
+ if (!cacheDeviceKey)
41953
+ return;
41897
41954
  if (enablePassphrase) {
41898
41955
  if (sessionId) {
41899
- deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
41956
+ deviceSessionCache[this.generateStateKey(cacheDeviceKey, passphraseState)] = sessionId;
41900
41957
  }
41901
41958
  else if (featuresSessionId) {
41902
- deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = featuresSessionId;
41959
+ deviceSessionCache[this.generateStateKey(cacheDeviceKey, passphraseState)] =
41960
+ featuresSessionId;
41903
41961
  }
41904
41962
  }
41905
- const oldKey = `${deviceId}`;
41963
+ const oldKey = `${cacheDeviceKey}`;
41906
41964
  if (deviceSessionCache[oldKey]) {
41907
41965
  delete deviceSessionCache[oldKey];
41908
41966
  }
41909
41967
  Log$c.debug('updateInternalState session cache: ', deviceSessionCache);
41910
41968
  }
41911
41969
  setInternalState(state, initSession) {
41912
- var _a, _b;
41913
- Log$c.debug('setInternalState session param: ', `state: ${state}`, `initSession: ${initSession}`, `device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `profile.deviceId: ${(_b = this.profile) === null || _b === void 0 ? void 0 : _b.deviceId}`, `passphraseState: ${this.passphraseState}`);
41970
+ var _a;
41971
+ Log$c.debug('setInternalState session param: ', `state: ${state}`, `initSession: ${initSession}`, `deviceId: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.deviceId}`, `passphraseState: ${this.passphraseState}`);
41914
41972
  if (!this.passphraseState && !initSession)
41915
41973
  return;
41916
- const deviceId = this.getCurrentDeviceId();
41974
+ const deviceId = this.getSessionCacheDeviceKey();
41917
41975
  if (!deviceId)
41918
41976
  return;
41919
41977
  const key = this.generateStateKey(deviceId, this.passphraseState);
@@ -41924,7 +41982,7 @@ class Device extends events.exports {
41924
41982
  }
41925
41983
  clearInternalState(_deviceId) {
41926
41984
  Log$c.debug('clearInternalState param: ', _deviceId);
41927
- const deviceId = _deviceId || this.getCurrentDeviceId();
41985
+ const deviceId = this.getSessionCacheDeviceKey(_deviceId);
41928
41986
  if (!deviceId)
41929
41987
  return;
41930
41988
  const key = `${deviceId}`;
@@ -41938,7 +41996,7 @@ class Device extends events.exports {
41938
41996
  return __awaiter(this, void 0, void 0, function* () {
41939
41997
  if (this.isProtocolV2()) {
41940
41998
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
41941
- if (this.profile && !this.featuresNeedsReload && !(options === null || options === void 0 ? void 0 : options.initSession)) {
41999
+ if (this.features && !this.featuresNeedsReload && !(options === null || options === void 0 ? void 0 : options.initSession)) {
41942
42000
  yield this._refreshProtocolV2Status();
41943
42001
  return;
41944
42002
  }
@@ -41981,20 +42039,14 @@ class Device extends events.exports {
41981
42039
  });
41982
42040
  }
41983
42041
  _initializeProtocolV2() {
41984
- var _a;
41985
42042
  return __awaiter(this, void 0, void 0, function* () {
41986
- Log$c.debug('Initialize device via Protocol V2 profile adapter');
42043
+ Log$c.debug('Initialize device via Protocol V2 features adapter');
41987
42044
  try {
41988
42045
  const deviceInfo = yield requestProtocolV2DeviceInfo({
41989
42046
  commands: this.commands,
41990
42047
  });
41991
- const profile = this.applyProfileUpdate(buildProfileFromProtocolV2({
41992
- deviceInfo,
41993
- sources: ['deviceInfo'],
41994
- scope: 'basic',
41995
- fallbackSerialNo: (_a = this.originalDescriptor) === null || _a === void 0 ? void 0 : _a.path,
41996
- }), deviceInfo);
41997
- Log$c.debug('Protocol V2 profile:', profile);
42048
+ const features = this.updateProtocolV2Features(deviceInfo);
42049
+ Log$c.debug('Protocol V2 features:', features);
41998
42050
  this.featuresNeedsReload = false;
41999
42051
  }
42000
42052
  catch (error) {
@@ -42004,20 +42056,14 @@ class Device extends events.exports {
42004
42056
  });
42005
42057
  }
42006
42058
  _refreshProtocolV2Status() {
42007
- var _a;
42008
42059
  return __awaiter(this, void 0, void 0, function* () {
42009
42060
  try {
42010
42061
  const deviceInfo = yield requestProtocolV2DeviceInfo({
42011
42062
  commands: this.commands,
42012
42063
  request: PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
42013
42064
  });
42014
- const profile = this.applyProfileUpdate(buildProfileFromProtocolV2({
42015
- deviceInfo,
42016
- sources: ['deviceInfo'],
42017
- scope: 'basic',
42018
- fallbackSerialNo: (_a = this.originalDescriptor) === null || _a === void 0 ? void 0 : _a.path,
42019
- }), deviceInfo);
42020
- Log$c.debug('Protocol V2 profile (status refresh):', profile);
42065
+ const features = this.updateProtocolV2Features(deviceInfo);
42066
+ Log$c.debug('Protocol V2 features (status refresh):', features);
42021
42067
  }
42022
42068
  catch (error) {
42023
42069
  Log$c.error('Protocol V2 status refresh failed:', error);
@@ -42026,79 +42072,40 @@ class Device extends events.exports {
42026
42072
  });
42027
42073
  }
42028
42074
  getFeatures() {
42029
- var _a, _b;
42030
42075
  return __awaiter(this, void 0, void 0, function* () {
42031
42076
  if (this.isProtocolV2()) {
42032
42077
  const deviceInfo = yield requestProtocolV2DeviceInfo({
42033
42078
  commands: this.commands,
42034
42079
  });
42035
- const profile = this.applyProfileUpdate(buildProfileFromProtocolV2({
42036
- deviceInfo,
42037
- sources: ['deviceInfo'],
42038
- scope: 'basic',
42039
- fallbackSerialNo: (_a = this.originalDescriptor) === null || _a === void 0 ? void 0 : _a.path,
42040
- }), deviceInfo);
42041
- return (_b = this.features) !== null && _b !== void 0 ? _b : this.updateProtocolV2Features(profile, deviceInfo);
42080
+ return this.updateProtocolV2Features(deviceInfo);
42042
42081
  }
42043
42082
  const { message } = yield this.commands.typedCall('GetFeatures', 'Features', {});
42044
42083
  this._updateFeatures(message);
42045
- return message;
42084
+ return this.features;
42046
42085
  });
42047
42086
  }
42048
- _updateFeatures(feat, initSession) {
42049
- var _a;
42050
- if (this.features && this.features.session_id && !feat.session_id) {
42051
- feat.session_id = this.features.session_id;
42087
+ _updateFeatures(protoFeatures, initSession) {
42088
+ var _a, _b;
42089
+ let feat = 'protocol' in protoFeatures
42090
+ ? protoFeatures
42091
+ : buildProtocolV1FeaturesPayload(protoFeatures, this.features);
42092
+ if (((_a = this.features) === null || _a === void 0 ? void 0 : _a.sessionId) && !feat.sessionId) {
42093
+ feat.sessionId = this.features.sessionId;
42052
42094
  }
42053
- if (this.getCurrentDeviceId() && feat.session_id) {
42054
- this.setInternalState(feat.session_id, initSession);
42095
+ if (this.getCurrentDeviceId() && feat.sessionId) {
42096
+ this.setInternalState(feat.sessionId, initSession);
42055
42097
  }
42056
- feat.unlocked = (_a = feat.unlocked) !== null && _a !== void 0 ? _a : true;
42098
+ feat.unlocked = (_b = feat.unlocked) !== null && _b !== void 0 ? _b : true;
42057
42099
  feat = fixFeaturesFirmwareVersion(feat);
42058
42100
  this.features = feat;
42059
- if (!this.isProtocolV2()) {
42060
- this.updateProfile(buildProfileFromProtocolV1({
42061
- features: feat,
42062
- sources: ['features'],
42063
- }));
42064
- }
42065
42101
  this.featuresNeedsReload = false;
42066
42102
  this.emit(DEVICE.FEATURES, this, feat);
42067
42103
  }
42068
- updateProfile(profile) {
42069
- var _a, _b;
42070
- if (!profile) {
42071
- this.features = undefined;
42072
- return;
42073
- }
42074
- if (profile.protocol === 'V2') {
42075
- this.updateProtocolV2Features(profile, (_a = profile.raw) === null || _a === void 0 ? void 0 : _a.protocolV2DeviceInfo);
42076
- return;
42077
- }
42078
- if ((_b = profile.raw) === null || _b === void 0 ? void 0 : _b.features) {
42079
- this.features = fixFeaturesFirmwareVersion(profile.raw.features);
42080
- }
42081
- }
42082
- applyProfileUpdate(next, deviceInfo) {
42083
- var _a;
42084
- const prev = this.profile;
42085
- if (!prev || prev.protocol !== next.protocol) {
42086
- this.updateProfile(Object.assign(Object.assign({}, next), { raw: Object.assign(Object.assign({}, next.raw), (deviceInfo ? { protocolV2DeviceInfo: deviceInfo } : {})) }));
42087
- return next;
42088
- }
42089
- const versions = Object.assign({}, prev.versions);
42090
- for (const [key, value] of Object.entries(next.versions)) {
42091
- if (value != null) {
42092
- versions[key] = value;
42093
- }
42094
- }
42095
- const merged = Object.assign(Object.assign(Object.assign({}, prev), next), { versions, verify: (_a = next.verify) !== null && _a !== void 0 ? _a : prev.verify, raw: Object.assign(Object.assign(Object.assign({}, prev.raw), next.raw), (deviceInfo ? { protocolV2DeviceInfo: deviceInfo } : {})) });
42096
- this.updateProfile(merged);
42097
- return merged;
42098
- }
42099
- updateProtocolV2Features(profile, deviceInfo) {
42100
- const features = fixFeaturesFirmwareVersion(buildProtocolV2GetFeaturesPayload(profile, deviceInfo));
42101
- this._updateFeatures(features);
42104
+ updateProtocolV2Features(deviceInfo) {
42105
+ const features = fixFeaturesFirmwareVersion(buildProtocolV2FeaturesPayload(deviceInfo, this.features));
42106
+ this.features = features;
42107
+ this.featuresNeedsReload = false;
42108
+ this.emit(DEVICE.FEATURES, this, features);
42102
42109
  return features;
42103
42110
  }
42104
42111
  updateDescriptor(descriptor, forceUpdate = false) {
@@ -42123,7 +42130,6 @@ class Device extends events.exports {
42123
42130
  if (device.features) {
42124
42131
  this._updateFeatures(device.features);
42125
42132
  }
42126
- this.updateProfile(device.profile);
42127
42133
  }
42128
42134
  run(fn, options) {
42129
42135
  return __awaiter(this, void 0, void 0, function* () {
@@ -42241,47 +42247,23 @@ class Device extends events.exports {
42241
42247
  }
42242
42248
  getMode() {
42243
42249
  var _a, _b, _c;
42244
- if (this.profile) {
42245
- if (this.profile.status.mode === 'bootloader')
42246
- return exports.EOneKeyDeviceMode.bootloader;
42247
- if (this.profile.status.mode === 'notInitialized')
42248
- return exports.EOneKeyDeviceMode.notInitialized;
42249
- if (this.profile.status.noBackup === true)
42250
- return exports.EOneKeyDeviceMode.backupMode;
42251
- if (this.profile.status.mode === 'normal')
42252
- return exports.EOneKeyDeviceMode.normal;
42253
- if (this.isProtocolV2())
42254
- return exports.EOneKeyDeviceMode.notInitialized;
42255
- }
42256
- if ((_a = this.features) === null || _a === void 0 ? void 0 : _a.bootloader_mode) {
42250
+ if ((_a = this.features) === null || _a === void 0 ? void 0 : _a.bootloaderMode) {
42257
42251
  return exports.EOneKeyDeviceMode.bootloader;
42258
42252
  }
42259
42253
  if (!((_b = this.features) === null || _b === void 0 ? void 0 : _b.initialized)) {
42260
42254
  return exports.EOneKeyDeviceMode.notInitialized;
42261
42255
  }
42262
- if ((_c = this.features) === null || _c === void 0 ? void 0 : _c.no_backup) {
42256
+ if ((_c = this.features) === null || _c === void 0 ? void 0 : _c.noBackup) {
42263
42257
  return exports.EOneKeyDeviceMode.backupMode;
42264
42258
  }
42265
42259
  return exports.EOneKeyDeviceMode.normal;
42266
42260
  }
42267
42261
  getFirmwareVersion() {
42268
- var _a;
42269
- const profileVersion = profileVersionToArray((_a = this.profile) === null || _a === void 0 ? void 0 : _a.versions.firmware);
42270
- if (profileVersion)
42271
- return profileVersion;
42272
- if (this.isProtocolV2())
42273
- return null;
42274
42262
  if (!this.features)
42275
42263
  return null;
42276
42264
  return getDeviceFirmwareVersion(this.features);
42277
42265
  }
42278
42266
  getBLEFirmwareVersion() {
42279
- var _a;
42280
- const profileVersion = profileVersionToArray((_a = this.profile) === null || _a === void 0 ? void 0 : _a.versions.ble);
42281
- if (profileVersion)
42282
- return profileVersion;
42283
- if (this.isProtocolV2())
42284
- return null;
42285
42267
  if (!this.features)
42286
42268
  return null;
42287
42269
  return getDeviceBLEFirmwareVersion(this.features);
@@ -42307,35 +42289,16 @@ class Device extends events.exports {
42307
42289
  return this.isUsed() && !this.isUsedHere();
42308
42290
  }
42309
42291
  isBootloader() {
42310
- if (this.profile) {
42311
- return (this.profile.status.mode === 'bootloader' || this.profile.status.bootloaderMode === true);
42312
- }
42313
- return this.features && !!this.features.bootloader_mode;
42292
+ return this.features && !!this.features.bootloaderMode;
42314
42293
  }
42315
42294
  isInitialized() {
42316
- if (this.profile) {
42317
- if (this.profile.status.initialized != null)
42318
- return this.profile.status.initialized;
42319
- if (this.profile.status.mode === 'normal')
42320
- return true;
42321
- if (this.profile.status.mode === 'notInitialized')
42322
- return false;
42323
- if (this.isProtocolV2())
42324
- return false;
42325
- if (this.features)
42326
- return !!this.features.initialized;
42327
- return false;
42328
- }
42329
42295
  return this.features && !!this.features.initialized;
42330
42296
  }
42331
42297
  isSeedless() {
42332
- if (this.profile) {
42333
- return this.profile.status.noBackup === true;
42334
- }
42335
- return this.features && !!this.features.no_backup;
42298
+ return this.features && !!this.features.noBackup;
42336
42299
  }
42337
42300
  isUnacquired() {
42338
- return this.features === undefined && this.profile === undefined;
42301
+ return this.features === undefined;
42339
42302
  }
42340
42303
  hasUnexpectedMode(allow, require) {
42341
42304
  if (!this.isUnacquired()) {
@@ -42360,7 +42323,7 @@ class Device extends events.exports {
42360
42323
  const isModeT = deviceType === hdShared.EDeviceType.Touch ||
42361
42324
  deviceType === hdShared.EDeviceType.Pro ||
42362
42325
  deviceType === hdShared.EDeviceType.Pro2;
42363
- const unlocked = this.profile ? this.profile.status.unlocked : (_a = this.features) === null || _a === void 0 ? void 0 : _a.unlocked;
42326
+ const unlocked = (_a = this.features) === null || _a === void 0 ? void 0 : _a.unlocked;
42364
42327
  const preCheckTouch = isModeT && unlocked === false;
42365
42328
  const passphraseProtection = this.getCurrentPassphraseProtection();
42366
42329
  return Boolean(passphraseProtection === true || preCheckTouch);
@@ -42394,16 +42357,11 @@ class Device extends events.exports {
42394
42357
  semver__default["default"].gte(firmwareVersion, versionRange.min));
42395
42358
  if (supportUnlock) {
42396
42359
  const res = yield this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
42397
- if (this.profile) {
42398
- this.updateProfile(Object.assign(Object.assign({}, this.profile), { status: Object.assign(Object.assign(Object.assign({}, this.profile.status), { unlocked: res.message.unlocked == null ? null : res.message.unlocked }), (res.message.passphrase_protection != null
42399
- ? { passphraseProtection: res.message.passphrase_protection }
42400
- : {})) }));
42401
- }
42402
42360
  if (this.features) {
42403
42361
  this.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
42404
- this.features.unlocked_attach_pin =
42362
+ this.features.unlockedAttachPin =
42405
42363
  res.message.unlocked_attach_pin == null ? undefined : res.message.unlocked_attach_pin;
42406
- this.features.passphrase_protection =
42364
+ this.features.passphraseProtection =
42407
42365
  res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
42408
42366
  return Promise.resolve(this.features);
42409
42367
  }
@@ -42517,7 +42475,7 @@ const getFirmwareReleaseInfo = (features, firmwareType) => {
42517
42475
  const firmwareStatus = DataManager.getFirmwareStatus(features, firmwareType);
42518
42476
  const changelog = DataManager.getFirmwareChangelog(features, firmwareType);
42519
42477
  const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
42520
- const bootloaderMode = !!features.bootloader_mode;
42478
+ const bootloaderMode = !!features.bootloaderMode;
42521
42479
  return {
42522
42480
  status: firmwareStatus,
42523
42481
  changelog,
@@ -42529,7 +42487,7 @@ const getBleFirmwareReleaseInfo = (features) => {
42529
42487
  const firmwareStatus = DataManager.getBLEFirmwareStatus(features);
42530
42488
  const changelog = DataManager.getBleFirmwareChangelog(features);
42531
42489
  const release = DataManager.getBleFirmwareLatestRelease(features);
42532
- const bootloaderMode = !!features.bootloader_mode;
42490
+ const bootloaderMode = !!features.bootloaderMode;
42533
42491
  return {
42534
42492
  status: firmwareStatus,
42535
42493
  changelog,
@@ -42543,7 +42501,7 @@ const getBootloaderReleaseInfo = ({ features, willUpdateFirmwareVersion, firmwar
42543
42501
  typeof item === 'object' &&
42544
42502
  Object.prototype.hasOwnProperty.call(item, 'zh-CN') &&
42545
42503
  Object.prototype.hasOwnProperty.call(item, 'en-US'));
42546
- const bootloaderMode = !!features.bootloader_mode;
42504
+ const bootloaderMode = !!features.bootloaderMode;
42547
42505
  let shouldUpdate = false;
42548
42506
  const deviceType = getDeviceType(features);
42549
42507
  if (DeviceModelToTypes.model_mini.includes(deviceType)) {
@@ -42911,7 +42869,7 @@ function shouldReadOnekeyFeatures(params) {
42911
42869
  params.scope === 'full');
42912
42870
  }
42913
42871
  function supportOnekeyFeatures(features) {
42914
- if (!features || features.bootloader_mode)
42872
+ if (!features || features.bootloaderMode)
42915
42873
  return false;
42916
42874
  const deviceType = getDeviceType(features);
42917
42875
  return ![
@@ -42951,7 +42909,6 @@ class GetDeviceInfo extends BaseMethod {
42951
42909
  });
42952
42910
  }
42953
42911
  runProtocolV2() {
42954
- var _a, _b, _c;
42955
42912
  return __awaiter(this, void 0, void 0, function* () {
42956
42913
  const sources = ['deviceInfo'];
42957
42914
  const protocolV2DeviceInfo = yield requestProtocolV2DeviceInfo({
@@ -42963,40 +42920,32 @@ class GetDeviceInfo extends BaseMethod {
42963
42920
  sources,
42964
42921
  scope: this.params.scope,
42965
42922
  includeRaw: this.params.includeRaw,
42966
- fallbackSerialNo: (_a = this.device.originalDescriptor) === null || _a === void 0 ? void 0 : _a.path,
42967
42923
  });
42968
- if (typeof this.device.applyProfileUpdate === 'function') {
42969
- this.device.applyProfileUpdate(profile, protocolV2DeviceInfo);
42970
- }
42971
- else {
42972
- (_c = (_b = this.device).updateProfile) === null || _c === void 0 ? void 0 : _c.call(_b, profile);
42973
- }
42924
+ this.device.updateProtocolV2Features(protocolV2DeviceInfo);
42974
42925
  return profile;
42975
42926
  });
42976
42927
  }
42977
42928
  runProtocolV1() {
42978
- var _a, _b;
42979
42929
  return __awaiter(this, void 0, void 0, function* () {
42980
42930
  if (this.params.refresh === true) {
42981
42931
  yield this.device.getFeatures();
42982
42932
  }
42983
42933
  const sources = ['features'];
42984
42934
  const { features } = this.device;
42985
- let onekeyFeatures;
42935
+ let protocolV1OneKeyFeatures;
42986
42936
  if (shouldReadOnekeyFeatures(this.params) && supportOnekeyFeatures(features)) {
42987
42937
  const { message } = yield this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
42988
- onekeyFeatures = normalizeOnekeyFeatures(message);
42989
- sources.push('onekeyFeatures');
42938
+ protocolV1OneKeyFeatures = normalizeOnekeyFeatures(message);
42939
+ sources.push('protocolV1OneKeyFeatures');
42990
42940
  }
42991
42941
  const profile = buildProfileFromProtocolV1({
42992
42942
  protocol: 'V1',
42993
42943
  features,
42994
- onekeyFeatures,
42944
+ protocolV1OneKeyFeatures,
42995
42945
  sources,
42996
42946
  scope: this.params.scope,
42997
42947
  includeRaw: this.params.includeRaw,
42998
42948
  });
42999
- (_b = (_a = this.device).updateProfile) === null || _b === void 0 ? void 0 : _b.call(_a, profile);
43000
42949
  return profile;
43001
42950
  });
43002
42951
  }
@@ -43077,20 +43026,14 @@ class GetOnekeyFeatures extends BaseMethod {
43077
43026
  this.skipForceUpdateCheck = true;
43078
43027
  }
43079
43028
  run() {
43080
- var _a;
43081
43029
  return __awaiter(this, void 0, void 0, function* () {
43082
43030
  if (this.device.isProtocolV2()) {
43083
43031
  const deviceInfo = yield requestProtocolV2DeviceInfo({
43084
43032
  commands: this.device.commands,
43085
43033
  request: PROTOCOL_V2_DEVICE_INFO_REQUEST,
43086
43034
  });
43087
- const profile = this.device.applyProfileUpdate(buildProfileFromProtocolV2({
43088
- deviceInfo,
43089
- sources: ['deviceInfo'],
43090
- scope: 'verify',
43091
- fallbackSerialNo: (_a = this.device.originalDescriptor) === null || _a === void 0 ? void 0 : _a.path,
43092
- }), deviceInfo);
43093
- return pickOnekeyFeatures(buildProtocolV2GetFeaturesPayload(profile, deviceInfo));
43035
+ const features = this.device.updateProtocolV2Features(deviceInfo);
43036
+ return pickOnekeyFeatures(features);
43094
43037
  }
43095
43038
  const { message } = yield this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
43096
43039
  normalizeOnekeyFirmwareVersion(message);
@@ -43118,8 +43061,8 @@ class GetPassphraseState extends BaseMethod {
43118
43061
  const isProSeries = deviceType === hdShared.EDeviceType.Pro || deviceType === hdShared.EDeviceType.Pro2;
43119
43062
  return Promise.resolve({
43120
43063
  passphrase_state: isProSeries || passphraseProtection === true ? passphraseState : undefined,
43121
- session_id: (_b = newSession !== null && newSession !== void 0 ? newSession : features === null || features === void 0 ? void 0 : features.session_id) !== null && _b !== void 0 ? _b : undefined,
43122
- unlocked_attach_pin: unlockedAttachPin !== null && unlockedAttachPin !== void 0 ? unlockedAttachPin : features === null || features === void 0 ? void 0 : features.unlocked_attach_pin,
43064
+ session_id: (_b = newSession !== null && newSession !== void 0 ? newSession : features === null || features === void 0 ? void 0 : features.sessionId) !== null && _b !== void 0 ? _b : undefined,
43065
+ unlocked_attach_pin: unlockedAttachPin !== null && unlockedAttachPin !== void 0 ? unlockedAttachPin : features === null || features === void 0 ? void 0 : features.unlockedAttachPin,
43123
43066
  passphrase_protection: passphraseProtection,
43124
43067
  });
43125
43068
  });
@@ -44071,7 +44014,7 @@ const getBinary = ({ features, updateType, version, isUpdateBootloader, firmware
44071
44014
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no firmware found for this device');
44072
44015
  }
44073
44016
  if (version && !semver__default["default"].eq(releaseInfo.version.join('.'), version.join('.'))) {
44074
- const touchWithoutVersion = getDeviceType(features) === 'touch' && !features.onekey_version;
44017
+ const touchWithoutVersion = getDeviceType(features) === 'touch' && !features.firmwareVersion;
44075
44018
  if (!touchWithoutVersion) {
44076
44019
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'firmware version mismatch');
44077
44020
  }
@@ -44132,7 +44075,7 @@ const isDeviceDisconnectedError$1 = (error) => {
44132
44075
  };
44133
44076
  const postConfirmationMessage = (device) => {
44134
44077
  var _a;
44135
- if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
44078
+ if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmwarePresent) {
44136
44079
  device.emit(DEVICE.BUTTON, device, { code: 'ButtonRequest_FirmwareUpdate' });
44137
44080
  }
44138
44081
  };
@@ -44170,7 +44113,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload, r
44170
44113
  const isFirmware = updateType === 'firmware';
44171
44114
  if (isFirmware && !isUpdateBootloader) {
44172
44115
  const newFeatures = yield typedCall('GetFeatures', 'Features', {});
44173
- const deviceBootloaderVersion = getDeviceBootloaderVersion(newFeatures.message).join('.');
44116
+ const deviceBootloaderVersion = getDeviceBootloaderVersion(buildProtocolV1FeaturesPayload(newFeatures.message, device.features)).join('.');
44174
44117
  const supportUpgradeFileHeader = semver__default["default"].gte(deviceBootloaderVersion, '2.1.0');
44175
44118
  Log$9.debug('supportUpgradeFileHeader:', supportUpgradeFileHeader);
44176
44119
  if (supportUpgradeFileHeader) {
@@ -45299,7 +45242,7 @@ class FirmwareUpdateV2 extends BaseMethod {
45299
45242
  const isMini = deviceType === hdShared.EDeviceType.Mini;
45300
45243
  const isBoot183ClassicUpBle = this.params.updateType === 'firmware' &&
45301
45244
  deviceType === hdShared.EDeviceType.Classic &&
45302
- features.bootloader_version === '1.8.3';
45245
+ getDeviceBootloaderVersion(features).join('.') === '1.8.3';
45303
45246
  return isMini || isBoot183ClassicUpBle;
45304
45247
  }
45305
45248
  isSupportResourceUpdate(features, updateType) {
@@ -45713,7 +45656,7 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
45713
45656
  }),
45714
45657
  ]);
45715
45658
  getFeaturesTimeoutCount = 0;
45716
- const features = featuresRes.message;
45659
+ const features = buildProtocolV1FeaturesPayload(featuresRes.message, this.device.features);
45717
45660
  const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
45718
45661
  const bleVersion = getDeviceBLEFirmwareVersion(features).join('.');
45719
45662
  const firmwareVersion = getDeviceFirmwareVersion(features).join('.');
@@ -46145,17 +46088,17 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46145
46088
  runProtocolV2() {
46146
46089
  var _a, _b;
46147
46090
  return __awaiter(this, void 0, void 0, function* () {
46148
- const legacyFeatures = yield this.getProtocolV2LegacyFeatures();
46149
- const deviceFirmwareType = getFirmwareType(legacyFeatures);
46091
+ const deviceFeatures = yield this.getProtocolV2DeviceFeatures();
46092
+ const deviceFirmwareType = getFirmwareType(deviceFeatures);
46150
46093
  const firmwareType = (_a = this.params.firmwareType) !== null && _a !== void 0 ? _a : deviceFirmwareType;
46151
46094
  let resourceBinary = null;
46152
46095
  let fwBinaryMap = [];
46153
46096
  let bootloaderBinary = null;
46154
46097
  try {
46155
46098
  this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
46156
- resourceBinary = yield this.prepareResourceBinary(firmwareType, legacyFeatures);
46157
- fwBinaryMap = yield this.prepareFirmwareAndBleBinary(firmwareType, legacyFeatures);
46158
- bootloaderBinary = yield this.prepareBootloaderBinary(firmwareType, legacyFeatures);
46099
+ resourceBinary = yield this.prepareResourceBinary(firmwareType, deviceFeatures);
46100
+ fwBinaryMap = yield this.prepareFirmwareAndBleBinary(firmwareType, deviceFeatures);
46101
+ bootloaderBinary = yield this.prepareBootloaderBinary(firmwareType, deviceFeatures);
46159
46102
  fwBinaryMap.push(...this.collectExplicitTargetBinaries());
46160
46103
  this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
46161
46104
  }
@@ -46177,10 +46120,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46177
46120
  return versions;
46178
46121
  });
46179
46122
  }
46180
- getProtocolV2LegacyFeatures() {
46123
+ getProtocolV2DeviceFeatures() {
46181
46124
  return __awaiter(this, void 0, void 0, function* () {
46182
46125
  if (typeof this.device.getFeatures === 'function') {
46183
- return this.device.getFeatures();
46126
+ const features = yield this.device.getFeatures();
46127
+ if (features)
46128
+ return features;
46184
46129
  }
46185
46130
  if (this.device.features) {
46186
46131
  return this.device.features;
@@ -46222,15 +46167,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46222
46167
  });
46223
46168
  }
46224
46169
  isProtocolV2BootloaderMode() {
46225
- var _a, _b, _c;
46170
+ var _a;
46226
46171
  if (typeof this.device.isBootloader === 'function') {
46227
46172
  return this.device.isBootloader();
46228
46173
  }
46229
- const profile = this.device.profile;
46230
- if (((_a = profile === null || profile === void 0 ? void 0 : profile.status) === null || _a === void 0 ? void 0 : _a.mode) === 'bootloader' || ((_b = profile === null || profile === void 0 ? void 0 : profile.status) === null || _b === void 0 ? void 0 : _b.bootloaderMode) === true) {
46231
- return true;
46232
- }
46233
- return !!((_c = this.device.features) === null || _c === void 0 ? void 0 : _c.bootloader_mode);
46174
+ return !!((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.bootloaderMode);
46234
46175
  }
46235
46176
  enterProtocolV2BootloaderMode() {
46236
46177
  var _a, _b, _c;
@@ -46471,13 +46412,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46471
46412
  });
46472
46413
  }
46473
46414
  waitForProtocolV2FinalFeatures() {
46474
- var _a, _b, _c, _d, _e;
46475
46415
  return __awaiter(this, void 0, void 0, function* () {
46476
- const profile = yield this.waitForProtocolV2ReconnectAndProfile(PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT);
46477
- (_b = (_a = this.device).updateProfile) === null || _b === void 0 ? void 0 : _b.call(_a, profile);
46478
- const bootloaderVersion = (_c = profile.versions.bootloader) !== null && _c !== void 0 ? _c : '0.0.0';
46479
- const bleVersion = (_d = profile.versions.ble) !== null && _d !== void 0 ? _d : '0.0.0';
46480
- const firmwareVersion = (_e = profile.versions.firmware) !== null && _e !== void 0 ? _e : '0.0.0';
46416
+ const features = yield this.waitForProtocolV2ReconnectAndFeatures(PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT);
46417
+ const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
46418
+ const bleVersion = getDeviceBLEFirmwareVersion(features).join('.');
46419
+ const firmwareVersion = getDeviceFirmwareVersion(features).join('.');
46481
46420
  if (firmwareVersion === '0.0.0') {
46482
46421
  Log$4.warn('Protocol V2 firmware update finished but app firmware version is still 0.0.0. This is allowed for Pro2 debug BLE-only update flows.');
46483
46422
  }
@@ -46488,8 +46427,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46488
46427
  };
46489
46428
  });
46490
46429
  }
46491
- waitForProtocolV2ReconnectAndProfile(timeout) {
46492
- var _a;
46430
+ waitForProtocolV2ReconnectAndFeatures(timeout) {
46493
46431
  return __awaiter(this, void 0, void 0, function* () {
46494
46432
  const startTime = Date.now();
46495
46433
  let lastError;
@@ -46501,12 +46439,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46501
46439
  timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
46502
46440
  request: PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
46503
46441
  });
46504
- return buildProfileFromProtocolV2({
46505
- deviceInfo,
46506
- sources: ['deviceInfo'],
46507
- scope: 'versions',
46508
- fallbackSerialNo: (_a = this.device.originalDescriptor) === null || _a === void 0 ? void 0 : _a.path,
46509
- });
46442
+ return this.device.updateProtocolV2Features(deviceInfo);
46510
46443
  }
46511
46444
  catch (error) {
46512
46445
  lastError = error;
@@ -51649,7 +51582,6 @@ class TronSignMessage extends BaseMethod {
51649
51582
  return {
51650
51583
  pro2: {
51651
51584
  min: '0.0.0',
51652
- unsupported: true,
51653
51585
  },
51654
51586
  model_mini: {
51655
51587
  min: '2.5.0',
@@ -51806,7 +51738,6 @@ class TronSignTransaction extends BaseMethod {
51806
51738
  return {
51807
51739
  pro2: {
51808
51740
  min: '0.0.0',
51809
- unsupported: true,
51810
51741
  },
51811
51742
  model_mini: {
51812
51743
  min: '2.5.0',
@@ -57763,7 +57694,7 @@ const checkPassphraseEnableState = (method, features) => {
57763
57694
  return;
57764
57695
  const passphraseProtection = method.device
57765
57696
  ? method.device.getCurrentPassphraseProtection()
57766
- : features === null || features === void 0 ? void 0 : features.passphrase_protection;
57697
+ : features === null || features === void 0 ? void 0 : features.passphraseProtection;
57767
57698
  if (passphraseProtection === true) {
57768
57699
  const hasNoPassphraseState = method.payload.passphraseState == null || method.payload.passphraseState === '';
57769
57700
  const shouldRequirePassphrase = !method.payload.useEmptyPassphrase && !method.payload.skipPassphraseCheck;