@onekeyfe/hd-core 1.2.0-alpha.18 → 1.2.0-alpha.19

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 (141) hide show
  1. package/__tests__/device-features-state.test.ts +78 -0
  2. package/__tests__/device-identity.test.ts +30 -0
  3. package/__tests__/device-pool-state.test.ts +113 -0
  4. package/__tests__/device-settings.test.ts +108 -0
  5. package/__tests__/device-state-contract.test.ts +27 -0
  6. package/__tests__/device-state-events.test.ts +163 -0
  7. package/__tests__/device-state-mapper.test.ts +222 -0
  8. package/__tests__/device-state-projector.test.ts +94 -0
  9. package/__tests__/device-state-store.test.ts +115 -0
  10. package/__tests__/device-wallet-session-store.test.ts +46 -0
  11. package/__tests__/deviceFeaturesUtils.test.ts +13 -1
  12. package/__tests__/deviceSettings.test.ts +54 -0
  13. package/__tests__/get-device-state.test.ts +367 -0
  14. package/__tests__/logBlockEvent.test.ts +13 -0
  15. package/__tests__/protocol-v2.test.ts +358 -413
  16. package/__tests__/public-device-state-api.test.ts +153 -0
  17. package/__tests__/refresh-device-state.test.ts +101 -0
  18. package/__tests__/request-context-logging.test.ts +16 -0
  19. package/__tests__/search-devices.test.ts +93 -0
  20. package/dist/api/ClearSessionCache.d.ts.map +1 -1
  21. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  22. package/dist/api/GetDeviceState.d.ts +7 -0
  23. package/dist/api/GetDeviceState.d.ts.map +1 -0
  24. package/dist/api/GetFeatures.d.ts +1 -1
  25. package/dist/api/GetFeatures.d.ts.map +1 -1
  26. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  27. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  28. package/dist/api/SearchDevices.d.ts.map +1 -1
  29. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  30. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  31. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  32. package/dist/api/index.d.ts +1 -4
  33. package/dist/api/index.d.ts.map +1 -1
  34. package/dist/api/internal.d.ts +4 -0
  35. package/dist/api/internal.d.ts.map +1 -0
  36. package/dist/api/protocol-v2/DeviceInfoGet.d.ts +0 -1
  37. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
  38. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
  39. package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +1 -1
  40. package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -1
  41. package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -1
  42. package/dist/api/utils.d.ts +2 -1
  43. package/dist/api/utils.d.ts.map +1 -1
  44. package/dist/constants/index.d.ts +1 -1
  45. package/dist/constants/index.d.ts.map +1 -1
  46. package/dist/core/index.d.ts.map +1 -1
  47. package/dist/device/Device.d.ts +22 -3
  48. package/dist/device/Device.d.ts.map +1 -1
  49. package/dist/device/DeviceFeaturesState.d.ts +4 -0
  50. package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
  51. package/dist/device/DevicePool.d.ts +1 -0
  52. package/dist/device/DevicePool.d.ts.map +1 -1
  53. package/dist/device/DeviceStateMapper.d.ts +13 -0
  54. package/dist/device/DeviceStateMapper.d.ts.map +1 -0
  55. package/dist/device/DeviceStateProjector.d.ts +8 -0
  56. package/dist/device/DeviceStateProjector.d.ts.map +1 -0
  57. package/dist/device/DeviceStateStore.d.ts +23 -0
  58. package/dist/device/DeviceStateStore.d.ts.map +1 -0
  59. package/dist/device/deviceIdentity.d.ts +5 -0
  60. package/dist/device/deviceIdentity.d.ts.map +1 -0
  61. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  62. package/dist/deviceProfile/index.d.ts +0 -1
  63. package/dist/deviceProfile/index.d.ts.map +1 -1
  64. package/dist/events/device.d.ts +7 -2
  65. package/dist/events/device.d.ts.map +1 -1
  66. package/dist/index.d.ts +688 -639
  67. package/dist/index.js +1274 -942
  68. package/dist/inject.d.ts.map +1 -1
  69. package/dist/protocols/protocol-v2/features.d.ts +1 -0
  70. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  71. package/dist/protocols/protocol-v2/index.d.ts +1 -1
  72. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  73. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  74. package/dist/types/api/deviceSettings.d.ts +8 -0
  75. package/dist/types/api/deviceSettings.d.ts.map +1 -1
  76. package/dist/types/api/getDeviceState.d.ts +12 -0
  77. package/dist/types/api/getDeviceState.d.ts.map +1 -0
  78. package/dist/types/api/index.d.ts +4 -7
  79. package/dist/types/api/index.d.ts.map +1 -1
  80. package/dist/types/api/protocolV2.d.ts +1 -6
  81. package/dist/types/api/protocolV2.d.ts.map +1 -1
  82. package/dist/types/device.d.ts +121 -1
  83. package/dist/types/device.d.ts.map +1 -1
  84. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  85. package/dist/utils/deviceSettings.d.ts.map +1 -1
  86. package/dist/utils/patch.d.ts +1 -1
  87. package/dist/utils/tracing.d.ts.map +1 -1
  88. package/package.json +4 -4
  89. package/src/api/ClearSessionCache.ts +4 -0
  90. package/src/api/FirmwareUpdateV4.ts +15 -7
  91. package/src/api/GetDeviceState.ts +55 -0
  92. package/src/api/GetFeatures.ts +8 -3
  93. package/src/api/GetOnekeyFeatures.ts +3 -72
  94. package/src/api/GetPassphraseState.ts +3 -1
  95. package/src/api/SearchDevices.ts +25 -4
  96. package/src/api/device/DeviceRebootToBoardloader.ts +1 -0
  97. package/src/api/device/DeviceRebootToBootloader.ts +1 -0
  98. package/src/api/device/DeviceSettings.ts +28 -0
  99. package/src/api/index.ts +1 -4
  100. package/src/api/internal.ts +9 -0
  101. package/src/api/protocol-v2/DeviceInfoGet.ts +3 -5
  102. package/src/api/protocol-v2/DeviceReboot.ts +3 -1
  103. package/src/api/protocol-v2/DeviceSettingsGet.ts +3 -1
  104. package/src/api/protocol-v2/DeviceSettingsSet.ts +2 -0
  105. package/src/api/protocol-v2/DeviceStatusGet.ts +1 -0
  106. package/src/api/utils.ts +9 -3
  107. package/src/constants/index.ts +1 -4
  108. package/src/core/index.ts +7 -1
  109. package/src/data/messages/messages-protocol-v2.json +22 -13
  110. package/src/device/Device.ts +256 -78
  111. package/src/device/DeviceFeaturesState.ts +34 -0
  112. package/src/device/DevicePool.ts +35 -9
  113. package/src/device/DeviceStateMapper.ts +364 -0
  114. package/src/device/DeviceStateProjector.ts +92 -0
  115. package/src/device/DeviceStateStore.ts +242 -0
  116. package/src/device/deviceIdentity.ts +18 -0
  117. package/src/deviceProfile/buildDeviceFeatures.ts +166 -109
  118. package/src/deviceProfile/index.ts +0 -1
  119. package/src/events/device.ts +13 -1
  120. package/src/events/logBlockEvent.ts +1 -1
  121. package/src/inject.ts +4 -5
  122. package/src/protocols/protocol-v2/features.ts +18 -9
  123. package/src/protocols/protocol-v2/index.ts +1 -0
  124. package/src/protocols/protocol-v2/walletSession.ts +5 -7
  125. package/src/types/api/deviceSettings.ts +8 -0
  126. package/src/types/api/getDeviceState.ts +19 -0
  127. package/src/types/api/index.ts +3 -20
  128. package/src/types/api/protocolV2.ts +0 -24
  129. package/src/types/device.ts +148 -1
  130. package/src/utils/deviceFeaturesUtils.ts +5 -1
  131. package/src/utils/deviceSettings.ts +41 -0
  132. package/src/utils/tracing.ts +3 -1
  133. package/dist/api/GetDeviceInfo.d.ts +0 -9
  134. package/dist/api/GetDeviceInfo.d.ts.map +0 -1
  135. package/dist/deviceProfile/buildDeviceProfile.d.ts +0 -22
  136. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
  137. package/dist/types/api/getDeviceInfo.d.ts +0 -88
  138. package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
  139. package/src/api/GetDeviceInfo.ts +0 -152
  140. package/src/deviceProfile/buildDeviceProfile.ts +0 -370
  141. package/src/types/api/getDeviceInfo.ts +0 -106
package/dist/index.js CHANGED
@@ -123,7 +123,10 @@ const createCoreApi = (call) => ({
123
123
  clearSessionCache: params => call(Object.assign(Object.assign({}, params), { method: 'clearSessionCache' })),
124
124
  searchDevices: params => call(Object.assign(Object.assign({}, params), { method: 'searchDevices' })),
125
125
  getFeatures: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getFeatures' })),
126
- getDeviceInfo: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getDeviceInfo' })),
126
+ getDeviceState: (connectId, params) => {
127
+ const _a = (params !== null && params !== void 0 ? params : {}), commonParams = __rest(_a, ["refresh", "includeRaw"]);
128
+ return call(Object.assign(Object.assign({}, commonParams), { connectId, method: 'getDeviceState' }));
129
+ },
127
130
  getOnekeyFeatures: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getOnekeyFeatures' })),
128
131
  checkFirmwareRelease: connectId => call({ connectId, method: 'checkFirmwareRelease' }),
129
132
  checkBLEFirmwareRelease: connectId => call({ connectId, method: 'checkBLEFirmwareRelease' }),
@@ -143,15 +146,12 @@ const createCoreApi = (call) => ({
143
146
  protocolInfoRequest: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'protocolInfoRequest' })),
144
147
  ping: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'ping' })),
145
148
  deviceReboot: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceReboot' })),
146
- deviceInfoGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceInfoGet' })),
147
- deviceStatusGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceStatusGet' })),
148
149
  deviceGetOnboardingStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetOnboardingStatus' })),
149
150
  deviceSessionOpen: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSessionOpen' })),
150
151
  deviceFirmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFirmwareUpdate' })),
151
152
  deviceGetFirmwareUpdateStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetFirmwareUpdateStatus' })),
152
153
  deviceFactoryInfoSet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFactoryInfoSet' })),
153
154
  deviceFactoryInfoGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFactoryInfoGet' })),
154
- deviceSettingsGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSettingsGet' })),
155
155
  deviceSettingsSet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSettingsSet' })),
156
156
  deviceSettingsPageShow: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSettingsPageShow' })),
157
157
  deviceUploadWallpaper: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceUploadWallpaper' })),
@@ -826,7 +826,7 @@ const createLogMessage = (type, payload) => ({
826
826
 
827
827
  const MAX_ENTRIES = 500;
828
828
  let postMessage$1;
829
- class Log$j {
829
+ class Log$k {
830
830
  constructor(prefix, enabled) {
831
831
  this.prefix = prefix;
832
832
  this.enabled = enabled;
@@ -878,7 +878,7 @@ class Log$j {
878
878
  }
879
879
  const _logs = {};
880
880
  const initLog = (prefix, enabled) => {
881
- const instance = new Log$j(prefix, !!enabled);
881
+ const instance = new Log$k(prefix, !!enabled);
882
882
  _logs[prefix] = instance;
883
883
  return instance;
884
884
  };
@@ -1076,7 +1076,7 @@ function patchFeatures(response) {
1076
1076
  return response;
1077
1077
  }
1078
1078
 
1079
- const Log$i = getLogger(exports.LoggerNames.Core);
1079
+ const Log$j = getLogger(exports.LoggerNames.Core);
1080
1080
  let globalInstanceCounter = 0;
1081
1081
  let sdkInstanceCounter = 0;
1082
1082
  function generateSdkInstanceId() {
@@ -1136,7 +1136,7 @@ function completeRequestContext(responseID, error) {
1136
1136
  context.status = error ? 'error' : 'success';
1137
1137
  if (error) {
1138
1138
  context.error = error.message;
1139
- Log$i.error(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
1139
+ Log$j.debug(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
1140
1140
  }
1141
1141
  globalActiveRequests.delete(responseID);
1142
1142
  if (context.sdkInstanceId) {
@@ -37213,7 +37213,8 @@ var nested = {
37213
37213
  LayoutSafeTxCreate: 1,
37214
37214
  LayoutFinalConfirm: 2,
37215
37215
  Layout7702: 3,
37216
- LayoutFlat: 4
37216
+ LayoutFlat: 4,
37217
+ LayoutEthApprove: 5
37217
37218
  }
37218
37219
  },
37219
37220
  ViewSignPage: {
@@ -37272,6 +37273,18 @@ var nested = {
37272
37273
  rule: "required",
37273
37274
  type: "string",
37274
37275
  id: 3
37276
+ },
37277
+ network: {
37278
+ type: "string",
37279
+ id: 4
37280
+ },
37281
+ derive_type: {
37282
+ type: "string",
37283
+ id: 5
37284
+ },
37285
+ value_key: {
37286
+ type: "uint32",
37287
+ id: 6
37275
37288
  }
37276
37289
  }
37277
37290
  },
@@ -37481,10 +37494,6 @@ var nested = {
37481
37494
  type: "string",
37482
37495
  id: 4
37483
37496
  },
37484
- passphrase_enable: {
37485
- type: "bool",
37486
- id: 6
37487
- },
37488
37497
  brightness: {
37489
37498
  type: "uint32",
37490
37499
  id: 7
@@ -37517,14 +37526,6 @@ var nested = {
37517
37526
  type: "bool",
37518
37527
  id: 14
37519
37528
  },
37520
- fido_enabled: {
37521
- type: "bool",
37522
- id: 15
37523
- },
37524
- experimental_features: {
37525
- type: "bool",
37526
- id: 16
37527
- },
37528
37529
  usb_lock_enable: {
37529
37530
  type: "bool",
37530
37531
  id: 17
@@ -37532,6 +37533,14 @@ var nested = {
37532
37533
  random_keypad: {
37533
37534
  type: "bool",
37534
37535
  id: 18
37536
+ },
37537
+ passphrase_enable: {
37538
+ type: "bool",
37539
+ id: 100
37540
+ },
37541
+ fido_enabled: {
37542
+ type: "bool",
37543
+ id: 101
37535
37544
  }
37536
37545
  }
37537
37546
  },
@@ -39257,7 +39266,7 @@ const findLatestRelease = (releases) => {
39257
39266
  };
39258
39267
 
39259
39268
  var _a$1;
39260
- const Log$h = getLogger(exports.LoggerNames.Core);
39269
+ const Log$i = getLogger(exports.LoggerNames.Core);
39261
39270
  const FIRMWARE_FIELDS = [
39262
39271
  'firmware',
39263
39272
  'firmware-v1',
@@ -39321,37 +39330,37 @@ class DataManager {
39321
39330
  let data = null;
39322
39331
  let fetchMethod = 'none';
39323
39332
  if (settings.configFetcher) {
39324
- Log$h.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
39333
+ Log$i.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
39325
39334
  try {
39326
39335
  data = yield settings.configFetcher(urlWithCache);
39327
39336
  if (data) {
39328
39337
  fetchMethod = 'configFetcher';
39329
- Log$h.log('[DataConfig] ConfigFetcher success');
39338
+ Log$i.log('[DataConfig] ConfigFetcher success');
39330
39339
  }
39331
39340
  else {
39332
- Log$h.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
39341
+ Log$i.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
39333
39342
  }
39334
39343
  }
39335
39344
  catch (e) {
39336
- Log$h.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
39345
+ Log$i.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
39337
39346
  }
39338
39347
  }
39339
39348
  if (!data) {
39340
- Log$h.debug('[DataConfig] Trying axios (SDK default fetcher)...');
39349
+ Log$i.debug('[DataConfig] Trying axios (SDK default fetcher)...');
39341
39350
  try {
39342
39351
  const response = yield axios__default["default"].get(urlWithCache, {
39343
39352
  timeout: 7000,
39344
39353
  });
39345
39354
  data = response.data;
39346
39355
  fetchMethod = 'axios';
39347
- Log$h.log('[DataConfig] Axios fetch success');
39356
+ Log$i.log('[DataConfig] Axios fetch success');
39348
39357
  }
39349
39358
  catch (e) {
39350
- Log$h.warn('[DataConfig] Axios fetch error:', e);
39359
+ Log$i.warn('[DataConfig] Axios fetch error:', e);
39351
39360
  }
39352
39361
  }
39353
39362
  if (data) {
39354
- Log$h.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
39363
+ Log$i.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
39355
39364
  this.deviceMap = {
39356
39365
  [hdShared.EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
39357
39366
  [hdShared.EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
@@ -39366,7 +39375,7 @@ class DataManager {
39366
39375
  };
39367
39376
  }
39368
39377
  else {
39369
- Log$h.warn('[DataConfig] All fetch methods failed, using built-in default config');
39378
+ Log$i.warn('[DataConfig] All fetch methods failed, using built-in default config');
39370
39379
  }
39371
39380
  });
39372
39381
  }
@@ -39797,6 +39806,7 @@ const DEVICE = {
39797
39806
  SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE: 'select_device_in_bootloader_for_web_device',
39798
39807
  SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: 'select_device_for_switch_firmware_web_device',
39799
39808
  FEATURES: 'features',
39809
+ STATE: 'state',
39800
39810
  };
39801
39811
  const createDeviceMessage = (type, payload) => ({
39802
39812
  event: DEVICE_EVENT,
@@ -39819,7 +39829,7 @@ const LogBlockEvent = new Set([
39819
39829
  UI_RESPONSE.RECEIVE_PIN,
39820
39830
  UI_RESPONSE.RECEIVE_PASSPHRASE,
39821
39831
  ]);
39822
- const LogBlockMethod = new Set(['evmSignTypedData']);
39832
+ const LogBlockMethod = new Set(['evmSignTypedData', 'deviceSessionOpen']);
39823
39833
  function getLogBlockLabel(message) {
39824
39834
  if (!message || typeof message !== 'object')
39825
39835
  return undefined;
@@ -39862,18 +39872,6 @@ const normalizeHostPassphrase = (passphrase) => {
39862
39872
  }
39863
39873
  return normalized;
39864
39874
  };
39865
- function requestProtocolV2DeviceStatus$1(device) {
39866
- return __awaiter(this, void 0, void 0, function* () {
39867
- const { message } = yield device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
39868
- return message;
39869
- });
39870
- }
39871
- function refreshProtocolV2DeviceStatus(device) {
39872
- return __awaiter(this, void 0, void 0, function* () {
39873
- const status = yield requestProtocolV2DeviceStatus$1(device);
39874
- return device.updateProtocolV2Status(status);
39875
- });
39876
- }
39877
39875
  const openDeviceSession = (device, request) => __awaiter(void 0, void 0, void 0, function* () {
39878
39876
  try {
39879
39877
  return yield device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
@@ -39926,7 +39924,7 @@ const openSelectedHiddenWallet = (device, promptPayload) => __awaiter(void 0, vo
39926
39924
  return openDeviceSession(device, request);
39927
39925
  });
39928
39926
  function getProtocolV2WalletSession(device, options) {
39929
- var _a, _b, _c, _d, _e, _f;
39927
+ var _a, _b, _c, _d, _e, _f, _g;
39930
39928
  return __awaiter(this, void 0, void 0, function* () {
39931
39929
  if (options === null || options === void 0 ? void 0 : options.initSession) {
39932
39930
  device.clearInternalState();
@@ -39974,14 +39972,11 @@ function getProtocolV2WalletSession(device, options) {
39974
39972
  device.clearInternalState();
39975
39973
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
39976
39974
  }
39977
- if (message.btc_test_address && device.getCurrentPassphraseProtection() !== true) {
39978
- yield refreshProtocolV2DeviceStatus(device);
39979
- }
39980
- device.updateInternalState(true, message.btc_test_address, device.getCurrentDeviceId(), message.session_id, (options === null || options === void 0 ? void 0 : options.initSession) ? null : (_d = device.features) === null || _d === void 0 ? void 0 : _d.sessionId);
39975
+ device.updateInternalState(true, message.btc_test_address, device.getCurrentDeviceId(), message.session_id, (options === null || options === void 0 ? void 0 : options.initSession) ? null : (_e = (_d = device.features) === null || _d === void 0 ? void 0 : _d.sessionId) !== null && _e !== void 0 ? _e : null);
39981
39976
  return {
39982
39977
  passphraseState: message.btc_test_address,
39983
39978
  newSession: message.session_id,
39984
- unlockedAttachPin: (_f = (_e = device.features) === null || _e === void 0 ? void 0 : _e.unlockedAttachPin) !== null && _f !== void 0 ? _f : undefined,
39979
+ unlockedAttachPin: (_g = (_f = device.features) === null || _f === void 0 ? void 0 : _f.unlockedAttachPin) !== null && _g !== void 0 ? _g : undefined,
39985
39980
  };
39986
39981
  }
39987
39982
  catch (error) {
@@ -40033,7 +40028,9 @@ const supportInputPinOnSoftware = (features) => {
40033
40028
  if (!features)
40034
40029
  return { support: false };
40035
40030
  const deviceType = getDeviceType(features);
40036
- if (deviceType === hdShared.EDeviceType.Touch || deviceType === hdShared.EDeviceType.Pro) {
40031
+ if (deviceType === hdShared.EDeviceType.Touch ||
40032
+ deviceType === hdShared.EDeviceType.Pro ||
40033
+ deviceType === hdShared.EDeviceType.Pro2) {
40037
40034
  return { support: false };
40038
40035
  }
40039
40036
  const currentVersion = getDeviceFirmwareVersion(features).join('.');
@@ -40416,6 +40413,25 @@ const LANGUAGE_LABELS = {
40416
40413
  it: 'Italiano',
40417
40414
  pt_br: 'Portuguese (Brazil)',
40418
40415
  };
40416
+ const PRO2_LANGUAGE_OPTIONS = [
40417
+ { code: 'en-Latn-US', label: 'English' },
40418
+ { code: 'zh-Hans-CN', label: '简体中文' },
40419
+ { code: 'zh-Hant-HK', label: '繁體中文(香港)' },
40420
+ { code: 'zh-Hant-TW', label: '繁體中文(台灣)' },
40421
+ { code: 'ja-Jpan-JP', label: '日本語' },
40422
+ { code: 'ko-Kore-KR', label: '한국어' },
40423
+ { code: 'fr-Latn-FR', label: 'Français' },
40424
+ { code: 'de-Latn-DE', label: 'Deutsch' },
40425
+ { code: 'ru-Cyrl-RU', label: 'Русский' },
40426
+ { code: 'es-Latn-ES', label: 'Español' },
40427
+ { code: 'it-Latn-IT', label: 'Italiano' },
40428
+ { code: 'pt-Latn-BR', label: 'Portuguese (Brazil)' },
40429
+ { code: 'vi-Latn-VN', label: 'Tiếng Việt' },
40430
+ { code: 'tr-Latn-TR', label: 'Türkçe' },
40431
+ { code: 'id-Latn-ID', label: 'Bahasa Indonesia' },
40432
+ { code: 'fil-Latn-PH', label: 'Filipino' },
40433
+ { code: 'uk-Cyrl-UA', label: 'Українська' },
40434
+ ];
40419
40435
  const getLanguageConfig = (deviceType) => {
40420
40436
  let keys = [];
40421
40437
  switch (deviceType) {
@@ -40431,6 +40447,8 @@ const getLanguageConfig = (deviceType) => {
40431
40447
  case hdShared.EDeviceType.Pro:
40432
40448
  keys = Object.keys(LANGUAGE_LABELS);
40433
40449
  break;
40450
+ case hdShared.EDeviceType.Pro2:
40451
+ return PRO2_LANGUAGE_OPTIONS.map(option => (Object.assign({}, option)));
40434
40452
  default:
40435
40453
  keys = [];
40436
40454
  break;
@@ -40461,6 +40479,16 @@ const getAutoLockOptions = (_deviceType) => {
40461
40479
  { seconds: 0, minute: 30, hour: 0, day: 0 },
40462
40480
  { seconds: 0, minute: 0, hour: 0, day: 0 },
40463
40481
  ];
40482
+ case hdShared.EDeviceType.Pro2:
40483
+ return [
40484
+ { seconds: 30, minute: 0, hour: 0, day: 0 },
40485
+ { seconds: 0, minute: 1, hour: 0, day: 0 },
40486
+ { seconds: 0, minute: 2, hour: 0, day: 0 },
40487
+ { seconds: 0, minute: 5, hour: 0, day: 0 },
40488
+ { seconds: 0, minute: 10, hour: 0, day: 0 },
40489
+ { seconds: 0, minute: 30, hour: 0, day: 0 },
40490
+ { seconds: 0, minute: 0, hour: 0, day: 0 },
40491
+ ];
40464
40492
  default:
40465
40493
  return [];
40466
40494
  }
@@ -40488,6 +40516,15 @@ const getAutoShutDownOptions = (_deviceType) => {
40488
40516
  { seconds: 0, minute: 10, hour: 0, day: 0 },
40489
40517
  { seconds: 0, minute: 0, hour: 0, day: 0 },
40490
40518
  ];
40519
+ case hdShared.EDeviceType.Pro2:
40520
+ return [
40521
+ { seconds: 0, minute: 1, hour: 0, day: 0 },
40522
+ { seconds: 0, minute: 2, hour: 0, day: 0 },
40523
+ { seconds: 0, minute: 5, hour: 0, day: 0 },
40524
+ { seconds: 0, minute: 10, hour: 0, day: 0 },
40525
+ { seconds: 0, minute: 30, hour: 0, day: 0 },
40526
+ { seconds: 0, minute: 0, hour: 0, day: 0 },
40527
+ ];
40491
40528
  default:
40492
40529
  return [];
40493
40530
  }
@@ -40922,7 +40959,7 @@ const getDefectiveDeviceInfo = (features) => {
40922
40959
  };
40923
40960
  };
40924
40961
 
40925
- const Log$g = getLogger(exports.LoggerNames.DevicePool);
40962
+ const Log$h = getLogger(exports.LoggerNames.DevicePool);
40926
40963
  const getDiff = (current, descriptors) => {
40927
40964
  const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
40928
40965
  const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
@@ -40974,12 +41011,13 @@ class DevicePool extends events.exports {
40974
41011
  const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
40975
41012
  if (exist) {
40976
41013
  device.updateDescriptor(exist, true);
41014
+ yield this._refreshRuntimeState(device, initOptions);
40977
41015
  devices[connectId] = device;
40978
41016
  deviceList.push(device);
40979
41017
  yield this._checkDevicePool(initOptions, connectId);
40980
41018
  return { devices, deviceList };
40981
41019
  }
40982
- Log$g.debug('found device in cache, but path is different: ', connectId);
41020
+ Log$h.debug('found device in cache, but path is different: ', connectId);
40983
41021
  }
40984
41022
  }
40985
41023
  const matchedDescriptor = connectId
@@ -41027,12 +41065,38 @@ class DevicePool extends events.exports {
41027
41065
  device = Device.fromDescriptor(descriptor);
41028
41066
  device.deviceConnector = this.connector;
41029
41067
  yield device.connect(initOptions === null || initOptions === void 0 ? void 0 : initOptions.connectProtocol);
41030
- yield device.initialize(initOptions);
41031
- yield device.release();
41068
+ try {
41069
+ yield device.initialize(initOptions);
41070
+ if ((initOptions === null || initOptions === void 0 ? void 0 : initOptions.refreshRuntimeState) && device.isProtocolV2()) {
41071
+ yield device.getDeviceState({ refreshSections: ['status'] });
41072
+ }
41073
+ }
41074
+ finally {
41075
+ yield device.release();
41076
+ }
41032
41077
  }
41033
41078
  return device;
41034
41079
  });
41035
41080
  }
41081
+ static _refreshRuntimeState(device, initOptions) {
41082
+ return __awaiter(this, void 0, void 0, function* () {
41083
+ if (!(initOptions === null || initOptions === void 0 ? void 0 : initOptions.refreshRuntimeState) || !device.isProtocolV2())
41084
+ return;
41085
+ let refreshError;
41086
+ yield device.run(() => __awaiter(this, void 0, void 0, function* () {
41087
+ try {
41088
+ yield device.getDeviceState({ refreshSections: ['status'] });
41089
+ }
41090
+ catch (error) {
41091
+ refreshError = error;
41092
+ }
41093
+ }), { connectProtocol: initOptions.connectProtocol });
41094
+ if (refreshError instanceof Error)
41095
+ throw refreshError;
41096
+ if (refreshError)
41097
+ throw new Error(String(refreshError));
41098
+ });
41099
+ }
41036
41100
  static _checkDevicePool(initOptions, connectId) {
41037
41101
  return __awaiter(this, void 0, void 0, function* () {
41038
41102
  yield this._sendConnectMessage(initOptions, connectId);
@@ -41043,21 +41107,21 @@ class DevicePool extends events.exports {
41043
41107
  return __awaiter(this, void 0, void 0, function* () {
41044
41108
  for (let i = this.connectedPool.length - 1; i >= 0; i--) {
41045
41109
  const descriptor = this.connectedPool[i];
41046
- if (connectId && descriptor.path !== connectId) {
41047
- continue;
41110
+ if (!connectId || descriptor.path === connectId) {
41111
+ const device = yield this._createDevice(descriptor, initOptions);
41112
+ Log$h.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
41113
+ this.emitter.emit(DEVICE.CONNECT, device);
41114
+ this.connectedPool.splice(i, 1);
41048
41115
  }
41049
- const device = yield this._createDevice(descriptor, initOptions);
41050
- Log$g.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
41051
- this.emitter.emit(DEVICE.CONNECT, device);
41052
- this.connectedPool.splice(i, 1);
41053
41116
  }
41054
41117
  });
41055
41118
  }
41056
41119
  static _sendDisconnectMessage() {
41057
41120
  for (let i = this.disconnectPool.length - 1; i >= 0; i--) {
41058
- const descriptor = this.connectedPool[i];
41121
+ const descriptor = this.disconnectPool[i];
41059
41122
  const device = (descriptor === null || descriptor === void 0 ? void 0 : descriptor.path) ? this.getDeviceByPath(descriptor.path) : null;
41060
41123
  if (device) {
41124
+ device.markTransportDisconnected();
41061
41125
  this.emitter.emit(DEVICE.DISCONNECT, device);
41062
41126
  }
41063
41127
  this.disconnectPool.splice(i, 1);
@@ -41067,9 +41131,9 @@ class DevicePool extends events.exports {
41067
41131
  const diff = getDiff(this.current || [], upcoming);
41068
41132
  this.upcoming = upcoming;
41069
41133
  this.current = this.upcoming;
41070
- Log$g.debug('device pool -> current: ', this.current);
41071
- Log$g.debug('device pool -> upcomming: ', this.upcoming);
41072
- Log$g.debug('DeviceCache.reportDeviceChange diff: ', diff);
41134
+ Log$h.debug('device pool -> current: ', this.current);
41135
+ Log$h.debug('device pool -> upcomming: ', this.upcoming);
41136
+ Log$h.debug('DeviceCache.reportDeviceChange diff: ', diff);
41073
41137
  if (!diff.didUpdate) {
41074
41138
  return;
41075
41139
  }
@@ -41079,7 +41143,7 @@ class DevicePool extends events.exports {
41079
41143
  this._addConnectedDeviceToPool(d);
41080
41144
  return;
41081
41145
  }
41082
- Log$g.debug('emit DEVICE.CONNECT: ', device.features);
41146
+ Log$h.debug('emit DEVICE.CONNECT: ', device.features);
41083
41147
  this.emitter.emit(DEVICE.CONNECT, device);
41084
41148
  });
41085
41149
  diff.disconnected.forEach(d => {
@@ -41089,7 +41153,8 @@ class DevicePool extends events.exports {
41089
41153
  this._addDisconnectedDeviceToPool(d);
41090
41154
  return;
41091
41155
  }
41092
- Log$g.debug('emit DEVICE.DISCONNECT: ', device.features);
41156
+ Log$h.debug('emit DEVICE.DISCONNECT: ', device.features);
41157
+ device.markTransportDisconnected();
41093
41158
  this.emitter.emit(DEVICE.DISCONNECT, device);
41094
41159
  });
41095
41160
  }
@@ -41125,7 +41190,7 @@ class DevicePool extends events.exports {
41125
41190
  this.disconnectPool = [];
41126
41191
  this.devicesCache = {};
41127
41192
  this.emitter.removeAllListeners();
41128
- Log$g.debug('DevicePool state has been reset');
41193
+ Log$h.debug('DevicePool state has been reset');
41129
41194
  }
41130
41195
  }
41131
41196
  DevicePool.current = null;
@@ -41135,7 +41200,7 @@ DevicePool.disconnectPool = [];
41135
41200
  DevicePool.devicesCache = {};
41136
41201
  DevicePool.emitter = new events.exports();
41137
41202
 
41138
- const Log$f = getLogger(exports.LoggerNames.Transport);
41203
+ const Log$g = getLogger(exports.LoggerNames.Transport);
41139
41204
  const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
41140
41205
  const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
41141
41206
  const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
@@ -41145,7 +41210,7 @@ const WebUsbLogger = getLogger(exports.LoggerNames.HdTransportWebUsb);
41145
41210
  const REACT_NATIVE_BLE_SCAN_TIMEOUT_MS = 8000;
41146
41211
  class TransportManager {
41147
41212
  static load() {
41148
- Log$f.debug('transport manager load');
41213
+ Log$g.debug('transport manager load');
41149
41214
  this.defaultMessages = DataManager.getProtobufMessages();
41150
41215
  this.currentMessages = this.defaultMessages;
41151
41216
  this.protocolV1MessageSchema = 'v1CurrentSchema';
@@ -41154,14 +41219,14 @@ class TransportManager {
41154
41219
  return __awaiter(this, void 0, void 0, function* () {
41155
41220
  try {
41156
41221
  const env = DataManager.getSettings('env');
41157
- Log$f.debug('Initializing transports', env);
41222
+ Log$g.debug('Initializing transports', env);
41158
41223
  if (env === 'react-native') {
41159
41224
  if (!this.reactNativeInit) {
41160
41225
  yield this.transport.init(BleLogger, DevicePool.emitter);
41161
41226
  this.reactNativeInit = true;
41162
41227
  }
41163
41228
  else {
41164
- Log$f.debug('React Native Do Not Initializing transports');
41229
+ Log$g.debug('React Native Do Not Initializing transports');
41165
41230
  }
41166
41231
  }
41167
41232
  else if (env === 'node-usb') {
@@ -41182,15 +41247,15 @@ class TransportManager {
41182
41247
  else {
41183
41248
  yield this.transport.init(HttpLogger);
41184
41249
  }
41185
- Log$f.debug('Configuring transports');
41250
+ Log$g.debug('Configuring transports');
41186
41251
  yield this.transport.configure(JSON.stringify(this.defaultMessages));
41187
41252
  this.currentMessages = this.defaultMessages;
41188
41253
  this.protocolV1MessageSchema = 'v1CurrentSchema';
41189
41254
  yield this.configureProtocolV2Messages();
41190
- Log$f.debug('Configuring transports done');
41255
+ Log$g.debug('Configuring transports done');
41191
41256
  }
41192
41257
  catch (error) {
41193
- Log$f.debug('Initializing transports error: ', error);
41258
+ Log$g.debug('Initializing transports error: ', error);
41194
41259
  if (error.code === 'ECONNABORTED') {
41195
41260
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
41196
41261
  }
@@ -41206,7 +41271,7 @@ class TransportManager {
41206
41271
  if (this.currentMessages === messages || !messages) {
41207
41272
  return;
41208
41273
  }
41209
- Log$f.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
41274
+ Log$g.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
41210
41275
  try {
41211
41276
  yield this.transport.configure(JSON.stringify(messages));
41212
41277
  this.currentMessages = messages;
@@ -41229,9 +41294,9 @@ class TransportManager {
41229
41294
  }
41230
41295
  if (plugin) {
41231
41296
  this.plugin = plugin;
41232
- Log$f.debug('set transport plugin: ', this.plugin);
41297
+ Log$g.debug('set transport plugin: ', this.plugin);
41233
41298
  }
41234
- Log$f.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
41299
+ Log$g.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
41235
41300
  }
41236
41301
  static getTransport() {
41237
41302
  return this.transport;
@@ -41242,7 +41307,7 @@ class TransportManager {
41242
41307
  const { configureProtocolV2 } = this.transport;
41243
41308
  if (protocolV2Messages && typeof configureProtocolV2 === 'function') {
41244
41309
  yield configureProtocolV2.call(this.transport, JSON.stringify(protocolV2Messages));
41245
- Log$f.debug('Protocol V2 messages configured');
41310
+ Log$g.debug('Protocol V2 messages configured');
41246
41311
  }
41247
41312
  });
41248
41313
  }
@@ -41420,7 +41485,7 @@ const cancelDeviceWithInitialize = (device) => {
41420
41485
  },
41421
41486
  }));
41422
41487
  };
41423
- const Log$e = getLogger(exports.LoggerNames.DeviceCommands);
41488
+ const Log$f = getLogger(exports.LoggerNames.DeviceCommands);
41424
41489
  const LogCore = getLogger(exports.LoggerNames.Core);
41425
41490
  class DeviceCommands {
41426
41491
  constructor(device, mainId) {
@@ -41429,7 +41494,7 @@ class DeviceCommands {
41429
41494
  this.transport = TransportManager.getTransport();
41430
41495
  this.disposed = false;
41431
41496
  this.instanceId = generateInstanceId('DeviceCommands', device.sdkInstanceId);
41432
- Log$e.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
41497
+ Log$f.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
41433
41498
  }
41434
41499
  dispose(_cancelRequest) {
41435
41500
  var _a, _b;
@@ -41499,7 +41564,7 @@ class DeviceCommands {
41499
41564
  return __awaiter(this, void 0, void 0, function* () {
41500
41565
  const shouldReduceDebug = shouldReduceDebugForCall(type);
41501
41566
  if (!shouldReduceDebug) {
41502
- Log$e.debug('[DeviceCommands] [call] Sending', type);
41567
+ Log$f.debug('[DeviceCommands] [call] Sending', type);
41503
41568
  }
41504
41569
  try {
41505
41570
  const promise = this.transport.call(this.mainId, type, msg !== null && msg !== void 0 ? msg : {}, options);
@@ -41534,7 +41599,7 @@ class DeviceCommands {
41534
41599
  }
41535
41600
  }
41536
41601
  if (responseData) {
41537
- Log$e.debug('error response', responseData);
41602
+ Log$f.debug('error response', responseData);
41538
41603
  }
41539
41604
  if (responseError === 'device disconnected during action') {
41540
41605
  return { type: 'BridgeDeviceDisconnected', message: { error: responseError } };
@@ -41574,7 +41639,7 @@ class DeviceCommands {
41574
41639
  'ResourceAck',
41575
41640
  ];
41576
41641
  if (!skipTypes.includes(type) && msg) {
41577
- Log$e.debug('[DeviceCommands] [typedCall] Sending payload', type, sanitizeDebugPayload(msg));
41642
+ Log$f.debug('[DeviceCommands] [typedCall] Sending payload', type, sanitizeDebugPayload(msg));
41578
41643
  }
41579
41644
  }
41580
41645
  catch (e) {
@@ -41585,10 +41650,10 @@ class DeviceCommands {
41585
41650
  assertType(response, resType);
41586
41651
  }
41587
41652
  catch (error) {
41588
- Log$e.debug('DeviceCommands typedcall error: ', error);
41653
+ Log$f.debug('DeviceCommands typedcall error: ', error);
41589
41654
  if (error instanceof hdShared.HardwareError) {
41590
41655
  if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
41591
- Log$e.debug('[DeviceCommands] [typedCall] Unexpected response type', {
41656
+ Log$f.debug('[DeviceCommands] [typedCall] Unexpected response type', {
41592
41657
  request: type,
41593
41658
  expected: resType,
41594
41659
  received: response.type,
@@ -41625,10 +41690,10 @@ class DeviceCommands {
41625
41690
  if (shouldReduceDebugForCall(callType)) {
41626
41691
  }
41627
41692
  else if (DataManager.getSettings('env') === 'react-native') {
41628
- Log$e.debug('_filterCommonTypes: ', JSON.stringify(sanitizeDebugPayload(res)));
41693
+ Log$f.debug('_filterCommonTypes: ', JSON.stringify(sanitizeDebugPayload(res)));
41629
41694
  }
41630
41695
  else {
41631
- Log$e.debug('_filterCommonTypes: ', sanitizeDebugPayload(res));
41696
+ Log$f.debug('_filterCommonTypes: ', sanitizeDebugPayload(res));
41632
41697
  }
41633
41698
  }
41634
41699
  catch (error) {
@@ -41765,7 +41830,7 @@ class DeviceCommands {
41765
41830
  reject(error);
41766
41831
  });
41767
41832
  const listenerCount = this.device.listenerCount(DEVICE.PIN);
41768
- Log$e.debug(`[${this.instanceId}] _promptPin called`, {
41833
+ Log$f.debug(`[${this.instanceId}] _promptPin called`, {
41769
41834
  responseID: this.currentResponseID,
41770
41835
  deviceInstanceId: this.device.instanceId,
41771
41836
  listenerCount,
@@ -41841,84 +41906,18 @@ class DeviceCommands {
41841
41906
  }
41842
41907
  }
41843
41908
 
41844
- class DeviceWalletSessionStore {
41845
- constructor() {
41846
- this.walletSessions = new Map();
41847
- this.pendingSessions = new Map();
41848
- }
41849
- get(deviceKey, passphraseState) {
41850
- var _a;
41851
- if (!deviceKey || !passphraseState)
41852
- return undefined;
41853
- return (_a = this.walletSessions.get(deviceKey)) === null || _a === void 0 ? void 0 : _a.get(passphraseState);
41854
- }
41855
- set(deviceKey, passphraseState, sessionId) {
41856
- if (!deviceKey || !passphraseState || !sessionId)
41857
- return;
41858
- let deviceSessions = this.walletSessions.get(deviceKey);
41859
- if (!deviceSessions) {
41860
- deviceSessions = new Map();
41861
- this.walletSessions.set(deviceKey, deviceSessions);
41862
- }
41863
- deviceSessions.set(passphraseState, sessionId);
41864
- }
41865
- setPending(deviceKey, sessionId) {
41866
- if (!deviceKey || !sessionId)
41867
- return;
41868
- this.pendingSessions.set(deviceKey, sessionId);
41869
- }
41870
- getPending(deviceKey) {
41871
- if (!deviceKey)
41872
- return undefined;
41873
- return this.pendingSessions.get(deviceKey);
41874
- }
41875
- delete(deviceKey, passphraseState) {
41876
- if (!deviceKey || !passphraseState)
41877
- return;
41878
- const deviceSessions = this.walletSessions.get(deviceKey);
41879
- if (!deviceSessions)
41880
- return;
41881
- deviceSessions.delete(passphraseState);
41882
- if (deviceSessions.size === 0) {
41883
- this.walletSessions.delete(deviceKey);
41884
- }
41885
- }
41886
- deletePending(deviceKey) {
41887
- if (!deviceKey)
41888
- return;
41889
- this.pendingSessions.delete(deviceKey);
41890
- }
41891
- deleteDevice(deviceKey) {
41892
- if (!deviceKey)
41893
- return;
41894
- this.walletSessions.delete(deviceKey);
41895
- this.pendingSessions.delete(deviceKey);
41896
- }
41897
- migrateDeviceKey(from, to) {
41898
- var _a;
41899
- if (!from || !to || from === to)
41900
- return;
41901
- const sourceSessions = this.walletSessions.get(from);
41902
- if (sourceSessions) {
41903
- const targetSessions = (_a = this.walletSessions.get(to)) !== null && _a !== void 0 ? _a : new Map();
41904
- this.walletSessions.set(to, targetSessions);
41905
- sourceSessions.forEach((sessionId, passphraseState) => {
41906
- targetSessions.set(passphraseState, sessionId);
41907
- });
41908
- this.walletSessions.delete(from);
41909
- }
41910
- const pendingSession = this.pendingSessions.get(from);
41911
- if (pendingSession) {
41912
- this.pendingSessions.set(to, pendingSession);
41913
- this.pendingSessions.delete(from);
41909
+ function mergeDeviceFeaturesPatch(previous, patch) {
41910
+ let next = previous;
41911
+ for (const [key, value] of Object.entries(patch)) {
41912
+ if (value !== undefined && !Object.is(previous[key], value)) {
41913
+ if (next === previous) {
41914
+ next = Object.assign({}, previous);
41915
+ }
41916
+ next[key] = value;
41914
41917
  }
41915
41918
  }
41916
- clear() {
41917
- this.walletSessions.clear();
41918
- this.pendingSessions.clear();
41919
- }
41919
+ return next;
41920
41920
  }
41921
- const deviceWalletSessionStore = new DeviceWalletSessionStore();
41922
41921
 
41923
41922
  const isProtocolV2RomloaderDeviceInfo = (deviceInfo, deviceStatus) => {
41924
41923
  var _a, _b, _c;
@@ -41933,9 +41932,16 @@ const isProtocolV2RomloaderDeviceInfo = (deviceInfo, deviceStatus) => {
41933
41932
  deviceInfo.se3 == null &&
41934
41933
  deviceInfo.se4 == null;
41935
41934
  };
41936
- const isProtocolV2BootloaderDeviceInfo = (deviceInfo, deviceStatus) => !!deviceInfo &&
41937
- deviceStatus == null &&
41938
- !isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus);
41935
+ const isProtocolV2BootloaderDeviceInfo = (deviceInfo, deviceStatus) => {
41936
+ var _a, _b;
41937
+ return !!deviceInfo &&
41938
+ deviceStatus == null &&
41939
+ !isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus) &&
41940
+ ((_a = deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.application) == null &&
41941
+ ((_b = deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.application_data) == null;
41942
+ };
41943
+ const isProtocolV2LoaderDeviceInfo = (deviceInfo, deviceStatus) => isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus) ||
41944
+ isProtocolV2BootloaderDeviceInfo(deviceInfo, deviceStatus);
41939
41945
  const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
41940
41946
  targets: {
41941
41947
  hw: true,
@@ -41979,7 +41985,6 @@ const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
41979
41985
  specific: true,
41980
41986
  },
41981
41987
  };
41982
- const PROTOCOL_V2_DEVICE_INFO_REQUEST = PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
41983
41988
  const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
41984
41989
  function requestProtocolV2DeviceInfo({ commands, timeoutMs = PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS, request = PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST, }) {
41985
41990
  return __awaiter(this, void 0, void 0, function* () {
@@ -41996,235 +42001,6 @@ function requestProtocolV2DeviceStatus({ commands, }) {
41996
42001
  });
41997
42002
  }
41998
42003
 
41999
- const isMeaningfulVersion = (version) => Boolean(version && version !== '0.0.0');
42000
- const firstMeaningfulVersion$1 = (...versions) => { var _a; return (_a = versions.find(isMeaningfulVersion)) !== null && _a !== void 0 ? _a : null; };
42001
- const versionArrayToString = (version) => {
42002
- if (!version || version.length === 0)
42003
- return null;
42004
- const value = version.join('.');
42005
- return isMeaningfulVersion(value) ? value : null;
42006
- };
42007
- const bytesToHex$3 = (value) => {
42008
- if (!value)
42009
- return undefined;
42010
- if (typeof value === 'string')
42011
- return value;
42012
- if (value instanceof Uint8Array) {
42013
- return Array.from(value)
42014
- .map(byte => byte.toString(16).padStart(2, '0'))
42015
- .join('');
42016
- }
42017
- if (Array.isArray(value)) {
42018
- return value.map(byte => Number(byte).toString(16).padStart(2, '0')).join('');
42019
- }
42020
- return undefined;
42021
- };
42022
- const getImageVersion$1 = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : null; };
42023
- const getImageBuildId$1 = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
42024
- const getImageHash$1 = (image) => bytesToHex$3(image === null || image === void 0 ? void 0 : image.hash);
42025
- const shouldIncludeVerify = (scope) => scope === 'verify' || scope === 'full';
42026
- const getDeviceMode = (features) => {
42027
- if (!features)
42028
- return 'unknown';
42029
- if (features.bootloaderMode === true)
42030
- return 'bootloader';
42031
- if (features.initialized === false)
42032
- return 'notInitialized';
42033
- if (features.initialized === true)
42034
- return 'normal';
42035
- return 'unknown';
42036
- };
42037
- const getProtocolV2Mode = (deviceInfo, deviceStatus) => {
42038
- if (isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus))
42039
- return 'romloader';
42040
- if (isProtocolV2BootloaderDeviceInfo(deviceInfo, deviceStatus))
42041
- return 'bootloader';
42042
- const initialized = deviceStatus === null || deviceStatus === void 0 ? void 0 : deviceStatus.init_states;
42043
- if (initialized === false)
42044
- return 'notInitialized';
42045
- if (initialized === true)
42046
- return 'normal';
42047
- return 'unknown';
42048
- };
42049
- const normalizeV1Versions = (features, protocolV1OneKeyFeatures) => ({
42050
- firmware: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_firmware_version, versionArrayToString(getDeviceFirmwareVersion(features))),
42051
- bootloader: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_boot_version, versionArrayToString(getDeviceBootloaderVersion(features))),
42052
- board: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_board_version, versionArrayToString(features ? getDeviceBoardloaderVersion(features) : undefined)),
42053
- 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)),
42054
- se01: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_version, features === null || features === void 0 ? void 0 : features.se01Version),
42055
- se02: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_version, features === null || features === void 0 ? void 0 : features.se02Version),
42056
- se03: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_version, features === null || features === void 0 ? void 0 : features.se03Version),
42057
- se04: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_version, features === null || features === void 0 ? void 0 : features.se04Version),
42058
- se01Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se01_boot_version, features === null || features === void 0 ? void 0 : features.se01BootVersion),
42059
- se02Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se02_boot_version, features === null || features === void 0 ? void 0 : features.se02BootVersion),
42060
- se03Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se03_boot_version, features === null || features === void 0 ? void 0 : features.se03BootVersion),
42061
- se04Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_boot_version, features === null || features === void 0 ? void 0 : features.se04BootVersion),
42062
- });
42063
- const normalizeV2Versions = (deviceInfo) => {
42064
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
42065
- const info = deviceInfo;
42066
- return {
42067
- firmware: firstMeaningfulVersion$1(getImageVersion$1((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application)),
42068
- bootloader: firstMeaningfulVersion$1(getImageVersion$1((_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.bootloader)),
42069
- board: firstMeaningfulVersion$1(getImageVersion$1((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.romloader)),
42070
- ble: firstMeaningfulVersion$1(getImageVersion$1((_d = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _d === void 0 ? void 0 : _d.application)),
42071
- se01: firstMeaningfulVersion$1(getImageVersion$1((_e = info === null || info === void 0 ? void 0 : info.se1) === null || _e === void 0 ? void 0 : _e.application)),
42072
- se02: firstMeaningfulVersion$1(getImageVersion$1((_f = info === null || info === void 0 ? void 0 : info.se2) === null || _f === void 0 ? void 0 : _f.application)),
42073
- se03: firstMeaningfulVersion$1(getImageVersion$1((_g = info === null || info === void 0 ? void 0 : info.se3) === null || _g === void 0 ? void 0 : _g.application)),
42074
- se04: firstMeaningfulVersion$1(getImageVersion$1((_h = info === null || info === void 0 ? void 0 : info.se4) === null || _h === void 0 ? void 0 : _h.application)),
42075
- se01Boot: firstMeaningfulVersion$1(getImageVersion$1((_j = info === null || info === void 0 ? void 0 : info.se1) === null || _j === void 0 ? void 0 : _j.bootloader)),
42076
- se02Boot: firstMeaningfulVersion$1(getImageVersion$1((_k = info === null || info === void 0 ? void 0 : info.se2) === null || _k === void 0 ? void 0 : _k.bootloader)),
42077
- se03Boot: firstMeaningfulVersion$1(getImageVersion$1((_l = info === null || info === void 0 ? void 0 : info.se3) === null || _l === void 0 ? void 0 : _l.bootloader)),
42078
- se04Boot: firstMeaningfulVersion$1(getImageVersion$1((_m = info === null || info === void 0 ? void 0 : info.se4) === null || _m === void 0 ? void 0 : _m.bootloader)),
42079
- };
42080
- };
42081
- const normalizeV1Status = (features) => {
42082
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
42083
- return ({
42084
- mode: getDeviceMode(features),
42085
- initialized: (_a = features === null || features === void 0 ? void 0 : features.initialized) !== null && _a !== void 0 ? _a : null,
42086
- bootloaderMode: (_b = features === null || features === void 0 ? void 0 : features.bootloaderMode) !== null && _b !== void 0 ? _b : null,
42087
- unlocked: (_c = features === null || features === void 0 ? void 0 : features.unlocked) !== null && _c !== void 0 ? _c : null,
42088
- passphraseProtection: (_d = features === null || features === void 0 ? void 0 : features.passphraseProtection) !== null && _d !== void 0 ? _d : null,
42089
- attachToPinEnabled: (_e = features === null || features === void 0 ? void 0 : features.attachToPinEnabled) !== null && _e !== void 0 ? _e : null,
42090
- unlockedAttachPin: (_f = features === null || features === void 0 ? void 0 : features.unlockedAttachPin) !== null && _f !== void 0 ? _f : null,
42091
- backupRequired: (_g = features === null || features === void 0 ? void 0 : features.backupRequired) !== null && _g !== void 0 ? _g : null,
42092
- noBackup: (_h = features === null || features === void 0 ? void 0 : features.noBackup) !== null && _h !== void 0 ? _h : null,
42093
- language: (_j = features === null || features === void 0 ? void 0 : features.language) !== null && _j !== void 0 ? _j : null,
42094
- bleEnabled: (_k = features === null || features === void 0 ? void 0 : features.bleEnabled) !== null && _k !== void 0 ? _k : null,
42095
- });
42096
- };
42097
- const normalizeV2Status = (deviceInfo, deviceStatus) => {
42098
- var _a, _b, _c, _d, _e, _f;
42099
- const status = deviceStatus;
42100
- const bootloaderMode = isProtocolV2BootloaderDeviceInfo(deviceInfo, deviceStatus);
42101
- return {
42102
- mode: getProtocolV2Mode(deviceInfo, deviceStatus),
42103
- initialized: (_a = status === null || status === void 0 ? void 0 : status.init_states) !== null && _a !== void 0 ? _a : null,
42104
- bootloaderMode,
42105
- unlocked: (_b = status === null || status === void 0 ? void 0 : status.unlocked) !== null && _b !== void 0 ? _b : null,
42106
- passphraseProtection: (_c = status === null || status === void 0 ? void 0 : status.passphrase_enabled) !== null && _c !== void 0 ? _c : null,
42107
- attachToPinEnabled: (_d = status === null || status === void 0 ? void 0 : status.attach_to_pin_enabled) !== null && _d !== void 0 ? _d : null,
42108
- unlockedAttachPin: (_e = status === null || status === void 0 ? void 0 : status.unlocked_by_attach_to_pin) !== null && _e !== void 0 ? _e : null,
42109
- backupRequired: (_f = status === null || status === void 0 ? void 0 : status.backup_required) !== null && _f !== void 0 ? _f : null,
42110
- noBackup: null,
42111
- language: null,
42112
- bleEnabled: null,
42113
- };
42114
- };
42115
- const normalizeV1Verify = (features, protocolV1OneKeyFeatures) => {
42116
- 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;
42117
- return ({
42118
- 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,
42119
- 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,
42120
- 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,
42121
- 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,
42122
- 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,
42123
- 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,
42124
- 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,
42125
- 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,
42126
- 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,
42127
- 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,
42128
- 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,
42129
- 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,
42130
- 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,
42131
- 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,
42132
- 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,
42133
- 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,
42134
- 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,
42135
- 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,
42136
- 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,
42137
- 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,
42138
- 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,
42139
- 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,
42140
- 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,
42141
- 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,
42142
- });
42143
- };
42144
- const normalizeV2Verify = (deviceInfo) => {
42145
- 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;
42146
- const info = deviceInfo;
42147
- return {
42148
- firmwareBuildId: getImageBuildId$1((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application),
42149
- firmwareHash: getImageHash$1((_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.application),
42150
- bootloaderBuildId: getImageBuildId$1((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.bootloader),
42151
- bootloaderHash: getImageHash$1((_d = info === null || info === void 0 ? void 0 : info.fw) === null || _d === void 0 ? void 0 : _d.bootloader),
42152
- boardBuildId: getImageBuildId$1((_e = info === null || info === void 0 ? void 0 : info.fw) === null || _e === void 0 ? void 0 : _e.romloader),
42153
- boardHash: getImageHash$1((_f = info === null || info === void 0 ? void 0 : info.fw) === null || _f === void 0 ? void 0 : _f.romloader),
42154
- bleBuildId: getImageBuildId$1((_g = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _g === void 0 ? void 0 : _g.application),
42155
- bleHash: getImageHash$1((_h = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _h === void 0 ? void 0 : _h.application),
42156
- se01BuildId: getImageBuildId$1((_j = info === null || info === void 0 ? void 0 : info.se1) === null || _j === void 0 ? void 0 : _j.application),
42157
- se01Hash: getImageHash$1((_k = info === null || info === void 0 ? void 0 : info.se1) === null || _k === void 0 ? void 0 : _k.application),
42158
- se02BuildId: getImageBuildId$1((_l = info === null || info === void 0 ? void 0 : info.se2) === null || _l === void 0 ? void 0 : _l.application),
42159
- se02Hash: getImageHash$1((_m = info === null || info === void 0 ? void 0 : info.se2) === null || _m === void 0 ? void 0 : _m.application),
42160
- se03BuildId: getImageBuildId$1((_o = info === null || info === void 0 ? void 0 : info.se3) === null || _o === void 0 ? void 0 : _o.application),
42161
- se03Hash: getImageHash$1((_p = info === null || info === void 0 ? void 0 : info.se3) === null || _p === void 0 ? void 0 : _p.application),
42162
- se04BuildId: getImageBuildId$1((_q = info === null || info === void 0 ? void 0 : info.se4) === null || _q === void 0 ? void 0 : _q.application),
42163
- se04Hash: getImageHash$1((_r = info === null || info === void 0 ? void 0 : info.se4) === null || _r === void 0 ? void 0 : _r.application),
42164
- se01BootBuildId: getImageBuildId$1((_s = info === null || info === void 0 ? void 0 : info.se1) === null || _s === void 0 ? void 0 : _s.bootloader),
42165
- se01BootHash: getImageHash$1((_t = info === null || info === void 0 ? void 0 : info.se1) === null || _t === void 0 ? void 0 : _t.bootloader),
42166
- se02BootBuildId: getImageBuildId$1((_u = info === null || info === void 0 ? void 0 : info.se2) === null || _u === void 0 ? void 0 : _u.bootloader),
42167
- se02BootHash: getImageHash$1((_v = info === null || info === void 0 ? void 0 : info.se2) === null || _v === void 0 ? void 0 : _v.bootloader),
42168
- se03BootBuildId: getImageBuildId$1((_w = info === null || info === void 0 ? void 0 : info.se3) === null || _w === void 0 ? void 0 : _w.bootloader),
42169
- se03BootHash: getImageHash$1((_x = info === null || info === void 0 ? void 0 : info.se3) === null || _x === void 0 ? void 0 : _x.bootloader),
42170
- se04BootBuildId: getImageBuildId$1((_y = info === null || info === void 0 ? void 0 : info.se4) === null || _y === void 0 ? void 0 : _y.bootloader),
42171
- se04BootHash: getImageHash$1((_z = info === null || info === void 0 ? void 0 : info.se4) === null || _z === void 0 ? void 0 : _z.bootloader),
42172
- };
42173
- };
42174
- const normalizeRaw = ({ features, protocolV1OneKeyFeatures, protocolV2DeviceInfo, protocolV2DeviceStatus, }) => (Object.assign(Object.assign(Object.assign(Object.assign({}, (features ? { features } : {})), (protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {})), (protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {})), (protocolV2DeviceStatus ? { protocolV2DeviceStatus } : {})));
42175
- function buildProfileFromProtocolV1({ protocol = 'V1', features, protocolV1OneKeyFeatures, sources = ['features'], scope = 'basic', includeRaw = false, }) {
42176
- const sourceFeatures = features;
42177
- const verify = normalizeV1Verify(sourceFeatures, protocolV1OneKeyFeatures);
42178
- return Object.assign(Object.assign({ protocol,
42179
- 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
42180
- ? {
42181
- raw: normalizeRaw({
42182
- features,
42183
- protocolV1OneKeyFeatures,
42184
- }),
42185
- }
42186
- : {}));
42187
- }
42188
- function buildProfileFromProtocolV2({ deviceInfo, deviceStatus, sources = ['deviceInfo'], scope = 'basic', includeRaw = false, }) {
42189
- var _a, _b, _c;
42190
- const info = deviceInfo;
42191
- const deviceId = (deviceStatus === null || deviceStatus === void 0 ? void 0 : deviceStatus.device_id) || '';
42192
- const serialNo = ((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.hw) === null || _a === void 0 ? void 0 : _a.serial_no) || '';
42193
- const label = null;
42194
- const bleName = (_c = (_b = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _b === void 0 ? void 0 : _b.bt_adv_name) !== null && _c !== void 0 ? _c : null;
42195
- const verify = normalizeV2Verify(deviceInfo);
42196
- return Object.assign(Object.assign({ protocol: 'V2', sources, deviceType: hdShared.EDeviceType.Pro2, firmwareType: hdShared.EFirmwareType.Universal, deviceId,
42197
- serialNo,
42198
- label,
42199
- bleName, status: normalizeV2Status(deviceInfo, deviceStatus), versions: normalizeV2Versions(deviceInfo) }, (shouldIncludeVerify(scope) ? { verify } : {})), (includeRaw
42200
- ? {
42201
- raw: normalizeRaw({
42202
- protocolV2DeviceInfo: deviceInfo,
42203
- protocolV2DeviceStatus: deviceStatus,
42204
- }),
42205
- }
42206
- : {}));
42207
- }
42208
-
42209
- const getImageVersion = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : null; };
42210
- const bytesToHex$2 = (value) => {
42211
- if (!value)
42212
- return undefined;
42213
- if (typeof value === 'string')
42214
- return value;
42215
- if (value instanceof Uint8Array) {
42216
- return Array.from(value)
42217
- .map(byte => byte.toString(16).padStart(2, '0'))
42218
- .join('');
42219
- }
42220
- if (Array.isArray(value)) {
42221
- return value.map(byte => Number(byte).toString(16).padStart(2, '0')).join('');
42222
- }
42223
- return undefined;
42224
- };
42225
- const getImageBuildId = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
42226
- const getImageHash = (image) => bytesToHex$2(image === null || image === void 0 ? void 0 : image.hash);
42227
- const firstValue = (...values) => values.find(value => value !== undefined && value !== null);
42228
42004
  const firstMeaningfulVersion = (...versions) => { var _a; return (_a = versions.find(version => Boolean(version && version !== '0.0.0'))) !== null && _a !== void 0 ? _a : null; };
42229
42005
  const versionFromParts = (major, minor, patch) => [major, minor, patch].map(part => Number(part) || 0).join('.');
42230
42006
  const getProtocolV1Mode = (features) => {
@@ -42232,9 +42008,9 @@ const getProtocolV1Mode = (features) => {
42232
42008
  return 'bootloader';
42233
42009
  if (features.initialized === false)
42234
42010
  return 'notInitialized';
42235
- if (features.initialized === true)
42236
- return 'normal';
42237
- return 'unknown';
42011
+ if (features.no_backup === true)
42012
+ return 'backupMode';
42013
+ return 'normal';
42238
42014
  };
42239
42015
  const getProtocolV1DeviceType = (features) => {
42240
42016
  const onekeyDeviceType = features.onekey_device_type;
@@ -42277,208 +42053,682 @@ const getProtocolV1DeviceType = (features) => {
42277
42053
  const getProtocolV1FirmwareType = (features) => {
42278
42054
  if (features.fw_vendor === 'OneKey Bitcoin-only')
42279
42055
  return hdShared.EFirmwareType.BitcoinOnly;
42056
+ const capabilities = features.capabilities;
42057
+ if ((capabilities === null || capabilities === void 0 ? void 0 : capabilities.length) &&
42058
+ !capabilities.includes(hdTransport.Enum_Capability.Capability_Bitcoin_like) &&
42059
+ !capabilities.includes('Capability_Bitcoin_like')) {
42060
+ return hdShared.EFirmwareType.BitcoinOnly;
42061
+ }
42280
42062
  return hdShared.EFirmwareType.Universal;
42281
42063
  };
42282
- const getProtocolV1Label = (features, deviceType, bleName) => {
42283
- if (features.label)
42284
- return features.label;
42285
- if (bleName)
42286
- return bleName;
42287
- if (deviceType === hdShared.EDeviceType.Unknown)
42288
- return null;
42289
- if (deviceType === hdShared.EDeviceType.ClassicPure)
42290
- return 'OneKey Classic 1S';
42291
- return `OneKey ${deviceType.charAt(0).toUpperCase()}${deviceType.slice(1)}`;
42292
- };
42064
+ const getProtocolV1Label = (features) => typeof features.label === 'string' && features.label.length > 0 ? features.label : null;
42293
42065
  const buildProtocolV1FeaturesPayload = (protocolV1Features, previous) => {
42294
- 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;
42066
+ 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;
42295
42067
  const features = protocolV1Features;
42296
- const firmwareVersion = firstMeaningfulVersion(features.onekey_firmware_version, features.onekey_version, versionFromParts(features.major_version, features.minor_version, features.patch_version));
42068
+ const firmwareVersion = firstMeaningfulVersion(features.onekey_firmware_version, features.onekey_version, versionFromParts(features.major_version, features.minor_version, features.patch_version), previous === null || previous === void 0 ? void 0 : previous.firmwareVersion);
42297
42069
  const bootloaderVersion = firstMeaningfulVersion(features.onekey_boot_version, features.bootloader_version, features.bootloader_mode
42298
42070
  ? versionFromParts(features.major_version, features.minor_version, features.patch_version)
42299
- : null);
42300
- const boardVersion = firstMeaningfulVersion(features.onekey_board_version, features.boardloader_version);
42301
- const bleVersion = firstMeaningfulVersion(features.onekey_ble_version, features.ble_ver);
42071
+ : null, previous === null || previous === void 0 ? void 0 : previous.bootloaderVersion);
42072
+ const boardVersion = firstMeaningfulVersion(features.onekey_board_version, features.boardloader_version, previous === null || previous === void 0 ? void 0 : previous.boardVersion);
42073
+ const bleVersion = firstMeaningfulVersion(features.onekey_ble_version, features.ble_ver, previous === null || previous === void 0 ? void 0 : previous.bleVersion);
42302
42074
  const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
42303
42075
  const bleName = features.onekey_ble_name || features.ble_name || null;
42304
42076
  const deviceType = getProtocolV1DeviceType(features);
42305
42077
  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;
42306
- return Object.assign(Object.assign({}, features), { protocol: 'V1', 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, deviceType, firmwareType: getProtocolV1FirmwareType(features), model: (_e = features.model) !== null && _e !== void 0 ? _e : null, vendor: (_f = features.vendor) !== null && _f !== void 0 ? _f : null, deviceId: (_g = features.device_id) !== null && _g !== void 0 ? _g : null, serialNo, label: getProtocolV1Label(features, deviceType, bleName), bleName, capabilities: (_h = features.capabilities) !== null && _h !== void 0 ? _h : [], mode: getProtocolV1Mode(features), initialized: (_j = features.initialized) !== null && _j !== void 0 ? _j : null, bootloaderMode: (_k = features.bootloader_mode) !== null && _k !== void 0 ? _k : null, unlocked: (_l = features.unlocked) !== null && _l !== void 0 ? _l : true, firmwarePresent: (_m = features.firmware_present) !== null && _m !== void 0 ? _m : null, passphraseProtection: (_o = features.passphrase_protection) !== null && _o !== void 0 ? _o : null, pinProtection: (_p = features.pin_protection) !== null && _p !== void 0 ? _p : null, backupRequired: (_q = features.needs_backup) !== null && _q !== void 0 ? _q : null, noBackup: (_r = features.no_backup) !== null && _r !== void 0 ? _r : null, unfinishedBackup: (_s = features.unfinished_backup) !== null && _s !== void 0 ? _s : null, recoveryMode: (_t = features.recovery_mode) !== null && _t !== void 0 ? _t : null, language: (_u = features.language) !== null && _u !== void 0 ? _u : null, bleEnabled: (_v = features.ble_enable) !== null && _v !== void 0 ? _v : null, sdCardPresent: (_w = features.sd_card_present) !== null && _w !== void 0 ? _w : null, sdProtection: (_x = features.sd_protection) !== null && _x !== void 0 ? _x : null, wipeCodeProtection: (_y = features.wipe_code_protection) !== null && _y !== void 0 ? _y : null, passphraseAlwaysOnDevice: (_z = features.passphrase_always_on_device) !== null && _z !== void 0 ? _z : null, safetyChecks: (_0 = features.safety_checks) !== null && _0 !== void 0 ? _0 : null, autoLockDelayMs: (_1 = features.auto_lock_delay_ms) !== null && _1 !== void 0 ? _1 : null, displayRotation: (_2 = features.display_rotation) !== null && _2 !== void 0 ? _2 : null, experimentalFeatures: (_3 = features.experimental_features) !== null && _3 !== void 0 ? _3 : null, firmwareVersion,
42078
+ return Object.assign(Object.assign({}, features), { protocol: 'V1', 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, deviceType, firmwareType: getProtocolV1FirmwareType(features), model: (_e = features.model) !== null && _e !== void 0 ? _e : null, vendor: (_f = features.vendor) !== null && _f !== void 0 ? _f : null, deviceId: (_g = features.device_id) !== null && _g !== void 0 ? _g : null, serialNo, label: getProtocolV1Label(features), bleName, capabilities: (_h = features.capabilities) !== null && _h !== void 0 ? _h : [], mode: getProtocolV1Mode(features), initialized: (_j = features.initialized) !== null && _j !== void 0 ? _j : null, bootloaderMode: (_k = features.bootloader_mode) !== null && _k !== void 0 ? _k : null, unlocked: (_l = features.unlocked) !== null && _l !== void 0 ? _l : true, firmwarePresent: (_m = features.firmware_present) !== null && _m !== void 0 ? _m : null, passphraseProtection: (_o = features.passphrase_protection) !== null && _o !== void 0 ? _o : null, pinProtection: (_p = features.pin_protection) !== null && _p !== void 0 ? _p : null, backupRequired: (_q = features.needs_backup) !== null && _q !== void 0 ? _q : null, noBackup: (_r = features.no_backup) !== null && _r !== void 0 ? _r : null, unfinishedBackup: (_s = features.unfinished_backup) !== null && _s !== void 0 ? _s : null, recoveryMode: (_t = features.recovery_mode) !== null && _t !== void 0 ? _t : null, language: (_u = features.language) !== null && _u !== void 0 ? _u : null, bleEnabled: (_v = features.ble_enable) !== null && _v !== void 0 ? _v : null, sdCardPresent: (_w = features.sd_card_present) !== null && _w !== void 0 ? _w : null, sdProtection: (_x = features.sd_protection) !== null && _x !== void 0 ? _x : null, wipeCodeProtection: (_y = features.wipe_code_protection) !== null && _y !== void 0 ? _y : null, passphraseAlwaysOnDevice: (_z = features.passphrase_always_on_device) !== null && _z !== void 0 ? _z : null, attachToPinEnabled: (_1 = (_0 = features.attach_to_pin_user) !== null && _0 !== void 0 ? _0 : previous === null || previous === void 0 ? void 0 : previous.attachToPinEnabled) !== null && _1 !== void 0 ? _1 : null, unlockedAttachPin: (_3 = (_2 = features.unlocked_attach_pin) !== null && _2 !== void 0 ? _2 : previous === null || previous === void 0 ? void 0 : previous.unlockedAttachPin) !== null && _3 !== void 0 ? _3 : undefined, safetyChecks: (_4 = features.safety_checks) !== null && _4 !== void 0 ? _4 : null, autoLockDelayMs: (_5 = features.auto_lock_delay_ms) !== null && _5 !== void 0 ? _5 : null, autoShutdownDelayMs: (_6 = features.auto_shutdown_delay_ms) !== null && _6 !== void 0 ? _6 : null, displayRotation: (_7 = features.display_rotation) !== null && _7 !== void 0 ? _7 : null, experimentalFeatures: (_8 = features.experimental_features) !== null && _8 !== void 0 ? _8 : null, wallpaperPath: (_9 = previous === null || previous === void 0 ? void 0 : previous.wallpaperPath) !== null && _9 !== void 0 ? _9 : null, brightness: (_11 = (_10 = features.brightness_prcent) !== null && _10 !== void 0 ? _10 : previous === null || previous === void 0 ? void 0 : previous.brightness) !== null && _11 !== void 0 ? _11 : null, animationEnabled: (_12 = previous === null || previous === void 0 ? void 0 : previous.animationEnabled) !== null && _12 !== void 0 ? _12 : null, tapToWake: (_13 = previous === null || previous === void 0 ? void 0 : previous.tapToWake) !== null && _13 !== void 0 ? _13 : null, hapticFeedback: (_15 = (_14 = features.haptic_feedback) !== null && _14 !== void 0 ? _14 : previous === null || previous === void 0 ? void 0 : previous.hapticFeedback) !== null && _15 !== void 0 ? _15 : null, deviceNameDisplayEnabled: (_16 = previous === null || previous === void 0 ? void 0 : previous.deviceNameDisplayEnabled) !== null && _16 !== void 0 ? _16 : null, airgapMode: (_17 = previous === null || previous === void 0 ? void 0 : previous.airgapMode) !== null && _17 !== void 0 ? _17 : null, fidoEnabled: (_18 = previous === null || previous === void 0 ? void 0 : previous.fidoEnabled) !== null && _18 !== void 0 ? _18 : null, usbLockEnabled: (_19 = previous === null || previous === void 0 ? void 0 : previous.usbLockEnabled) !== null && _19 !== void 0 ? _19 : null, randomKeypad: (_20 = previous === null || previous === void 0 ? void 0 : previous.randomKeypad) !== null && _20 !== void 0 ? _20 : null, firmwareVersion,
42307
42079
  bootloaderVersion,
42308
42080
  boardVersion,
42309
- bleVersion, se01Version: firstMeaningfulVersion(features.onekey_se01_version), se02Version: firstMeaningfulVersion(features.onekey_se02_version), se03Version: firstMeaningfulVersion(features.onekey_se03_version), se04Version: firstMeaningfulVersion(features.onekey_se04_version), se01BootVersion: firstMeaningfulVersion(features.onekey_se01_boot_version), se02BootVersion: firstMeaningfulVersion(features.onekey_se02_boot_version), se03BootVersion: firstMeaningfulVersion(features.onekey_se03_boot_version), se04BootVersion: firstMeaningfulVersion(features.onekey_se04_boot_version), seVersion: (_4 = features.se_ver) !== null && _4 !== void 0 ? _4 : null, verify: {
42310
- firmwareBuildId: features.onekey_firmware_build_id,
42311
- firmwareHash: features.onekey_firmware_hash,
42312
- bootloaderBuildId: features.onekey_boot_build_id,
42313
- bootloaderHash: features.onekey_boot_hash,
42314
- boardBuildId: features.onekey_board_build_id,
42315
- boardHash: features.onekey_board_hash,
42316
- bleBuildId: features.onekey_ble_build_id,
42317
- bleHash: features.onekey_ble_hash,
42318
- se01BuildId: features.onekey_se01_build_id,
42319
- se01Hash: features.onekey_se01_hash,
42320
- se02BuildId: features.onekey_se02_build_id,
42321
- se02Hash: features.onekey_se02_hash,
42322
- se03BuildId: features.onekey_se03_build_id,
42323
- se03Hash: features.onekey_se03_hash,
42324
- se04BuildId: features.onekey_se04_build_id,
42325
- se04Hash: features.onekey_se04_hash,
42326
- se01BootBuildId: features.onekey_se01_boot_build_id,
42327
- se01BootHash: features.onekey_se01_boot_hash,
42328
- se02BootBuildId: features.onekey_se02_boot_build_id,
42329
- se02BootHash: features.onekey_se02_boot_hash,
42330
- se03BootBuildId: features.onekey_se03_boot_build_id,
42331
- se03BootHash: features.onekey_se03_boot_hash,
42332
- se04BootBuildId: features.onekey_se04_boot_build_id,
42333
- se04BootHash: features.onekey_se04_boot_hash,
42081
+ bleVersion, se01Version: firstMeaningfulVersion(features.onekey_se01_version, previous === null || previous === void 0 ? void 0 : previous.se01Version), se02Version: firstMeaningfulVersion(features.onekey_se02_version, previous === null || previous === void 0 ? void 0 : previous.se02Version), se03Version: firstMeaningfulVersion(features.onekey_se03_version, previous === null || previous === void 0 ? void 0 : previous.se03Version), se04Version: firstMeaningfulVersion(features.onekey_se04_version, previous === null || previous === void 0 ? void 0 : previous.se04Version), se01BootVersion: firstMeaningfulVersion(features.onekey_se01_boot_version, previous === null || previous === void 0 ? void 0 : previous.se01BootVersion), se02BootVersion: firstMeaningfulVersion(features.onekey_se02_boot_version, previous === null || previous === void 0 ? void 0 : previous.se02BootVersion), se03BootVersion: firstMeaningfulVersion(features.onekey_se03_boot_version, previous === null || previous === void 0 ? void 0 : previous.se03BootVersion), se04BootVersion: firstMeaningfulVersion(features.onekey_se04_boot_version, previous === null || previous === void 0 ? void 0 : previous.se04BootVersion), seVersion: (_22 = (_21 = features.se_ver) !== null && _21 !== void 0 ? _21 : previous === null || previous === void 0 ? void 0 : previous.seVersion) !== null && _22 !== void 0 ? _22 : null, verify: {
42082
+ firmwareBuildId: (_23 = features.onekey_firmware_build_id) !== null && _23 !== void 0 ? _23 : (_24 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _24 === void 0 ? void 0 : _24.firmwareBuildId,
42083
+ firmwareHash: (_25 = features.onekey_firmware_hash) !== null && _25 !== void 0 ? _25 : (_26 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _26 === void 0 ? void 0 : _26.firmwareHash,
42084
+ bootloaderBuildId: (_27 = features.onekey_boot_build_id) !== null && _27 !== void 0 ? _27 : (_28 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _28 === void 0 ? void 0 : _28.bootloaderBuildId,
42085
+ bootloaderHash: (_29 = features.onekey_boot_hash) !== null && _29 !== void 0 ? _29 : (_30 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _30 === void 0 ? void 0 : _30.bootloaderHash,
42086
+ boardBuildId: (_31 = features.onekey_board_build_id) !== null && _31 !== void 0 ? _31 : (_32 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _32 === void 0 ? void 0 : _32.boardBuildId,
42087
+ boardHash: (_33 = features.onekey_board_hash) !== null && _33 !== void 0 ? _33 : (_34 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _34 === void 0 ? void 0 : _34.boardHash,
42088
+ bleBuildId: (_35 = features.onekey_ble_build_id) !== null && _35 !== void 0 ? _35 : (_36 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _36 === void 0 ? void 0 : _36.bleBuildId,
42089
+ bleHash: (_37 = features.onekey_ble_hash) !== null && _37 !== void 0 ? _37 : (_38 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _38 === void 0 ? void 0 : _38.bleHash,
42090
+ se01BuildId: (_39 = features.onekey_se01_build_id) !== null && _39 !== void 0 ? _39 : (_40 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _40 === void 0 ? void 0 : _40.se01BuildId,
42091
+ se01Hash: (_41 = features.onekey_se01_hash) !== null && _41 !== void 0 ? _41 : (_42 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _42 === void 0 ? void 0 : _42.se01Hash,
42092
+ se02BuildId: (_43 = features.onekey_se02_build_id) !== null && _43 !== void 0 ? _43 : (_44 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _44 === void 0 ? void 0 : _44.se02BuildId,
42093
+ se02Hash: (_45 = features.onekey_se02_hash) !== null && _45 !== void 0 ? _45 : (_46 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _46 === void 0 ? void 0 : _46.se02Hash,
42094
+ se03BuildId: (_47 = features.onekey_se03_build_id) !== null && _47 !== void 0 ? _47 : (_48 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _48 === void 0 ? void 0 : _48.se03BuildId,
42095
+ se03Hash: (_49 = features.onekey_se03_hash) !== null && _49 !== void 0 ? _49 : (_50 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _50 === void 0 ? void 0 : _50.se03Hash,
42096
+ se04BuildId: (_51 = features.onekey_se04_build_id) !== null && _51 !== void 0 ? _51 : (_52 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _52 === void 0 ? void 0 : _52.se04BuildId,
42097
+ se04Hash: (_53 = features.onekey_se04_hash) !== null && _53 !== void 0 ? _53 : (_54 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _54 === void 0 ? void 0 : _54.se04Hash,
42098
+ se01BootBuildId: (_55 = features.onekey_se01_boot_build_id) !== null && _55 !== void 0 ? _55 : (_56 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _56 === void 0 ? void 0 : _56.se01BootBuildId,
42099
+ se01BootHash: (_57 = features.onekey_se01_boot_hash) !== null && _57 !== void 0 ? _57 : (_58 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _58 === void 0 ? void 0 : _58.se01BootHash,
42100
+ se02BootBuildId: (_59 = features.onekey_se02_boot_build_id) !== null && _59 !== void 0 ? _59 : (_60 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _60 === void 0 ? void 0 : _60.se02BootBuildId,
42101
+ se02BootHash: (_61 = features.onekey_se02_boot_hash) !== null && _61 !== void 0 ? _61 : (_62 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _62 === void 0 ? void 0 : _62.se02BootHash,
42102
+ se03BootBuildId: (_63 = features.onekey_se03_boot_build_id) !== null && _63 !== void 0 ? _63 : (_64 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _64 === void 0 ? void 0 : _64.se03BootBuildId,
42103
+ se03BootHash: (_65 = features.onekey_se03_boot_hash) !== null && _65 !== void 0 ? _65 : (_66 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _66 === void 0 ? void 0 : _66.se03BootHash,
42104
+ se04BootBuildId: (_67 = features.onekey_se04_boot_build_id) !== null && _67 !== void 0 ? _67 : (_68 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _68 === void 0 ? void 0 : _68.se04BootBuildId,
42105
+ se04BootHash: (_69 = features.onekey_se04_boot_hash) !== null && _69 !== void 0 ? _69 : (_70 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _70 === void 0 ? void 0 : _70.se04BootHash,
42334
42106
  }, sessionId, session_id: sessionId !== null && sessionId !== void 0 ? sessionId : undefined, raw: {
42335
42107
  protocolV1Features,
42336
42108
  } });
42337
42109
  };
42338
- const buildProtocolV2FeaturesPayload = ({ deviceInfo, deviceStatus, previous, }) => {
42339
- 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;
42340
- const info = deviceInfo;
42341
- const fwApplication = (_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application;
42342
- const fwBootloader = (_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.bootloader;
42343
- const fwBoard = (_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.romloader;
42344
- const bleApplication = (_d = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _d === void 0 ? void 0 : _d.application;
42345
- const status = deviceStatus;
42346
- const firmwareVersion = firstMeaningfulVersion(getImageVersion(fwApplication), previous === null || previous === void 0 ? void 0 : previous.firmwareVersion);
42347
- const bootloaderVersion = firstMeaningfulVersion(getImageVersion(fwBootloader), previous === null || previous === void 0 ? void 0 : previous.bootloaderVersion);
42348
- const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), previous === null || previous === void 0 ? void 0 : previous.boardVersion);
42349
- const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication), previous === null || previous === void 0 ? void 0 : previous.bleVersion);
42350
- const deviceId = (_e = status === null || status === void 0 ? void 0 : status.device_id) !== null && _e !== void 0 ? _e : null;
42351
- const serialNo = (_g = firstValue((_f = info === null || info === void 0 ? void 0 : info.hw) === null || _f === void 0 ? void 0 : _f.serial_no, previous === null || previous === void 0 ? void 0 : previous.serialNo)) !== null && _g !== void 0 ? _g : '';
42352
- const label = (_h = previous === null || previous === void 0 ? void 0 : previous.label) !== null && _h !== void 0 ? _h : null;
42353
- const bleName = firstValue((_j = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _j === void 0 ? void 0 : _j.bt_adv_name, previous === null || previous === void 0 ? void 0 : previous.bleName);
42354
- const initialized = (_k = firstValue(status === null || status === void 0 ? void 0 : status.init_states, previous === null || previous === void 0 ? void 0 : previous.initialized)) !== null && _k !== void 0 ? _k : null;
42355
- const passphraseProtection = (status === null || status === void 0 ? void 0 : status.unlocked) === true ? (_l = status.passphrase_enabled) !== null && _l !== void 0 ? _l : null : null;
42356
- const language = (_m = previous === null || previous === void 0 ? void 0 : previous.language) !== null && _m !== void 0 ? _m : null;
42357
- const backupRequired = (_o = firstValue(status === null || status === void 0 ? void 0 : status.backup_required, previous === null || previous === void 0 ? void 0 : previous.backupRequired)) !== null && _o !== void 0 ? _o : null;
42358
- const bleEnabled = previous === null || previous === void 0 ? void 0 : previous.bleEnabled;
42359
- const unlocked = (_p = firstValue(status === null || status === void 0 ? void 0 : status.unlocked, previous === null || previous === void 0 ? void 0 : previous.unlocked)) !== null && _p !== void 0 ? _p : null;
42360
- const attachToPinEnabled = (_q = status === null || status === void 0 ? void 0 : status.attach_to_pin_enabled) !== null && _q !== void 0 ? _q : null;
42361
- const unlockedAttachPin = (_r = status === null || status === void 0 ? void 0 : status.unlocked_by_attach_to_pin) !== null && _r !== void 0 ? _r : undefined;
42362
- const romloaderMode = isProtocolV2RomloaderDeviceInfo(info, status);
42363
- const bootloaderMode = isProtocolV2BootloaderDeviceInfo(info, status);
42364
- let mode = 'unknown';
42365
- if (romloaderMode) {
42110
+
42111
+ const definedEntries = (value) => Object.fromEntries(Object.entries(value).filter(([, fieldValue]) => fieldValue !== undefined));
42112
+ const imageVersion = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : undefined; };
42113
+ const bytesToHex$2 = (value) => {
42114
+ if (!value)
42115
+ return undefined;
42116
+ if (typeof value === 'string')
42117
+ return value;
42118
+ if (value instanceof Uint8Array || Array.isArray(value)) {
42119
+ return Array.from(value)
42120
+ .map(byte => Number(byte).toString(16).padStart(2, '0'))
42121
+ .join('');
42122
+ }
42123
+ return undefined;
42124
+ };
42125
+ const imageBuildId = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
42126
+ const imageHash = (image) => bytesToHex$2(image === null || image === void 0 ? void 0 : image.hash);
42127
+ const getFeaturesMode = (features) => {
42128
+ if (features.mode !== undefined && features.mode !== null)
42129
+ return features.mode;
42130
+ if (features.bootloaderMode === true)
42131
+ return 'bootloader';
42132
+ if (features.initialized === false)
42133
+ return 'notInitialized';
42134
+ if (features.initialized === true)
42135
+ return 'normal';
42136
+ return undefined;
42137
+ };
42138
+ const getProtocolV2StatusMode = (initialized) => {
42139
+ if (initialized === false)
42140
+ return 'notInitialized';
42141
+ if (initialized === true)
42142
+ return 'normal';
42143
+ return undefined;
42144
+ };
42145
+ const mapFeaturesToState = (features) => {
42146
+ var _a, _b, _c;
42147
+ return ({
42148
+ protocol: features.protocol,
42149
+ protocolVersion: features.protocolVersion,
42150
+ identity: {
42151
+ deviceType: features.deviceType,
42152
+ firmwareType: features.firmwareType,
42153
+ model: features.model,
42154
+ vendor: features.vendor,
42155
+ deviceId: features.deviceId,
42156
+ serialNo: features.serialNo,
42157
+ label: features.label,
42158
+ bleName: features.bleName,
42159
+ },
42160
+ status: {
42161
+ mode: getFeaturesMode(features),
42162
+ initialized: features.initialized,
42163
+ unlocked: features.unlocked,
42164
+ firmwarePresent: features.firmwarePresent,
42165
+ backupRequired: features.backupRequired,
42166
+ noBackup: features.noBackup,
42167
+ unfinishedBackup: features.unfinishedBackup,
42168
+ recoveryMode: features.recoveryMode,
42169
+ passphraseProtection: features.passphraseProtection,
42170
+ pinProtection: features.pinProtection,
42171
+ attachToPinEnabled: (_a = features.attachToPinEnabled) !== null && _a !== void 0 ? _a : null,
42172
+ unlockedAttachPin: (_b = features.unlockedAttachPin) !== null && _b !== void 0 ? _b : null,
42173
+ },
42174
+ settings: {
42175
+ language: features.language,
42176
+ bleEnabled: features.bleEnabled,
42177
+ sdCardPresent: features.sdCardPresent,
42178
+ sdProtection: features.sdProtection,
42179
+ wipeCodeProtection: features.wipeCodeProtection,
42180
+ passphraseAlwaysOnDevice: features.passphraseAlwaysOnDevice,
42181
+ safetyChecks: features.safetyChecks,
42182
+ autoLockDelayMs: features.autoLockDelayMs,
42183
+ autoShutdownDelayMs: features.autoShutdownDelayMs,
42184
+ displayRotation: features.displayRotation,
42185
+ experimentalFeatures: features.experimentalFeatures,
42186
+ wallpaperPath: features.wallpaperPath,
42187
+ brightness: features.brightness,
42188
+ animationEnabled: features.animationEnabled,
42189
+ tapToWake: features.tapToWake,
42190
+ hapticFeedback: features.hapticFeedback,
42191
+ deviceNameDisplayEnabled: features.deviceNameDisplayEnabled,
42192
+ airgapMode: features.airgapMode,
42193
+ fidoEnabled: features.fidoEnabled,
42194
+ usbLockEnabled: features.usbLockEnabled,
42195
+ randomKeypad: features.randomKeypad,
42196
+ },
42197
+ versions: {
42198
+ firmware: features.firmwareVersion,
42199
+ bootloader: features.bootloaderVersion,
42200
+ board: features.boardVersion,
42201
+ ble: features.bleVersion,
42202
+ se: features.seVersion,
42203
+ se01: features.se01Version,
42204
+ se02: features.se02Version,
42205
+ se03: features.se03Version,
42206
+ se04: features.se04Version,
42207
+ se01Boot: features.se01BootVersion,
42208
+ se02Boot: features.se02BootVersion,
42209
+ se03Boot: features.se03BootVersion,
42210
+ se04Boot: features.se04BootVersion,
42211
+ },
42212
+ capabilities: features.capabilities,
42213
+ verification: definedEntries((_c = features.verify) !== null && _c !== void 0 ? _c : {}),
42214
+ session: {
42215
+ sessionId: features.sessionId,
42216
+ passphraseState: features.passphraseState,
42217
+ },
42218
+ raw: features.raw,
42219
+ });
42220
+ };
42221
+ const meaningfulVersion = (version) => {
42222
+ if (!version || version === '0.0.0')
42223
+ return undefined;
42224
+ const parts = version.split('.');
42225
+ while (parts.length < 3)
42226
+ parts.push('0');
42227
+ return parts.map(part => (Number.isNaN(Number.parseInt(part, 10)) ? '0' : part)).join('.');
42228
+ };
42229
+ const mapProtocolV1OnekeyFeaturesToState = (features) => {
42230
+ const verification = definedEntries({
42231
+ firmwareBuildId: features.onekey_firmware_build_id,
42232
+ firmwareHash: features.onekey_firmware_hash,
42233
+ bootloaderBuildId: features.onekey_boot_build_id,
42234
+ bootloaderHash: features.onekey_boot_hash,
42235
+ boardBuildId: features.onekey_board_build_id,
42236
+ boardHash: features.onekey_board_hash,
42237
+ bleBuildId: features.onekey_ble_build_id,
42238
+ bleHash: features.onekey_ble_hash,
42239
+ se01BuildId: features.onekey_se01_build_id,
42240
+ se01Hash: features.onekey_se01_hash,
42241
+ se02BuildId: features.onekey_se02_build_id,
42242
+ se02Hash: features.onekey_se02_hash,
42243
+ se03BuildId: features.onekey_se03_build_id,
42244
+ se03Hash: features.onekey_se03_hash,
42245
+ se04BuildId: features.onekey_se04_build_id,
42246
+ se04Hash: features.onekey_se04_hash,
42247
+ se01BootBuildId: features.onekey_se01_boot_build_id,
42248
+ se01BootHash: features.onekey_se01_boot_hash,
42249
+ se02BootBuildId: features.onekey_se02_boot_build_id,
42250
+ se02BootHash: features.onekey_se02_boot_hash,
42251
+ se03BootBuildId: features.onekey_se03_boot_build_id,
42252
+ se03BootHash: features.onekey_se03_boot_hash,
42253
+ se04BootBuildId: features.onekey_se04_boot_build_id,
42254
+ se04BootHash: features.onekey_se04_boot_hash,
42255
+ });
42256
+ return Object.assign(Object.assign({ versions: definedEntries({
42257
+ firmware: meaningfulVersion(features.onekey_firmware_version),
42258
+ bootloader: meaningfulVersion(features.onekey_boot_version),
42259
+ board: meaningfulVersion(features.onekey_board_version),
42260
+ ble: meaningfulVersion(features.onekey_ble_version),
42261
+ se01: meaningfulVersion(features.onekey_se01_version),
42262
+ se02: meaningfulVersion(features.onekey_se02_version),
42263
+ se03: meaningfulVersion(features.onekey_se03_version),
42264
+ se04: meaningfulVersion(features.onekey_se04_version),
42265
+ se01Boot: meaningfulVersion(features.onekey_se01_boot_version),
42266
+ se02Boot: meaningfulVersion(features.onekey_se02_boot_version),
42267
+ se03Boot: meaningfulVersion(features.onekey_se03_boot_version),
42268
+ se04Boot: meaningfulVersion(features.onekey_se04_boot_version),
42269
+ }) }, (Object.keys(verification).length > 0 ? { verification } : {})), { raw: { protocolV1OneKeyFeatures: features } });
42270
+ };
42271
+ const mapProtocolV2DeviceInfoToState = (info, currentMode) => {
42272
+ 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;
42273
+ const romloader = isProtocolV2RomloaderDeviceInfo(info);
42274
+ const bootloader = isProtocolV2BootloaderDeviceInfo(info);
42275
+ const loader = romloader || bootloader;
42276
+ let mode = 'normal';
42277
+ if (romloader) {
42366
42278
  mode = 'romloader';
42367
42279
  }
42368
- else if (bootloaderMode) {
42280
+ else if (bootloader) {
42369
42281
  mode = 'bootloader';
42370
42282
  }
42371
- else if (initialized === false) {
42372
- mode = 'notInitialized';
42373
- }
42374
- else if (initialized === true) {
42375
- mode = 'normal';
42283
+ else if (currentMode === 'notInitialized' || currentMode === 'backupMode') {
42284
+ mode = currentMode;
42376
42285
  }
42377
42286
  return {
42378
42287
  protocol: 'V2',
42379
- protocolVersion: (_t = (_s = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.protocol_version) !== null && _s !== void 0 ? _s : previous === null || previous === void 0 ? void 0 : previous.protocolVersion) !== null && _t !== void 0 ? _t : null,
42380
- deviceType: hdShared.EDeviceType.Pro2,
42381
- firmwareType: (_u = previous === null || previous === void 0 ? void 0 : previous.firmwareType) !== null && _u !== void 0 ? _u : hdShared.EFirmwareType.Universal,
42382
- model: 'pro2',
42383
- vendor: 'onekey.so',
42384
- deviceId,
42385
- serialNo,
42386
- label,
42387
- bleName: bleName !== null && bleName !== void 0 ? bleName : null,
42388
- capabilities: [],
42389
- mode,
42390
- initialized,
42391
- bootloaderMode,
42392
- unlocked,
42393
- firmwarePresent: (_v = previous === null || previous === void 0 ? void 0 : previous.firmwarePresent) !== null && _v !== void 0 ? _v : null,
42394
- passphraseProtection,
42395
- pinProtection: null,
42396
- backupRequired,
42397
- noBackup: null,
42398
- unfinishedBackup: null,
42399
- recoveryMode: null,
42400
- language,
42401
- bleEnabled: bleEnabled !== null && bleEnabled !== void 0 ? bleEnabled : null,
42402
- sdCardPresent: null,
42403
- sdProtection: null,
42404
- wipeCodeProtection: null,
42405
- passphraseAlwaysOnDevice: null,
42406
- attachToPinEnabled,
42407
- safetyChecks: null,
42408
- autoLockDelayMs: null,
42409
- displayRotation: null,
42410
- experimentalFeatures: null,
42411
- firmwareVersion,
42412
- bootloaderVersion,
42413
- boardVersion,
42414
- bleVersion,
42415
- se01Version: firstMeaningfulVersion(getImageVersion((_w = info === null || info === void 0 ? void 0 : info.se1) === null || _w === void 0 ? void 0 : _w.application), previous === null || previous === void 0 ? void 0 : previous.se01Version),
42416
- se02Version: firstMeaningfulVersion(getImageVersion((_x = info === null || info === void 0 ? void 0 : info.se2) === null || _x === void 0 ? void 0 : _x.application), previous === null || previous === void 0 ? void 0 : previous.se02Version),
42417
- se03Version: firstMeaningfulVersion(getImageVersion((_y = info === null || info === void 0 ? void 0 : info.se3) === null || _y === void 0 ? void 0 : _y.application), previous === null || previous === void 0 ? void 0 : previous.se03Version),
42418
- se04Version: firstMeaningfulVersion(getImageVersion((_z = info === null || info === void 0 ? void 0 : info.se4) === null || _z === void 0 ? void 0 : _z.application), previous === null || previous === void 0 ? void 0 : previous.se04Version),
42419
- se01BootVersion: firstMeaningfulVersion(getImageVersion((_0 = info === null || info === void 0 ? void 0 : info.se1) === null || _0 === void 0 ? void 0 : _0.bootloader), previous === null || previous === void 0 ? void 0 : previous.se01BootVersion),
42420
- se02BootVersion: firstMeaningfulVersion(getImageVersion((_1 = info === null || info === void 0 ? void 0 : info.se2) === null || _1 === void 0 ? void 0 : _1.bootloader), previous === null || previous === void 0 ? void 0 : previous.se02BootVersion),
42421
- se03BootVersion: firstMeaningfulVersion(getImageVersion((_2 = info === null || info === void 0 ? void 0 : info.se3) === null || _2 === void 0 ? void 0 : _2.bootloader), previous === null || previous === void 0 ? void 0 : previous.se03BootVersion),
42422
- se04BootVersion: firstMeaningfulVersion(getImageVersion((_3 = info === null || info === void 0 ? void 0 : info.se4) === null || _3 === void 0 ? void 0 : _3.bootloader), previous === null || previous === void 0 ? void 0 : previous.se04BootVersion),
42423
- seVersion: (_4 = previous === null || previous === void 0 ? void 0 : previous.seVersion) !== null && _4 !== void 0 ? _4 : null,
42424
- verify: {
42425
- firmwareBuildId: (_5 = getImageBuildId(fwApplication)) !== null && _5 !== void 0 ? _5 : (_6 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _6 === void 0 ? void 0 : _6.firmwareBuildId,
42426
- firmwareHash: (_7 = getImageHash(fwApplication)) !== null && _7 !== void 0 ? _7 : (_8 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _8 === void 0 ? void 0 : _8.firmwareHash,
42427
- bootloaderBuildId: (_9 = getImageBuildId(fwBootloader)) !== null && _9 !== void 0 ? _9 : (_10 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _10 === void 0 ? void 0 : _10.bootloaderBuildId,
42428
- bootloaderHash: (_11 = getImageHash(fwBootloader)) !== null && _11 !== void 0 ? _11 : (_12 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _12 === void 0 ? void 0 : _12.bootloaderHash,
42429
- boardBuildId: (_13 = getImageBuildId(fwBoard)) !== null && _13 !== void 0 ? _13 : (_14 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _14 === void 0 ? void 0 : _14.boardBuildId,
42430
- boardHash: (_15 = getImageHash(fwBoard)) !== null && _15 !== void 0 ? _15 : (_16 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _16 === void 0 ? void 0 : _16.boardHash,
42431
- bleBuildId: (_17 = getImageBuildId(bleApplication)) !== null && _17 !== void 0 ? _17 : (_18 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _18 === void 0 ? void 0 : _18.bleBuildId,
42432
- bleHash: (_19 = getImageHash(bleApplication)) !== null && _19 !== void 0 ? _19 : (_20 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _20 === void 0 ? void 0 : _20.bleHash,
42433
- se01BuildId: (_22 = getImageBuildId((_21 = info === null || info === void 0 ? void 0 : info.se1) === null || _21 === void 0 ? void 0 : _21.application)) !== null && _22 !== void 0 ? _22 : (_23 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _23 === void 0 ? void 0 : _23.se01BuildId,
42434
- se01Hash: (_25 = getImageHash((_24 = info === null || info === void 0 ? void 0 : info.se1) === null || _24 === void 0 ? void 0 : _24.application)) !== null && _25 !== void 0 ? _25 : (_26 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _26 === void 0 ? void 0 : _26.se01Hash,
42435
- se02BuildId: (_28 = getImageBuildId((_27 = info === null || info === void 0 ? void 0 : info.se2) === null || _27 === void 0 ? void 0 : _27.application)) !== null && _28 !== void 0 ? _28 : (_29 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _29 === void 0 ? void 0 : _29.se02BuildId,
42436
- se02Hash: (_31 = getImageHash((_30 = info === null || info === void 0 ? void 0 : info.se2) === null || _30 === void 0 ? void 0 : _30.application)) !== null && _31 !== void 0 ? _31 : (_32 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _32 === void 0 ? void 0 : _32.se02Hash,
42437
- se03BuildId: (_34 = getImageBuildId((_33 = info === null || info === void 0 ? void 0 : info.se3) === null || _33 === void 0 ? void 0 : _33.application)) !== null && _34 !== void 0 ? _34 : (_35 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _35 === void 0 ? void 0 : _35.se03BuildId,
42438
- se03Hash: (_37 = getImageHash((_36 = info === null || info === void 0 ? void 0 : info.se3) === null || _36 === void 0 ? void 0 : _36.application)) !== null && _37 !== void 0 ? _37 : (_38 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _38 === void 0 ? void 0 : _38.se03Hash,
42439
- se04BuildId: (_40 = getImageBuildId((_39 = info === null || info === void 0 ? void 0 : info.se4) === null || _39 === void 0 ? void 0 : _39.application)) !== null && _40 !== void 0 ? _40 : (_41 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _41 === void 0 ? void 0 : _41.se04BuildId,
42440
- se04Hash: (_43 = getImageHash((_42 = info === null || info === void 0 ? void 0 : info.se4) === null || _42 === void 0 ? void 0 : _42.application)) !== null && _43 !== void 0 ? _43 : (_44 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _44 === void 0 ? void 0 : _44.se04Hash,
42441
- se01BootBuildId: (_46 = getImageBuildId((_45 = info === null || info === void 0 ? void 0 : info.se1) === null || _45 === void 0 ? void 0 : _45.bootloader)) !== null && _46 !== void 0 ? _46 : (_47 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _47 === void 0 ? void 0 : _47.se01BootBuildId,
42442
- se01BootHash: (_49 = getImageHash((_48 = info === null || info === void 0 ? void 0 : info.se1) === null || _48 === void 0 ? void 0 : _48.bootloader)) !== null && _49 !== void 0 ? _49 : (_50 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _50 === void 0 ? void 0 : _50.se01BootHash,
42443
- se02BootBuildId: (_52 = getImageBuildId((_51 = info === null || info === void 0 ? void 0 : info.se2) === null || _51 === void 0 ? void 0 : _51.bootloader)) !== null && _52 !== void 0 ? _52 : (_53 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _53 === void 0 ? void 0 : _53.se02BootBuildId,
42444
- se02BootHash: (_55 = getImageHash((_54 = info === null || info === void 0 ? void 0 : info.se2) === null || _54 === void 0 ? void 0 : _54.bootloader)) !== null && _55 !== void 0 ? _55 : (_56 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _56 === void 0 ? void 0 : _56.se02BootHash,
42445
- se03BootBuildId: (_58 = getImageBuildId((_57 = info === null || info === void 0 ? void 0 : info.se3) === null || _57 === void 0 ? void 0 : _57.bootloader)) !== null && _58 !== void 0 ? _58 : (_59 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _59 === void 0 ? void 0 : _59.se03BootBuildId,
42446
- se03BootHash: (_61 = getImageHash((_60 = info === null || info === void 0 ? void 0 : info.se3) === null || _60 === void 0 ? void 0 : _60.bootloader)) !== null && _61 !== void 0 ? _61 : (_62 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _62 === void 0 ? void 0 : _62.se03BootHash,
42447
- se04BootBuildId: (_64 = getImageBuildId((_63 = info === null || info === void 0 ? void 0 : info.se4) === null || _63 === void 0 ? void 0 : _63.bootloader)) !== null && _64 !== void 0 ? _64 : (_65 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _65 === void 0 ? void 0 : _65.se04BootBuildId,
42448
- se04BootHash: (_67 = getImageHash((_66 = info === null || info === void 0 ? void 0 : info.se4) === null || _66 === void 0 ? void 0 : _66.bootloader)) !== null && _67 !== void 0 ? _67 : (_68 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _68 === void 0 ? void 0 : _68.se04BootHash,
42288
+ protocolVersion: info.protocol_version,
42289
+ identity: definedEntries({
42290
+ deviceType: hdShared.EDeviceType.Pro2,
42291
+ firmwareType: hdShared.EFirmwareType.Universal,
42292
+ model: 'pro2',
42293
+ vendor: 'onekey.so',
42294
+ serialNo: (_a = info.hw) === null || _a === void 0 ? void 0 : _a.serial_no,
42295
+ bleName: (_b = info.coprocessor) === null || _b === void 0 ? void 0 : _b.bt_adv_name,
42296
+ deviceId: loader ? null : undefined,
42297
+ }),
42298
+ status: loader
42299
+ ? {
42300
+ mode,
42301
+ initialized: null,
42302
+ unlocked: null,
42303
+ firmwarePresent: null,
42304
+ backupRequired: null,
42305
+ noBackup: null,
42306
+ unfinishedBackup: null,
42307
+ recoveryMode: null,
42308
+ passphraseProtection: null,
42309
+ pinProtection: null,
42310
+ attachToPinEnabled: null,
42311
+ unlockedAttachPin: null,
42312
+ }
42313
+ : { mode },
42314
+ versions: definedEntries({
42315
+ firmware: imageVersion((_c = info.fw) === null || _c === void 0 ? void 0 : _c.application),
42316
+ bootloader: imageVersion((_d = info.fw) === null || _d === void 0 ? void 0 : _d.bootloader),
42317
+ board: imageVersion((_e = info.fw) === null || _e === void 0 ? void 0 : _e.romloader),
42318
+ ble: imageVersion((_f = info.coprocessor) === null || _f === void 0 ? void 0 : _f.application),
42319
+ se01: imageVersion((_g = info.se1) === null || _g === void 0 ? void 0 : _g.application),
42320
+ se02: imageVersion((_h = info.se2) === null || _h === void 0 ? void 0 : _h.application),
42321
+ se03: imageVersion((_j = info.se3) === null || _j === void 0 ? void 0 : _j.application),
42322
+ se04: imageVersion((_k = info.se4) === null || _k === void 0 ? void 0 : _k.application),
42323
+ se01Boot: imageVersion((_l = info.se1) === null || _l === void 0 ? void 0 : _l.bootloader),
42324
+ se02Boot: imageVersion((_m = info.se2) === null || _m === void 0 ? void 0 : _m.bootloader),
42325
+ se03Boot: imageVersion((_o = info.se3) === null || _o === void 0 ? void 0 : _o.bootloader),
42326
+ se04Boot: imageVersion((_p = info.se4) === null || _p === void 0 ? void 0 : _p.bootloader),
42327
+ }),
42328
+ verification: definedEntries({
42329
+ firmwareBuildId: imageBuildId((_q = info.fw) === null || _q === void 0 ? void 0 : _q.application),
42330
+ firmwareHash: imageHash((_r = info.fw) === null || _r === void 0 ? void 0 : _r.application),
42331
+ bootloaderBuildId: imageBuildId((_s = info.fw) === null || _s === void 0 ? void 0 : _s.bootloader),
42332
+ bootloaderHash: imageHash((_t = info.fw) === null || _t === void 0 ? void 0 : _t.bootloader),
42333
+ boardBuildId: imageBuildId((_u = info.fw) === null || _u === void 0 ? void 0 : _u.romloader),
42334
+ boardHash: imageHash((_v = info.fw) === null || _v === void 0 ? void 0 : _v.romloader),
42335
+ bleBuildId: imageBuildId((_w = info.coprocessor) === null || _w === void 0 ? void 0 : _w.application),
42336
+ bleHash: imageHash((_x = info.coprocessor) === null || _x === void 0 ? void 0 : _x.application),
42337
+ se01BuildId: imageBuildId((_y = info.se1) === null || _y === void 0 ? void 0 : _y.application),
42338
+ se01Hash: imageHash((_z = info.se1) === null || _z === void 0 ? void 0 : _z.application),
42339
+ se02BuildId: imageBuildId((_0 = info.se2) === null || _0 === void 0 ? void 0 : _0.application),
42340
+ se02Hash: imageHash((_1 = info.se2) === null || _1 === void 0 ? void 0 : _1.application),
42341
+ se03BuildId: imageBuildId((_2 = info.se3) === null || _2 === void 0 ? void 0 : _2.application),
42342
+ se03Hash: imageHash((_3 = info.se3) === null || _3 === void 0 ? void 0 : _3.application),
42343
+ se04BuildId: imageBuildId((_4 = info.se4) === null || _4 === void 0 ? void 0 : _4.application),
42344
+ se04Hash: imageHash((_5 = info.se4) === null || _5 === void 0 ? void 0 : _5.application),
42345
+ se01BootBuildId: imageBuildId((_6 = info.se1) === null || _6 === void 0 ? void 0 : _6.bootloader),
42346
+ se01BootHash: imageHash((_7 = info.se1) === null || _7 === void 0 ? void 0 : _7.bootloader),
42347
+ se02BootBuildId: imageBuildId((_8 = info.se2) === null || _8 === void 0 ? void 0 : _8.bootloader),
42348
+ se02BootHash: imageHash((_9 = info.se2) === null || _9 === void 0 ? void 0 : _9.bootloader),
42349
+ se03BootBuildId: imageBuildId((_10 = info.se3) === null || _10 === void 0 ? void 0 : _10.bootloader),
42350
+ se03BootHash: imageHash((_11 = info.se3) === null || _11 === void 0 ? void 0 : _11.bootloader),
42351
+ se04BootBuildId: imageBuildId((_12 = info.se4) === null || _12 === void 0 ? void 0 : _12.bootloader),
42352
+ se04BootHash: imageHash((_13 = info.se4) === null || _13 === void 0 ? void 0 : _13.bootloader),
42353
+ }),
42354
+ raw: Object.assign({ protocolV2DeviceInfo: info }, (loader ? { protocolV2DeviceStatus: null } : {})),
42355
+ };
42356
+ };
42357
+ const mapProtocolV2DeviceStatusToState = (status) => {
42358
+ var _a;
42359
+ return ({
42360
+ identity: definedEntries({ deviceId: status.device_id }),
42361
+ status: definedEntries({
42362
+ mode: getProtocolV2StatusMode(status.init_states),
42363
+ initialized: status.init_states,
42364
+ unlocked: status.unlocked,
42365
+ passphraseProtection: status.unlocked === true ? (_a = status.passphrase_enabled) !== null && _a !== void 0 ? _a : null : undefined,
42366
+ backupRequired: status.backup_required,
42367
+ attachToPinEnabled: status.attach_to_pin_enabled,
42368
+ unlockedAttachPin: status.unlocked_by_attach_to_pin,
42369
+ }),
42370
+ raw: { protocolV2DeviceStatus: status },
42371
+ });
42372
+ };
42373
+ const mapApplySettingsToState = (settings) => {
42374
+ const identity = definedEntries({ label: settings.label });
42375
+ const status = definedEntries({ passphraseProtection: settings.use_passphrase });
42376
+ const stateSettings = definedEntries({
42377
+ language: settings.language,
42378
+ autoLockDelayMs: settings.auto_lock_delay_ms,
42379
+ autoShutdownDelayMs: settings.auto_shutdown_delay_ms,
42380
+ displayRotation: settings.display_rotation,
42381
+ passphraseAlwaysOnDevice: settings.passphrase_always_on_device,
42382
+ safetyChecks: settings.safety_checks,
42383
+ experimentalFeatures: settings.experimental_features,
42384
+ hapticFeedback: settings.haptic_feedback,
42385
+ });
42386
+ return Object.assign(Object.assign(Object.assign({}, (Object.keys(identity).length ? { identity } : {})), (Object.keys(status).length ? { status } : {})), (Object.keys(stateSettings).length ? { settings: stateSettings } : {}));
42387
+ };
42388
+ const mapDeviceSettingsToState = (settings) => {
42389
+ const settingsWithExperimental = settings;
42390
+ const identity = definedEntries({ label: settings.label });
42391
+ const status = definedEntries({ passphraseProtection: settings.passphrase_enable });
42392
+ const stateSettings = definedEntries({
42393
+ bleEnabled: settings.bt_enable,
42394
+ language: settings.language,
42395
+ wallpaperPath: settings.wallpaper_path,
42396
+ brightness: settings.brightness,
42397
+ autoLockDelayMs: settings.autolock_delay_ms,
42398
+ autoShutdownDelayMs: settings.autoshutdown_delay_ms,
42399
+ animationEnabled: settings.animation_enable,
42400
+ tapToWake: settings.tap_to_wake,
42401
+ hapticFeedback: settings.haptic_feedback,
42402
+ deviceNameDisplayEnabled: settings.device_name_display_enabled,
42403
+ airgapMode: settings.airgap_mode,
42404
+ fidoEnabled: settings.fido_enabled,
42405
+ experimentalFeatures: settingsWithExperimental.experimental_features,
42406
+ usbLockEnabled: settings.usb_lock_enable,
42407
+ randomKeypad: settings.random_keypad,
42408
+ });
42409
+ return Object.assign(Object.assign(Object.assign({}, (Object.keys(identity).length ? { identity } : {})), (Object.keys(status).length ? { status } : {})), (Object.keys(stateSettings).length ? { settings: stateSettings } : {}));
42410
+ };
42411
+ const mapCommonSettingsToProtocolV2 = (settings) => definedEntries({
42412
+ label: settings.label,
42413
+ bt_enable: settings.bluetoothEnabled,
42414
+ language: settings.language,
42415
+ brightness: settings.brightness,
42416
+ autolock_delay_ms: settings.autoLockDelayMs,
42417
+ autoshutdown_delay_ms: settings.autoShutdownDelayMs,
42418
+ animation_enable: settings.animationEnabled,
42419
+ tap_to_wake: settings.tapToWake,
42420
+ haptic_feedback: settings.hapticFeedback,
42421
+ device_name_display_enabled: settings.deviceNameDisplayEnabled,
42422
+ fido_enabled: settings.fidoEnabled,
42423
+ usb_lock_enable: settings.usbLockEnabled,
42424
+ random_keypad: settings.randomKeypad,
42425
+ });
42426
+
42427
+ const getBootloaderMode = (state) => state.status.mode === 'bootloader' || state.status.mode === 'romloader';
42428
+ const projectFeatures = (state) => {
42429
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
42430
+ const snapshot = structuredClone(state);
42431
+ const rawFeatures = (_b = (_a = snapshot.raw) === null || _a === void 0 ? void 0 : _a.protocolV1Features) !== null && _b !== void 0 ? _b : {};
42432
+ const rawOneKeyFeatures = (_d = (_c = snapshot.raw) === null || _c === void 0 ? void 0 : _c.protocolV1OneKeyFeatures) !== null && _d !== void 0 ? _d : {};
42433
+ const sessionId = (_f = (_e = snapshot.session) === null || _e === void 0 ? void 0 : _e.sessionId) !== null && _f !== void 0 ? _f : null;
42434
+ const bootloaderMode = snapshot.protocol === 'V1'
42435
+ ? (_g = rawFeatures.bootloader_mode) !== null && _g !== void 0 ? _g : null
42436
+ : getBootloaderMode(snapshot);
42437
+ return Object.assign(Object.assign(Object.assign({}, rawFeatures), rawOneKeyFeatures), { protocol: snapshot.protocol, protocolVersion: (_h = snapshot.protocolVersion) !== null && _h !== void 0 ? _h : (snapshot.protocol === 'V1' ? 1 : null), deviceType: snapshot.identity.deviceType, firmwareType: snapshot.identity.firmwareType, model: snapshot.identity.model, vendor: snapshot.identity.vendor, deviceId: snapshot.identity.deviceId, serialNo: snapshot.identity.serialNo, label: snapshot.identity.label, bleName: snapshot.identity.bleName, capabilities: snapshot.capabilities, mode: snapshot.status.mode, initialized: snapshot.status.initialized, bootloaderMode, unlocked: snapshot.status.unlocked, firmwarePresent: snapshot.status.firmwarePresent, passphraseProtection: snapshot.status.passphraseProtection, pinProtection: snapshot.status.pinProtection, backupRequired: snapshot.status.backupRequired, noBackup: snapshot.status.noBackup, unfinishedBackup: snapshot.status.unfinishedBackup, recoveryMode: snapshot.status.recoveryMode, attachToPinEnabled: snapshot.status.attachToPinEnabled, unlockedAttachPin: (_j = snapshot.status.unlockedAttachPin) !== null && _j !== void 0 ? _j : undefined, language: snapshot.settings.language, bleEnabled: snapshot.settings.bleEnabled, sdCardPresent: snapshot.settings.sdCardPresent, sdProtection: snapshot.settings.sdProtection, wipeCodeProtection: snapshot.settings.wipeCodeProtection, passphraseAlwaysOnDevice: snapshot.settings.passphraseAlwaysOnDevice, safetyChecks: snapshot.settings.safetyChecks, autoLockDelayMs: snapshot.settings.autoLockDelayMs, autoShutdownDelayMs: snapshot.settings.autoShutdownDelayMs, displayRotation: snapshot.settings.displayRotation, experimentalFeatures: snapshot.settings.experimentalFeatures, wallpaperPath: snapshot.settings.wallpaperPath, brightness: snapshot.settings.brightness, animationEnabled: snapshot.settings.animationEnabled, tapToWake: snapshot.settings.tapToWake, hapticFeedback: snapshot.settings.hapticFeedback, deviceNameDisplayEnabled: snapshot.settings.deviceNameDisplayEnabled, airgapMode: snapshot.settings.airgapMode, fidoEnabled: snapshot.settings.fidoEnabled, usbLockEnabled: snapshot.settings.usbLockEnabled, randomKeypad: snapshot.settings.randomKeypad, firmwareVersion: snapshot.versions.firmware, bootloaderVersion: snapshot.versions.bootloader, boardVersion: snapshot.versions.board, bleVersion: snapshot.versions.ble, se01Version: snapshot.versions.se01, se02Version: snapshot.versions.se02, se03Version: snapshot.versions.se03, se04Version: snapshot.versions.se04, se01BootVersion: snapshot.versions.se01Boot, se02BootVersion: snapshot.versions.se02Boot, se03BootVersion: snapshot.versions.se03Boot, se04BootVersion: snapshot.versions.se04Boot, seVersion: (_k = snapshot.versions.se) !== null && _k !== void 0 ? _k : null, verify: snapshot.verification, sessionId, passphraseState: (_l = snapshot.session) === null || _l === void 0 ? void 0 : _l.passphraseState, raw: snapshot.raw, device_id: (_m = snapshot.identity.deviceId) !== null && _m !== void 0 ? _m : undefined, session_id: sessionId !== null && sessionId !== void 0 ? sessionId : undefined, ble_name: (_o = snapshot.identity.bleName) !== null && _o !== void 0 ? _o : undefined, passphrase_protection: (_p = snapshot.status.passphraseProtection) !== null && _p !== void 0 ? _p : undefined, bootloader_mode: bootloaderMode });
42438
+ };
42439
+
42440
+ const PRODUCT_DISPLAY_NAMES = {
42441
+ [hdShared.EDeviceType.Classic]: 'OneKey Classic',
42442
+ [hdShared.EDeviceType.Classic1s]: 'OneKey Classic 1S',
42443
+ [hdShared.EDeviceType.ClassicPure]: 'OneKey Classic 1S Pure',
42444
+ [hdShared.EDeviceType.Mini]: 'OneKey Mini',
42445
+ [hdShared.EDeviceType.Touch]: 'OneKey Touch',
42446
+ [hdShared.EDeviceType.Pro]: 'OneKey Pro',
42447
+ [hdShared.EDeviceType.Pro2]: 'OneKey Pro 2',
42448
+ };
42449
+ const getModelDisplayName = (deviceType) => { var _a; return (_a = PRODUCT_DISPLAY_NAMES[deviceType]) !== null && _a !== void 0 ? _a : 'OneKey'; };
42450
+ const getDisplayName = (identity) => identity.label || identity.bleName || getModelDisplayName(identity.deviceType);
42451
+ function createEmptyDeviceState(identity = {}) {
42452
+ const normalizedIdentity = Object.assign({ deviceType: hdShared.EDeviceType.Unknown, firmwareType: hdShared.EFirmwareType.Universal, model: null, vendor: null, deviceId: null, serialNo: '', label: null, bleName: null, displayName: '' }, identity);
42453
+ normalizedIdentity.displayName = getDisplayName(normalizedIdentity);
42454
+ return {
42455
+ schemaVersion: 1,
42456
+ revision: 0,
42457
+ updatedAt: Date.now(),
42458
+ protocol: 'unknown',
42459
+ protocolVersion: null,
42460
+ identity: normalizedIdentity,
42461
+ status: {
42462
+ mode: 'unknown',
42463
+ initialized: null,
42464
+ unlocked: null,
42465
+ firmwarePresent: null,
42466
+ backupRequired: null,
42467
+ noBackup: null,
42468
+ unfinishedBackup: null,
42469
+ recoveryMode: null,
42470
+ passphraseProtection: null,
42471
+ pinProtection: null,
42472
+ attachToPinEnabled: null,
42473
+ unlockedAttachPin: null,
42474
+ },
42475
+ settings: {
42476
+ language: null,
42477
+ bleEnabled: null,
42478
+ sdCardPresent: null,
42479
+ sdProtection: null,
42480
+ wipeCodeProtection: null,
42481
+ passphraseAlwaysOnDevice: null,
42482
+ safetyChecks: null,
42483
+ autoLockDelayMs: null,
42484
+ autoShutdownDelayMs: null,
42485
+ displayRotation: null,
42486
+ experimentalFeatures: null,
42487
+ wallpaperPath: null,
42488
+ brightness: null,
42489
+ animationEnabled: null,
42490
+ tapToWake: null,
42491
+ hapticFeedback: null,
42492
+ deviceNameDisplayEnabled: null,
42493
+ airgapMode: null,
42494
+ fidoEnabled: null,
42495
+ usbLockEnabled: null,
42496
+ randomKeypad: null,
42449
42497
  },
42450
- sessionId: (_69 = previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _69 !== void 0 ? _69 : null,
42451
- device_id: deviceId !== null && deviceId !== void 0 ? deviceId : undefined,
42452
- session_id: (_70 = previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _70 !== void 0 ? _70 : undefined,
42453
- ble_name: bleName !== null && bleName !== void 0 ? bleName : undefined,
42454
- onekey_device_type: 'PRO2',
42455
- passphrase_protection: passphraseProtection !== null && passphraseProtection !== void 0 ? passphraseProtection : undefined,
42456
- bootloader_mode: bootloaderMode,
42457
- passphraseState: previous === null || previous === void 0 ? void 0 : previous.passphraseState,
42458
- unlockedAttachPin,
42459
- raw: {
42460
- protocolV2DeviceInfo: deviceInfo,
42461
- protocolV2DeviceStatus: deviceStatus,
42498
+ versions: {
42499
+ firmware: null,
42500
+ bootloader: null,
42501
+ board: null,
42502
+ ble: null,
42462
42503
  },
42504
+ capabilities: [],
42463
42505
  };
42506
+ }
42507
+ const isEqual = (left, right) => JSON.stringify(left) === JSON.stringify(right);
42508
+ const applySectionPatch = (target, patch, prefix, changedKeys) => {
42509
+ for (const [key, value] of Object.entries(patch)) {
42510
+ if (value !== undefined && !isEqual(target[key], value)) {
42511
+ target[key] = value;
42512
+ changedKeys.push(`${prefix}.${String(key)}`);
42513
+ }
42514
+ }
42515
+ };
42516
+ class DeviceStateStore {
42517
+ constructor(initial) {
42518
+ this.state = initial ? structuredClone(initial) : undefined;
42519
+ }
42520
+ getState() {
42521
+ return this.state;
42522
+ }
42523
+ replace(state, source) {
42524
+ var _a, _b;
42525
+ const revision = ((_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.revision) !== null && _b !== void 0 ? _b : 0) + 1;
42526
+ this.state = Object.assign(Object.assign({}, structuredClone(state)), { revision, updatedAt: Date.now() });
42527
+ return {
42528
+ state: this.state,
42529
+ revision,
42530
+ source,
42531
+ changedKeys: ['*'],
42532
+ };
42533
+ }
42534
+ update(patch, source) {
42535
+ var _a, _b, _c, _d, _e, _f;
42536
+ const next = structuredClone((_a = this.state) !== null && _a !== void 0 ? _a : createEmptyDeviceState());
42537
+ const changedKeys = [];
42538
+ if (patch.protocol !== undefined && patch.protocol !== next.protocol) {
42539
+ next.protocol = patch.protocol;
42540
+ changedKeys.push('protocol');
42541
+ }
42542
+ if (patch.protocolVersion !== undefined && patch.protocolVersion !== next.protocolVersion) {
42543
+ next.protocolVersion = patch.protocolVersion;
42544
+ changedKeys.push('protocolVersion');
42545
+ }
42546
+ if (patch.identity)
42547
+ applySectionPatch(next.identity, patch.identity, 'identity', changedKeys);
42548
+ if (patch.status)
42549
+ applySectionPatch(next.status, patch.status, 'status', changedKeys);
42550
+ if (patch.settings)
42551
+ applySectionPatch(next.settings, patch.settings, 'settings', changedKeys);
42552
+ if (patch.versions)
42553
+ applySectionPatch(next.versions, patch.versions, 'versions', changedKeys);
42554
+ if (patch.capabilities !== undefined && !isEqual(next.capabilities, patch.capabilities)) {
42555
+ next.capabilities = structuredClone(patch.capabilities);
42556
+ changedKeys.push('capabilities');
42557
+ }
42558
+ if (patch.verification !== undefined) {
42559
+ const mergedVerification = Object.assign(Object.assign({}, structuredClone((_b = next.verification) !== null && _b !== void 0 ? _b : {})), structuredClone(patch.verification));
42560
+ if (!isEqual(next.verification, mergedVerification)) {
42561
+ next.verification = mergedVerification;
42562
+ changedKeys.push('verification');
42563
+ }
42564
+ }
42565
+ if (patch.raw !== undefined) {
42566
+ const mergedRaw = structuredClone((_c = next.raw) !== null && _c !== void 0 ? _c : {});
42567
+ for (const [key, value] of Object.entries(patch.raw)) {
42568
+ if (value === null) {
42569
+ delete mergedRaw[key];
42570
+ }
42571
+ else if (value !== undefined) {
42572
+ mergedRaw[key] = structuredClone(value);
42573
+ }
42574
+ }
42575
+ if (!isEqual(next.raw, mergedRaw)) {
42576
+ next.raw = mergedRaw;
42577
+ changedKeys.push('raw');
42578
+ }
42579
+ }
42580
+ if (patch.session === null) {
42581
+ if (next.session !== undefined) {
42582
+ delete next.session;
42583
+ changedKeys.push('session');
42584
+ }
42585
+ }
42586
+ else if (patch.session) {
42587
+ const session = (_d = next.session) !== null && _d !== void 0 ? _d : { sessionId: null };
42588
+ applySectionPatch(session, patch.session, 'session', changedKeys);
42589
+ next.session = session;
42590
+ }
42591
+ const displayName = getDisplayName(next.identity);
42592
+ if (displayName !== next.identity.displayName) {
42593
+ next.identity.displayName = displayName;
42594
+ changedKeys.push('identity.displayName');
42595
+ }
42596
+ if (changedKeys.length > 0) {
42597
+ next.revision = ((_f = (_e = this.state) === null || _e === void 0 ? void 0 : _e.revision) !== null && _f !== void 0 ? _f : 0) + 1;
42598
+ next.updatedAt = Date.now();
42599
+ this.state = next;
42600
+ }
42601
+ else if (!this.state) {
42602
+ this.state = next;
42603
+ }
42604
+ return {
42605
+ state: this.state,
42606
+ revision: this.state.revision,
42607
+ source,
42608
+ changedKeys,
42609
+ };
42610
+ }
42611
+ clearSession(source) {
42612
+ var _a;
42613
+ if (!((_a = this.state) === null || _a === void 0 ? void 0 : _a.session))
42614
+ return undefined;
42615
+ return this.update({ session: null }, source);
42616
+ }
42617
+ }
42618
+ const createPublicDeviceState = (state) => {
42619
+ const snapshot = structuredClone(state);
42620
+ delete snapshot.raw;
42621
+ delete snapshot.session;
42622
+ return snapshot;
42464
42623
  };
42465
42624
 
42625
+ class DeviceWalletSessionStore {
42626
+ constructor() {
42627
+ this.walletSessions = new Map();
42628
+ this.pendingSessions = new Map();
42629
+ }
42630
+ get(deviceKey, passphraseState) {
42631
+ var _a;
42632
+ if (!deviceKey || !passphraseState)
42633
+ return undefined;
42634
+ return (_a = this.walletSessions.get(deviceKey)) === null || _a === void 0 ? void 0 : _a.get(passphraseState);
42635
+ }
42636
+ set(deviceKey, passphraseState, sessionId) {
42637
+ if (!deviceKey || !passphraseState || !sessionId)
42638
+ return;
42639
+ let deviceSessions = this.walletSessions.get(deviceKey);
42640
+ if (!deviceSessions) {
42641
+ deviceSessions = new Map();
42642
+ this.walletSessions.set(deviceKey, deviceSessions);
42643
+ }
42644
+ deviceSessions.set(passphraseState, sessionId);
42645
+ }
42646
+ setPending(deviceKey, sessionId) {
42647
+ if (!deviceKey || !sessionId)
42648
+ return;
42649
+ this.pendingSessions.set(deviceKey, sessionId);
42650
+ }
42651
+ getPending(deviceKey) {
42652
+ if (!deviceKey)
42653
+ return undefined;
42654
+ return this.pendingSessions.get(deviceKey);
42655
+ }
42656
+ delete(deviceKey, passphraseState) {
42657
+ if (!deviceKey || !passphraseState)
42658
+ return;
42659
+ const deviceSessions = this.walletSessions.get(deviceKey);
42660
+ if (!deviceSessions)
42661
+ return;
42662
+ deviceSessions.delete(passphraseState);
42663
+ if (deviceSessions.size === 0) {
42664
+ this.walletSessions.delete(deviceKey);
42665
+ }
42666
+ }
42667
+ deletePending(deviceKey) {
42668
+ if (!deviceKey)
42669
+ return;
42670
+ this.pendingSessions.delete(deviceKey);
42671
+ }
42672
+ deleteDevice(deviceKey) {
42673
+ if (!deviceKey)
42674
+ return;
42675
+ this.walletSessions.delete(deviceKey);
42676
+ this.pendingSessions.delete(deviceKey);
42677
+ }
42678
+ migrateDeviceKey(from, to) {
42679
+ var _a;
42680
+ if (!from || !to || from === to)
42681
+ return;
42682
+ const sourceSessions = this.walletSessions.get(from);
42683
+ if (sourceSessions) {
42684
+ const targetSessions = (_a = this.walletSessions.get(to)) !== null && _a !== void 0 ? _a : new Map();
42685
+ this.walletSessions.set(to, targetSessions);
42686
+ sourceSessions.forEach((sessionId, passphraseState) => {
42687
+ targetSessions.set(passphraseState, sessionId);
42688
+ });
42689
+ this.walletSessions.delete(from);
42690
+ }
42691
+ const pendingSession = this.pendingSessions.get(from);
42692
+ if (pendingSession) {
42693
+ this.pendingSessions.set(to, pendingSession);
42694
+ this.pendingSessions.delete(from);
42695
+ }
42696
+ }
42697
+ clear() {
42698
+ this.walletSessions.clear();
42699
+ this.pendingSessions.clear();
42700
+ }
42701
+ }
42702
+ const deviceWalletSessionStore = new DeviceWalletSessionStore();
42703
+
42466
42704
  const parseRunOptions = (options) => {
42467
42705
  if (!options)
42468
42706
  options = {};
42469
42707
  return options;
42470
42708
  };
42471
- const Log$d = getLogger(exports.LoggerNames.Device);
42709
+ const Log$e = getLogger(exports.LoggerNames.Device);
42472
42710
  function preloadSessionCache(deviceId, passphraseState, sessionId) {
42473
42711
  deviceWalletSessionStore.set(deviceId, passphraseState, sessionId);
42474
42712
  }
42475
42713
  class Device extends events.exports {
42714
+ get state() {
42715
+ return this.stateStore.getState();
42716
+ }
42717
+ get features() {
42718
+ return this.state ? projectFeatures(this.state) : undefined;
42719
+ }
42720
+ set features(features) {
42721
+ this.stateStore = new DeviceStateStore();
42722
+ if (features) {
42723
+ this.stateStore.update(mapFeaturesToState(features), 'compatibility');
42724
+ }
42725
+ }
42476
42726
  constructor(descriptor, sdkInstanceId) {
42477
42727
  super();
42478
42728
  this.deviceConnector = null;
42479
42729
  this.deviceAcquired = false;
42480
- this.features = undefined;
42481
- this.featuresNeedsReload = false;
42730
+ this.stateStore = new DeviceStateStore();
42731
+ this.protocolV2StateNeedsReload = false;
42482
42732
  this.externalState = [];
42483
42733
  this.unavailableCapabilities = {};
42484
42734
  this.instance = 0;
@@ -42490,7 +42740,7 @@ class Device extends events.exports {
42490
42740
  this.sdkInstanceId = sdkInstanceId;
42491
42741
  this.instanceId = generateInstanceId('Device', this.sdkInstanceId);
42492
42742
  this.createdAt = Date.now();
42493
- Log$d.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
42743
+ Log$e.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
42494
42744
  }
42495
42745
  static fromDescriptor(originalDescriptor, sdkInstanceId) {
42496
42746
  const descriptor = Object.assign({}, originalDescriptor);
@@ -42508,6 +42758,7 @@ class Device extends events.exports {
42508
42758
  const connectId = this.getConnectId();
42509
42759
  const deviceId = this.getCurrentDeviceId() || null;
42510
42760
  const { features } = this;
42761
+ const state = this.state ? createPublicDeviceState(this.state) : undefined;
42511
42762
  return {
42512
42763
  connectId: DataManager.isBleConnect(env) ? this.mainId || null : connectId,
42513
42764
  uuid: serialNo,
@@ -42520,9 +42771,11 @@ class Device extends events.exports {
42520
42771
  path: (_a = this.originalDescriptor) === null || _a === void 0 ? void 0 : _a.path,
42521
42772
  bleName,
42522
42773
  name: bleName || label || `OneKey ${deviceType === null || deviceType === void 0 ? void 0 : deviceType.toUpperCase()}`,
42774
+ displayName: label || bleName || `OneKey ${deviceType === null || deviceType === void 0 ? void 0 : deviceType.toUpperCase()}`,
42523
42775
  label: label || 'OneKey',
42524
42776
  mode: this.getMode(),
42525
42777
  features,
42778
+ state,
42526
42779
  sessionId: (_c = (_b = this.features) === null || _b === void 0 ? void 0 : _b.sessionId) !== null && _c !== void 0 ? _c : null,
42527
42780
  firmwareVersion: this.getFirmwareVersion(),
42528
42781
  bleFirmwareVersion: this.getBLEFirmwareVersion(),
@@ -42570,12 +42823,12 @@ class Device extends events.exports {
42570
42823
  if (DataManager.isBleConnect(env)) {
42571
42824
  acquireResult = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id, undefined, true, expectedProtocol));
42572
42825
  this.mainId = (_b = acquireResult === null || acquireResult === void 0 ? void 0 : acquireResult.uuid) !== null && _b !== void 0 ? _b : '';
42573
- Log$d.debug('Expected uuid:', this.mainId);
42826
+ Log$e.debug('Expected uuid:', this.mainId);
42574
42827
  }
42575
42828
  else {
42576
42829
  acquireResult = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session, undefined, expectedProtocol));
42577
42830
  this.mainId = acquireResult;
42578
- Log$d.debug('Expected session id:', this.mainId);
42831
+ Log$e.debug('Expected session id:', this.mainId);
42579
42832
  }
42580
42833
  this.deviceAcquired = true;
42581
42834
  this.updateDescriptor({ [mainIdKey]: this.mainId });
@@ -42610,11 +42863,11 @@ class Device extends events.exports {
42610
42863
  (this.mainId && DataManager.isBleConnect(env))) {
42611
42864
  if (this.pendingCallbackPromise) {
42612
42865
  try {
42613
- Log$d.debug('Waiting for callback tasks to complete before releasing device (in release method)');
42866
+ Log$e.debug('Waiting for callback tasks to complete before releasing device (in release method)');
42614
42867
  yield this.pendingCallbackPromise.promise;
42615
42868
  }
42616
42869
  catch (error) {
42617
- Log$d.error('Error waiting for callback tasks in release method:', error);
42870
+ Log$e.error('Error waiting for callback tasks in release method:', error);
42618
42871
  }
42619
42872
  }
42620
42873
  if (this.commands) {
@@ -42633,7 +42886,7 @@ class Device extends events.exports {
42633
42886
  this.updateDescriptor({ session: null });
42634
42887
  }
42635
42888
  catch (err) {
42636
- Log$d.error('[Device] release error: ', err);
42889
+ Log$e.error('[Device] release error: ', err);
42637
42890
  }
42638
42891
  finally {
42639
42892
  this.needReloadDevice = true;
@@ -42808,7 +43061,7 @@ class Device extends events.exports {
42808
43061
  }
42809
43062
  getInternalState(_deviceId) {
42810
43063
  var _a;
42811
- Log$d.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.deviceId: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.deviceId}`, `passphraseState: ${this.passphraseState}`);
43064
+ Log$e.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.deviceId: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.deviceId}`, `passphraseState: ${this.passphraseState}`);
42812
43065
  const deviceId = this.getSessionCacheDeviceKey(_deviceId);
42813
43066
  if (!deviceId)
42814
43067
  return undefined;
@@ -42817,7 +43070,7 @@ class Device extends events.exports {
42817
43070
  return deviceWalletSessionStore.get(deviceId, this.passphraseState);
42818
43071
  }
42819
43072
  updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
42820
- Log$d.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `hasSessionId: ${Boolean(sessionId)}`, `hasFeaturesSessionId: ${Boolean(featuresSessionId)}`);
43073
+ Log$e.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `hasSessionId: ${Boolean(sessionId)}`, `hasFeaturesSessionId: ${Boolean(featuresSessionId)}`);
42821
43074
  const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
42822
43075
  if (!cacheDeviceKey)
42823
43076
  return;
@@ -42829,7 +43082,7 @@ class Device extends events.exports {
42829
43082
  }
42830
43083
  setInternalState(state, initSession) {
42831
43084
  var _a;
42832
- Log$d.debug('setInternalState session param: ', `hasState: ${Boolean(state)}`, `initSession: ${initSession}`, `deviceId: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.deviceId}`, `passphraseState: ${this.passphraseState}`);
43085
+ Log$e.debug('setInternalState session param: ', `hasState: ${Boolean(state)}`, `initSession: ${initSession}`, `deviceId: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.deviceId}`, `passphraseState: ${this.passphraseState}`);
42833
43086
  if (!this.passphraseState && !initSession)
42834
43087
  return;
42835
43088
  const deviceId = this.getSessionCacheDeviceKey();
@@ -42843,7 +43096,7 @@ class Device extends events.exports {
42843
43096
  }
42844
43097
  }
42845
43098
  clearInternalState(_deviceId) {
42846
- Log$d.debug('clearInternalState param: ', _deviceId);
43099
+ Log$e.debug('clearInternalState param: ', _deviceId);
42847
43100
  const deviceId = this.getSessionCacheDeviceKey(_deviceId);
42848
43101
  if (!deviceId)
42849
43102
  return;
@@ -42853,16 +43106,18 @@ class Device extends events.exports {
42853
43106
  }
42854
43107
  }
42855
43108
  initialize(options) {
43109
+ var _a;
42856
43110
  return __awaiter(this, void 0, void 0, function* () {
42857
43111
  if (this.isProtocolV2()) {
42858
43112
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
42859
- if (this.features && !this.featuresNeedsReload && !(options === null || options === void 0 ? void 0 : options.initSession)) {
42860
- if (this.features.bootloaderMode) {
43113
+ if (this.state && !(options === null || options === void 0 ? void 0 : options.initSession) && !this.protocolV2StateNeedsReload) {
43114
+ if ((_a = this.features) === null || _a === void 0 ? void 0 : _a.bootloaderMode) {
42861
43115
  return;
42862
43116
  }
42863
43117
  return;
42864
43118
  }
42865
43119
  yield this._initializeProtocolV2(options);
43120
+ this.protocolV2StateNeedsReload = false;
42866
43121
  return;
42867
43122
  }
42868
43123
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
@@ -42895,31 +43150,24 @@ class Device extends events.exports {
42895
43150
  yield TransportManager.reconfigure(this.features);
42896
43151
  }
42897
43152
  catch (error) {
42898
- Log$d.error('Initialization failed:', error);
43153
+ Log$e.error('Initialization failed:', error);
42899
43154
  throw error;
42900
43155
  }
42901
43156
  });
42902
43157
  }
42903
43158
  _initializeProtocolV2(options) {
42904
43159
  return __awaiter(this, void 0, void 0, function* () {
42905
- Log$d.debug('Initialize device via Protocol V2 features adapter');
43160
+ Log$e.debug('Initialize device via Protocol V2 features adapter');
42906
43161
  try {
42907
43162
  const deviceInfo = yield requestProtocolV2DeviceInfo({
42908
43163
  commands: this.commands,
42909
43164
  timeoutMs: options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs,
42910
43165
  });
42911
- const deviceStatus = yield requestProtocolV2DeviceStatus({
42912
- commands: this.commands,
42913
- }).catch(error => {
42914
- Log$d.debug('Protocol V2 status unavailable during initialization:', error);
42915
- return undefined;
42916
- });
42917
- const features = this.updateProtocolV2Features(deviceInfo, deviceStatus);
42918
- Log$d.debug('Protocol V2 features:', features);
42919
- this.featuresNeedsReload = false;
43166
+ const features = this.updateProtocolV2Features(deviceInfo, null);
43167
+ Log$e.debug('Protocol V2 features:', features);
42920
43168
  }
42921
43169
  catch (error) {
42922
- Log$d.error('Protocol V2 initialization failed:', error);
43170
+ Log$e.error('Protocol V2 initialization failed:', error);
42923
43171
  throw error;
42924
43172
  }
42925
43173
  });
@@ -42930,16 +43178,69 @@ class Device extends events.exports {
42930
43178
  const deviceInfo = yield requestProtocolV2DeviceInfo({
42931
43179
  commands: this.commands,
42932
43180
  });
42933
- const deviceStatus = yield requestProtocolV2DeviceStatus({
42934
- commands: this.commands,
42935
- }).catch(() => undefined);
42936
- return this.updateProtocolV2Features(deviceInfo, deviceStatus);
43181
+ return this.updateProtocolV2Features(deviceInfo, null);
42937
43182
  }
42938
43183
  const { message } = yield this.commands.typedCall('GetFeatures', 'Features', {});
42939
43184
  this._updateFeatures(message);
42940
43185
  return this.features;
42941
43186
  });
42942
43187
  }
43188
+ getDeviceState(params = {}) {
43189
+ var _a, _b, _c, _d;
43190
+ return __awaiter(this, void 0, void 0, function* () {
43191
+ const refresh = new Set((_a = params.refreshSections) !== null && _a !== void 0 ? _a : []);
43192
+ const getProtocolV2DeviceInfoRequest = () => {
43193
+ if (refresh.has('verification'))
43194
+ return PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
43195
+ if (refresh.has('versions'))
43196
+ return PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST;
43197
+ return PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST;
43198
+ };
43199
+ let initializedWithDeviceInfo = false;
43200
+ if (!this.state) {
43201
+ if (this.isProtocolV2()) {
43202
+ const deviceInfo = yield requestProtocolV2DeviceInfo({
43203
+ commands: this.commands,
43204
+ request: getProtocolV2DeviceInfoRequest(),
43205
+ });
43206
+ this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo), 'device-info');
43207
+ initializedWithDeviceInfo = true;
43208
+ }
43209
+ else {
43210
+ yield this.getFeatures();
43211
+ }
43212
+ }
43213
+ else if (!this.isProtocolV2() && refresh.size > 0) {
43214
+ yield this.getFeatures();
43215
+ }
43216
+ if (!this.isProtocolV2() && refresh.has('verification')) {
43217
+ const { message } = yield this.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
43218
+ this.updateState(mapProtocolV1OnekeyFeaturesToState(message), 'device-info');
43219
+ }
43220
+ if (this.isProtocolV2()) {
43221
+ const refreshDeviceInfo = refresh.has('identity') || refresh.has('versions') || refresh.has('verification');
43222
+ if (refreshDeviceInfo && !initializedWithDeviceInfo) {
43223
+ const deviceInfo = yield requestProtocolV2DeviceInfo({
43224
+ commands: this.commands,
43225
+ request: getProtocolV2DeviceInfoRequest(),
43226
+ });
43227
+ this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo, (_b = this.state) === null || _b === void 0 ? void 0 : _b.status.mode), 'device-info');
43228
+ }
43229
+ if (refresh.has('status') && ((_c = this.state) === null || _c === void 0 ? void 0 : _c.status.mode) === 'normal') {
43230
+ const status = yield requestProtocolV2DeviceStatus({ commands: this.commands });
43231
+ this.updateState(mapProtocolV2DeviceStatusToState(status), 'device-status');
43232
+ }
43233
+ if (refresh.has('settings') && ((_d = this.state) === null || _d === void 0 ? void 0 : _d.status.mode) === 'normal') {
43234
+ const { message } = yield this.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
43235
+ this.updateState(mapDeviceSettingsToState(message), 'apply-settings');
43236
+ }
43237
+ }
43238
+ if (!this.state) {
43239
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed);
43240
+ }
43241
+ return params.includeRaw ? structuredClone(this.state) : createPublicDeviceState(this.state);
43242
+ });
43243
+ }
42943
43244
  _updateFeatures(protoFeatures, initSession) {
42944
43245
  var _a, _b;
42945
43246
  const previousCacheDeviceKey = this.getSessionCacheDeviceKey();
@@ -42951,7 +43252,7 @@ class Device extends events.exports {
42951
43252
  }
42952
43253
  feat.unlocked = (_b = feat.unlocked) !== null && _b !== void 0 ? _b : true;
42953
43254
  feat = fixFeaturesFirmwareVersion(feat);
42954
- this.features = feat;
43255
+ this.updateState(mapFeaturesToState(feat), 'initialize');
42955
43256
  const nextCacheDeviceKey = this.getSessionCacheDeviceKey();
42956
43257
  if (previousCacheDeviceKey && nextCacheDeviceKey) {
42957
43258
  deviceWalletSessionStore.migrateDeviceKey(previousCacheDeviceKey, nextCacheDeviceKey);
@@ -42959,35 +43260,118 @@ class Device extends events.exports {
42959
43260
  if (feat.deviceId && feat.sessionId) {
42960
43261
  this.setInternalState(feat.sessionId, initSession);
42961
43262
  }
42962
- this.featuresNeedsReload = false;
42963
- this.emit(DEVICE.FEATURES, this, feat);
43263
+ }
43264
+ updateState(patch, source) {
43265
+ var _a;
43266
+ const result = this.stateStore.update(patch, source);
43267
+ if (result.changedKeys.length === 0)
43268
+ return result.state;
43269
+ const event = {
43270
+ connectId: (_a = this.getConnectId()) !== null && _a !== void 0 ? _a : null,
43271
+ state: createPublicDeviceState(result.state),
43272
+ revision: result.revision,
43273
+ source,
43274
+ changedKeys: result.changedKeys,
43275
+ };
43276
+ Log$e.debug('Device state patch committed', {
43277
+ source,
43278
+ keys: result.changedKeys,
43279
+ });
43280
+ this.emit(DEVICE.STATE, this, event);
43281
+ if (result.state.protocol === 'V1') {
43282
+ this.emit(DEVICE.FEATURES, this, projectFeatures(result.state));
43283
+ }
43284
+ return result.state;
43285
+ }
43286
+ clearCachedSession(deviceId, passphraseState) {
43287
+ const current = this.state;
43288
+ if (!(current === null || current === void 0 ? void 0 : current.session))
43289
+ return false;
43290
+ if (deviceId && current.identity.deviceId !== deviceId)
43291
+ return false;
43292
+ if (passphraseState && current.session.passphraseState !== passphraseState)
43293
+ return false;
43294
+ return this.stateStore.clearSession('session-clear') !== undefined;
43295
+ }
43296
+ updateFeaturesPatch(patch, source) {
43297
+ const currentFeatures = this.features;
43298
+ if (!currentFeatures)
43299
+ return undefined;
43300
+ const features = mergeDeviceFeaturesPatch(currentFeatures, patch);
43301
+ if (features === currentFeatures)
43302
+ return currentFeatures;
43303
+ const normalized = fixFeaturesFirmwareVersion(features);
43304
+ this.updateState(mapFeaturesToState(normalized), source);
43305
+ return this.features;
42964
43306
  }
42965
43307
  updateProtocolV2Features(deviceInfo, deviceStatus) {
42966
- var _a, _b;
43308
+ var _a;
42967
43309
  const previousCacheDeviceKey = this.getSessionCacheDeviceKey();
42968
- const resolvedDeviceStatus = deviceStatus === undefined
42969
- ? (_b = (_a = this.features) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2DeviceStatus
42970
- : deviceStatus !== null && deviceStatus !== void 0 ? deviceStatus : undefined;
42971
- const features = fixFeaturesFirmwareVersion(buildProtocolV2FeaturesPayload({
42972
- deviceInfo,
42973
- deviceStatus: resolvedDeviceStatus,
42974
- previous: this.features,
42975
- }));
42976
- this.features = features;
43310
+ if (deviceStatus) {
43311
+ this.updateState(mapProtocolV2DeviceStatusToState(deviceStatus), 'device-status');
43312
+ }
43313
+ if (deviceInfo) {
43314
+ this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo, (_a = this.state) === null || _a === void 0 ? void 0 : _a.status.mode), 'device-info');
43315
+ }
42977
43316
  const nextCacheDeviceKey = this.getSessionCacheDeviceKey();
42978
43317
  if (previousCacheDeviceKey && nextCacheDeviceKey) {
42979
43318
  deviceWalletSessionStore.migrateDeviceKey(previousCacheDeviceKey, nextCacheDeviceKey);
42980
43319
  }
42981
- this.featuresNeedsReload = false;
42982
- this.emit(DEVICE.FEATURES, this, features);
42983
- return features;
43320
+ return this.features;
42984
43321
  }
42985
43322
  updateProtocolV2Status(status) {
42986
43323
  var _a, _b, _c, _d;
42987
- const previousDeviceInfo = (_b = (_a = this.features) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2DeviceInfo;
42988
- const previousStatus = (_d = (_c = this.features) === null || _c === void 0 ? void 0 : _c.raw) === null || _d === void 0 ? void 0 : _d.protocolV2DeviceStatus;
43324
+ const previousDeviceInfo = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2DeviceInfo;
43325
+ const previousStatus = (_d = (_c = this.state) === null || _c === void 0 ? void 0 : _c.raw) === null || _d === void 0 ? void 0 : _d.protocolV2DeviceStatus;
42989
43326
  return this.updateProtocolV2Features(previousDeviceInfo, Object.assign(Object.assign({}, previousStatus), status));
42990
43327
  }
43328
+ markTransportDisconnected() {
43329
+ if (!this.isProtocolV2())
43330
+ return;
43331
+ this.protocolV2StateNeedsReload = true;
43332
+ this.clearPreInitialized();
43333
+ this.clearCachedSession();
43334
+ }
43335
+ markProtocolV2Reboot(rebootType) {
43336
+ if (!this.isProtocolV2())
43337
+ return;
43338
+ this.protocolV2StateNeedsReload = true;
43339
+ this.clearPreInitialized();
43340
+ let loaderMode;
43341
+ if (rebootType === hdTransport.DeviceRebootType.Bootloader) {
43342
+ loaderMode = 'bootloader';
43343
+ }
43344
+ else if (rebootType === hdTransport.DeviceRebootType.Romloader) {
43345
+ loaderMode = 'romloader';
43346
+ }
43347
+ if (loaderMode) {
43348
+ this.updateState({
43349
+ identity: { deviceId: null },
43350
+ status: {
43351
+ mode: loaderMode,
43352
+ initialized: null,
43353
+ unlocked: null,
43354
+ firmwarePresent: null,
43355
+ backupRequired: null,
43356
+ noBackup: null,
43357
+ unfinishedBackup: null,
43358
+ recoveryMode: null,
43359
+ passphraseProtection: null,
43360
+ pinProtection: null,
43361
+ attachToPinEnabled: null,
43362
+ unlockedAttachPin: null,
43363
+ },
43364
+ session: null,
43365
+ raw: { protocolV2DeviceStatus: null },
43366
+ }, 'transport-reconnect');
43367
+ return;
43368
+ }
43369
+ this.updateState({
43370
+ status: { mode: 'normal', unlocked: null },
43371
+ session: null,
43372
+ raw: { protocolV2DeviceStatus: null },
43373
+ }, 'transport-reconnect');
43374
+ }
42991
43375
  updateDescriptor(descriptor, forceUpdate = false) {
42992
43376
  var _a;
42993
43377
  const env = DataManager.getSettings('env');
@@ -43015,7 +43399,7 @@ class Device extends events.exports {
43015
43399
  return __awaiter(this, void 0, void 0, function* () {
43016
43400
  if (this.runPromise) {
43017
43401
  yield this.interruptionFromOutside();
43018
- Log$d.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
43402
+ Log$e.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
43019
43403
  }
43020
43404
  options = parseRunOptions(options);
43021
43405
  this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
@@ -43043,6 +43427,7 @@ class Device extends events.exports {
43043
43427
  }
43044
43428
  }
43045
43429
  catch (error) {
43430
+ yield this.release();
43046
43431
  this.runPromise = null;
43047
43432
  if (error instanceof hdShared.HardwareError) {
43048
43433
  return Promise.reject(error);
@@ -43073,7 +43458,7 @@ class Device extends events.exports {
43073
43458
  yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.disconnect(this.mainId));
43074
43459
  }
43075
43460
  yield this.release();
43076
- Log$d.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
43461
+ Log$e.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
43077
43462
  }
43078
43463
  this.runPromise = null;
43079
43464
  return;
@@ -43083,7 +43468,7 @@ class Device extends events.exports {
43083
43468
  options.keepSession === false) {
43084
43469
  this.keepSession = false;
43085
43470
  yield this.release();
43086
- Log$d.debug('release device, mainId: ', this.mainId);
43471
+ Log$e.debug('release device, mainId: ', this.mainId);
43087
43472
  }
43088
43473
  if (this.runPromise) {
43089
43474
  this.runPromise.resolve();
@@ -43116,7 +43501,7 @@ class Device extends events.exports {
43116
43501
  setCancelableAction(callback) {
43117
43502
  this.cancelableAction = (e) => callback(e)
43118
43503
  .catch(e2 => {
43119
- Log$d.debug('cancelableAction error', e2);
43504
+ Log$e.debug('cancelableAction error', e2);
43120
43505
  })
43121
43506
  .finally(() => {
43122
43507
  this.clearCancelableAction();
@@ -43126,16 +43511,24 @@ class Device extends events.exports {
43126
43511
  this.cancelableAction = undefined;
43127
43512
  }
43128
43513
  getMode() {
43129
- var _a, _b, _c;
43130
- if ((_a = this.features) === null || _a === void 0 ? void 0 : _a.bootloaderMode) {
43514
+ var _a, _b, _c, _d;
43515
+ switch ((_a = this.state) === null || _a === void 0 ? void 0 : _a.status.mode) {
43516
+ case 'bootloader':
43517
+ case 'romloader':
43518
+ return exports.EOneKeyDeviceMode.bootloader;
43519
+ case 'notInitialized':
43520
+ return exports.EOneKeyDeviceMode.notInitialized;
43521
+ case 'backupMode':
43522
+ return exports.EOneKeyDeviceMode.backupMode;
43523
+ case 'normal':
43524
+ return exports.EOneKeyDeviceMode.normal;
43525
+ }
43526
+ if ((_b = this.features) === null || _b === void 0 ? void 0 : _b.bootloaderMode)
43131
43527
  return exports.EOneKeyDeviceMode.bootloader;
43132
- }
43133
- if (!((_b = this.features) === null || _b === void 0 ? void 0 : _b.initialized)) {
43528
+ if (((_c = this.features) === null || _c === void 0 ? void 0 : _c.initialized) === false)
43134
43529
  return exports.EOneKeyDeviceMode.notInitialized;
43135
- }
43136
- if ((_c = this.features) === null || _c === void 0 ? void 0 : _c.noBackup) {
43530
+ if ((_d = this.features) === null || _d === void 0 ? void 0 : _d.noBackup)
43137
43531
  return exports.EOneKeyDeviceMode.backupMode;
43138
- }
43139
43532
  return exports.EOneKeyDeviceMode.normal;
43140
43533
  }
43141
43534
  getFirmwareVersion() {
@@ -43214,6 +43607,7 @@ class Device extends events.exports {
43214
43607
  lockDevice() {
43215
43608
  return __awaiter(this, void 0, void 0, function* () {
43216
43609
  const res = yield this.commands.typedCall('LockDevice', 'Success', {});
43610
+ this.updateState({ status: { unlocked: false } }, 'lock');
43217
43611
  return res.message;
43218
43612
  });
43219
43613
  }
@@ -43242,8 +43636,7 @@ class Device extends events.exports {
43242
43636
  }
43243
43637
  throw error;
43244
43638
  }
43245
- const { message: status } = yield this.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
43246
- return this.updateProtocolV2Status(status);
43639
+ return this.updateFeaturesPatch({ unlocked: true }, 'unlock');
43247
43640
  }
43248
43641
  const firmwareVersion = (_c = this.getCurrentFirmwareVersionString()) !== null && _c !== void 0 ? _c : '0.0.0';
43249
43642
  const versionRange = this.getCurrentMethodVersionRange(type => this.supportUnlockVersionRange()[type]);
@@ -43255,11 +43648,15 @@ class Device extends events.exports {
43255
43648
  if (supportUnlock) {
43256
43649
  const res = yield this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
43257
43650
  if (this.features) {
43258
- this.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
43259
- this.features.unlockedAttachPin =
43260
- res.message.unlocked_attach_pin == null ? undefined : res.message.unlocked_attach_pin;
43261
- this.features.passphraseProtection =
43262
- res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
43651
+ this.updateState({
43652
+ status: {
43653
+ unlocked: res.message.unlocked == null ? null : res.message.unlocked,
43654
+ unlockedAttachPin: res.message.unlocked_attach_pin == null ? null : res.message.unlocked_attach_pin,
43655
+ passphraseProtection: res.message.passphrase_protection == null
43656
+ ? null
43657
+ : res.message.passphrase_protection,
43658
+ },
43659
+ }, 'unlock');
43263
43660
  return Promise.resolve(this.features);
43264
43661
  }
43265
43662
  const features = yield this.getFeatures();
@@ -43289,7 +43686,7 @@ class Device extends events.exports {
43289
43686
  const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
43290
43687
  const useErrorAttachPin = unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
43291
43688
  const passphraseStateMismatch = !!passphraseState && passphraseState !== newPassphraseState;
43292
- Log$d.debug('Check passphrase state safety: ', {
43689
+ Log$e.debug('Check passphrase state safety: ', {
43293
43690
  passphraseState,
43294
43691
  newPassphraseState,
43295
43692
  unlockedAttachPin,
@@ -43320,6 +43717,15 @@ class Device extends events.exports {
43320
43717
  }
43321
43718
  }
43322
43719
 
43720
+ function checkLiveDeviceId(device, expectedDeviceId) {
43721
+ return __awaiter(this, void 0, void 0, function* () {
43722
+ if (device.isProtocolV2()) {
43723
+ yield device.getDeviceState({ refreshSections: ['status'] });
43724
+ }
43725
+ return device.checkDeviceId(expectedDeviceId);
43726
+ });
43727
+ }
43728
+
43323
43729
  class DeviceList extends events.exports {
43324
43730
  constructor() {
43325
43731
  super(...arguments);
@@ -43417,7 +43823,7 @@ const getBootloaderReleaseInfo = ({ features, willUpdateFirmwareVersion, firmwar
43417
43823
  };
43418
43824
  };
43419
43825
 
43420
- const Log$c = getLogger(exports.LoggerNames.Method);
43826
+ const Log$d = getLogger(exports.LoggerNames.Method);
43421
43827
  const isEvmLedgerLegacyPathWithHighIndex = (path) => {
43422
43828
  let addressN;
43423
43829
  if (typeof path === 'string') {
@@ -43491,7 +43897,7 @@ class BaseMethod {
43491
43897
  setContext(context) {
43492
43898
  this.sdkInstanceId = context.sdkInstanceId;
43493
43899
  this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
43494
- Log$c.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
43900
+ Log$d.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
43495
43901
  }
43496
43902
  setDevice(device) {
43497
43903
  var _a, _b;
@@ -43511,7 +43917,7 @@ class BaseMethod {
43511
43917
  if (device.commands) {
43512
43918
  device.commands.currentResponseID = this.responseID;
43513
43919
  }
43514
- Log$c.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
43920
+ Log$d.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
43515
43921
  }
43516
43922
  checkFirmwareRelease() {
43517
43923
  if (!this.device || this.device.isProtocolV2())
@@ -43589,7 +43995,7 @@ class BaseMethod {
43589
43995
  checkFlag = true;
43590
43996
  }
43591
43997
  if (checkFlag && this.device.getCurrentSafetyChecks() === 'Strict') {
43592
- Log$c.debug('will change safety_checks level');
43998
+ Log$d.debug('will change safety_checks level');
43593
43999
  yield this.device.commands.typedCall('ApplySettings', 'Success', {
43594
44000
  safety_checks: 'PromptTemporarily',
43595
44001
  });
@@ -43623,7 +44029,7 @@ class TestInitializeDeviceDuration extends BaseMethod {
43623
44029
  }
43624
44030
  }
43625
44031
 
43626
- const Log$b = getLogger(exports.LoggerNames.Core);
44032
+ const Log$c = getLogger(exports.LoggerNames.Core);
43627
44033
  const parseInitOptions$1 = (payload) => ({
43628
44034
  initSession: payload === null || payload === void 0 ? void 0 : payload.initSession,
43629
44035
  passphraseState: payload === null || payload === void 0 ? void 0 : payload.passphraseState,
@@ -43646,13 +44052,14 @@ class PreInitialize extends BaseMethod {
43646
44052
  }
43647
44053
  catch (_a) {
43648
44054
  this.device.clearPreInitialized();
43649
- Log$b.debug('[PRE-INIT][FAILED]');
44055
+ Log$c.debug('[PRE-INIT][FAILED]');
43650
44056
  return false;
43651
44057
  }
43652
44058
  });
43653
44059
  }
43654
44060
  }
43655
44061
 
44062
+ const Log$b = getLogger(exports.LoggerNames.DevicePool);
43656
44063
  class SearchDevices extends BaseMethod {
43657
44064
  init() {
43658
44065
  this.useDevice = false;
@@ -43679,9 +44086,22 @@ class SearchDevices extends BaseMethod {
43679
44086
  }
43680
44087
  return devices;
43681
44088
  }
43682
- const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, undefined, {
43683
- connectProtocol: this.payload.connectProtocol,
43684
- });
44089
+ const deviceList = [];
44090
+ for (const descriptor of devicesDescriptor) {
44091
+ try {
44092
+ const result = yield DevicePool.getDevices([descriptor], descriptor.path, {
44093
+ connectProtocol: this.payload.connectProtocol,
44094
+ refreshRuntimeState: true,
44095
+ });
44096
+ deviceList.push(...result.deviceList);
44097
+ }
44098
+ catch (error) {
44099
+ const errorCode = error && typeof error === 'object' && 'errorCode' in error
44100
+ ? error.errorCode
44101
+ : undefined;
44102
+ Log$b.debug('Skip unavailable device during search', Object.assign({ path: descriptor.path }, (errorCode !== undefined ? { errorCode } : {})));
44103
+ }
44104
+ }
43685
44105
  return deviceList.map(device => device.toMessageObject());
43686
44106
  });
43687
44107
  }
@@ -43689,6 +44109,7 @@ class SearchDevices extends BaseMethod {
43689
44109
 
43690
44110
  class GetFeatures extends BaseMethod {
43691
44111
  init() {
44112
+ this.unlockPolicy = 'none';
43692
44113
  this.allowDeviceMode = [
43693
44114
  ...this.allowDeviceMode,
43694
44115
  UI_REQUEST.NOT_INITIALIZE,
@@ -43704,207 +44125,62 @@ class GetFeatures extends BaseMethod {
43704
44125
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceDetectInBootloaderMode));
43705
44126
  }
43706
44127
  if (this.device.isProtocolV2()) {
43707
- return this.device.getFeatures();
44128
+ throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
43708
44129
  }
43709
- return Promise.resolve(this.device.features);
44130
+ const state = yield this.device.getDeviceState({
44131
+ includeRaw: true,
44132
+ });
44133
+ return projectFeatures(state);
43710
44134
  });
43711
44135
  }
43712
44136
  }
43713
44137
 
43714
- const ProtocolV2FirmwareTargetType = {
43715
- FW_MGMT_TARGET_INVALID: 0,
43716
- FW_MGMT_TARGET_CRATE: 1,
43717
- FW_MGMT_TARGET_ROMLOADER: 2,
43718
- FW_MGMT_TARGET_BOOTLOADER: 3,
43719
- FW_MGMT_TARGET_APPLICATION_P1: 4,
43720
- FW_MGMT_TARGET_APPLICATION_P2: 5,
43721
- FW_MGMT_TARGET_COPROCESSOR: 6,
43722
- FW_MGMT_TARGET_SE01: 7,
43723
- FW_MGMT_TARGET_SE02: 8,
43724
- FW_MGMT_TARGET_SE03: 9,
43725
- FW_MGMT_TARGET_SE04: 10,
44138
+ const SCOPE_SECTIONS = {
44139
+ runtime: ['status'],
44140
+ settings: ['status', 'settings'],
44141
+ firmware: ['status', 'identity', 'versions', 'verification'],
43726
44142
  };
43727
-
43728
- const DEVICE_INFO_SCOPES = ['basic', 'versions', 'verify', 'full'];
43729
- function isDeviceInfoScope(scope) {
43730
- return typeof scope === 'string' && DEVICE_INFO_SCOPES.includes(scope);
43731
- }
43732
- function normalizeScope(scope) {
43733
- if (scope === undefined || scope === null)
43734
- return 'basic';
43735
- if (isDeviceInfoScope(scope)) {
43736
- return scope;
43737
- }
43738
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid getDeviceInfo scope: ${String(scope)}`);
43739
- }
43740
- function resolveProtocolV2DeviceInfoRequest(params) {
43741
- if (params.scope === 'verify' || params.scope === 'full') {
43742
- return PROTOCOL_V2_DEVICE_INFO_REQUEST;
43743
- }
43744
- if (params.scope === 'versions') {
43745
- return PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST;
43746
- }
43747
- return PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST;
43748
- }
43749
- function shouldReadOnekeyFeatures(params) {
43750
- return (params.includeRaw === true ||
43751
- params.scope === 'versions' ||
43752
- params.scope === 'verify' ||
43753
- params.scope === 'full');
43754
- }
43755
- function supportOnekeyFeatures(features) {
43756
- if (!features || features.bootloaderMode)
43757
- return false;
43758
- const deviceType = getDeviceType(features);
43759
- return ![
43760
- hdShared.EDeviceType.Unknown,
43761
- hdShared.EDeviceType.Classic1s,
43762
- hdShared.EDeviceType.ClassicPure,
43763
- hdShared.EDeviceType.Pro2,
43764
- ].includes(deviceType);
43765
- }
43766
- function normalizeOnekeyFeatures(message) {
43767
- if (message.onekey_firmware_version && !semver__default["default"].valid(message.onekey_firmware_version)) {
43768
- message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
43769
- }
43770
- return message;
43771
- }
43772
- class GetDeviceInfo extends BaseMethod {
44143
+ const isLoaderMode = (mode) => mode === 'bootloader' || mode === 'romloader';
44144
+ class GetDeviceState extends BaseMethod {
43773
44145
  init() {
44146
+ var _a;
44147
+ const scope = ((_a = this.payload.scope) !== null && _a !== void 0 ? _a : 'runtime');
44148
+ if (!Object.prototype.hasOwnProperty.call(SCOPE_SECTIONS, scope)) {
44149
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Unsupported device state scope: ${String(scope)}`);
44150
+ }
43774
44151
  this.allowDeviceMode = [
43775
44152
  ...this.allowDeviceMode,
43776
44153
  UI_REQUEST.NOT_INITIALIZE,
43777
44154
  UI_REQUEST.BOOTLOADER,
43778
44155
  ];
44156
+ this.unlockPolicy = 'none';
43779
44157
  this.useDevicePassphraseState = false;
43780
44158
  this.skipForceUpdateCheck = true;
43781
- this.params = {
43782
- scope: normalizeScope(this.payload.scope),
43783
- refresh: this.payload.refresh,
43784
- includeRaw: this.payload.includeRaw,
43785
- };
44159
+ this.params = { scope };
43786
44160
  }
43787
44161
  run() {
43788
44162
  return __awaiter(this, void 0, void 0, function* () {
43789
- if (this.device.isProtocolV2()) {
43790
- return this.runProtocolV2();
43791
- }
43792
- return this.runProtocolV1();
43793
- });
43794
- }
43795
- runProtocolV2() {
43796
- return __awaiter(this, void 0, void 0, function* () {
43797
- const sources = ['deviceInfo'];
43798
- const protocolV2DeviceInfo = yield requestProtocolV2DeviceInfo({
43799
- commands: this.device.commands,
43800
- request: resolveProtocolV2DeviceInfoRequest(this.params),
43801
- });
43802
- const protocolV2DeviceStatus = yield requestProtocolV2DeviceStatus({
43803
- commands: this.device.commands,
43804
- }).catch(() => undefined);
43805
- const profile = buildProfileFromProtocolV2({
43806
- deviceInfo: protocolV2DeviceInfo,
43807
- deviceStatus: protocolV2DeviceStatus,
43808
- sources,
43809
- scope: this.params.scope,
43810
- includeRaw: this.params.includeRaw,
44163
+ const state = yield this.device.getDeviceState({
44164
+ refreshSections: SCOPE_SECTIONS[this.params.scope],
43811
44165
  });
43812
- this.device.updateProtocolV2Features(protocolV2DeviceInfo, protocolV2DeviceStatus);
43813
- return profile;
44166
+ if (this.params.scope === 'settings' &&
44167
+ this.device.isProtocolV2() &&
44168
+ isLoaderMode(state.status.mode)) {
44169
+ throw hdShared.createDeviceNotSupportMethodError(`${this.name}:${this.params.scope}`, this.device.getCurrentFirmwareType());
44170
+ }
44171
+ return state;
43814
44172
  });
43815
44173
  }
43816
- runProtocolV1() {
43817
- return __awaiter(this, void 0, void 0, function* () {
43818
- if (this.params.refresh === true) {
43819
- yield this.device.getFeatures();
43820
- }
43821
- const sources = ['features'];
43822
- const { features } = this.device;
43823
- let protocolV1OneKeyFeatures;
43824
- if (shouldReadOnekeyFeatures(this.params) && supportOnekeyFeatures(features)) {
43825
- const { message } = yield this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
43826
- protocolV1OneKeyFeatures = normalizeOnekeyFeatures(message);
43827
- sources.push('protocolV1OneKeyFeatures');
43828
- }
43829
- const profile = buildProfileFromProtocolV1({
43830
- protocol: 'V1',
43831
- features,
43832
- protocolV1OneKeyFeatures,
43833
- sources,
43834
- scope: this.params.scope,
43835
- includeRaw: this.params.includeRaw,
43836
- });
43837
- return profile;
43838
- });
43839
- }
43840
- }
43841
-
43842
- const ONEKEY_FEATURE_KEYS = [
43843
- 'onekey_device_type',
43844
- 'onekey_board_version',
43845
- 'onekey_boot_version',
43846
- 'onekey_firmware_version',
43847
- 'onekey_board_hash',
43848
- 'onekey_boot_hash',
43849
- 'onekey_firmware_hash',
43850
- 'onekey_board_build_id',
43851
- 'onekey_boot_build_id',
43852
- 'onekey_firmware_build_id',
43853
- 'onekey_serial_no',
43854
- 'onekey_ble_name',
43855
- 'onekey_ble_version',
43856
- 'onekey_ble_build_id',
43857
- 'onekey_ble_hash',
43858
- 'onekey_se_type',
43859
- 'onekey_se01_state',
43860
- 'onekey_se02_state',
43861
- 'onekey_se03_state',
43862
- 'onekey_se04_state',
43863
- 'onekey_se01_version',
43864
- 'onekey_se02_version',
43865
- 'onekey_se03_version',
43866
- 'onekey_se04_version',
43867
- 'onekey_se01_hash',
43868
- 'onekey_se02_hash',
43869
- 'onekey_se03_hash',
43870
- 'onekey_se04_hash',
43871
- 'onekey_se01_build_id',
43872
- 'onekey_se02_build_id',
43873
- 'onekey_se03_build_id',
43874
- 'onekey_se04_build_id',
43875
- 'onekey_se01_boot_version',
43876
- 'onekey_se02_boot_version',
43877
- 'onekey_se03_boot_version',
43878
- 'onekey_se04_boot_version',
43879
- 'onekey_se01_boot_hash',
43880
- 'onekey_se02_boot_hash',
43881
- 'onekey_se03_boot_hash',
43882
- 'onekey_se04_boot_hash',
43883
- 'onekey_se01_boot_build_id',
43884
- 'onekey_se02_boot_build_id',
43885
- 'onekey_se03_boot_build_id',
43886
- 'onekey_se04_boot_build_id',
43887
- ];
44174
+ }
44175
+
43888
44176
  function normalizeOnekeyFirmwareVersion(message) {
43889
44177
  if (message.onekey_firmware_version && !semver__default["default"].valid(message.onekey_firmware_version)) {
43890
44178
  message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
43891
44179
  }
43892
44180
  }
43893
- function pickOnekeyFeatures(features) {
43894
- const message = {};
43895
- if (!features)
43896
- return message;
43897
- for (const key of ONEKEY_FEATURE_KEYS) {
43898
- const value = features[key];
43899
- if (value !== undefined && value !== null) {
43900
- message[key] = value;
43901
- }
43902
- }
43903
- normalizeOnekeyFirmwareVersion(message);
43904
- return message;
43905
- }
43906
44181
  class GetOnekeyFeatures extends BaseMethod {
43907
44182
  init() {
44183
+ this.unlockPolicy = 'none';
43908
44184
  this.allowDeviceMode = [
43909
44185
  ...this.allowDeviceMode,
43910
44186
  UI_REQUEST.NOT_INITIALIZE,
@@ -43916,12 +44192,7 @@ class GetOnekeyFeatures extends BaseMethod {
43916
44192
  run() {
43917
44193
  return __awaiter(this, void 0, void 0, function* () {
43918
44194
  if (this.device.isProtocolV2()) {
43919
- const deviceInfo = yield requestProtocolV2DeviceInfo({
43920
- commands: this.device.commands,
43921
- request: PROTOCOL_V2_DEVICE_INFO_REQUEST,
43922
- });
43923
- const features = this.device.updateProtocolV2Features(deviceInfo);
43924
- return pickOnekeyFeatures(features);
44195
+ throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
43925
44196
  }
43926
44197
  const { message } = yield this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
43927
44198
  normalizeOnekeyFirmwareVersion(message);
@@ -43945,7 +44216,7 @@ class GetPassphraseState extends BaseMethod {
43945
44216
  const passphraseProtection = this.device.getCurrentPassphraseProtection();
43946
44217
  const deviceType = this.device.getCurrentDeviceType();
43947
44218
  if (deviceType === hdShared.EDeviceType.Pro2) {
43948
- return Promise.resolve(passphraseProtection === true ? passphraseState : undefined);
44219
+ return Promise.resolve(passphraseState);
43949
44220
  }
43950
44221
  return Promise.resolve(deviceType === hdShared.EDeviceType.Pro || passphraseProtection === true ? passphraseState : undefined);
43951
44222
  });
@@ -43999,6 +44270,9 @@ class ClearSessionCache extends BaseMethod {
43999
44270
  else {
44000
44271
  deviceWalletSessionStore.delete(deviceId, passphraseState);
44001
44272
  }
44273
+ Object.values(DevicePool.devicesCache).forEach(device => {
44274
+ device.clearCachedSession(deviceId, passphraseState);
44275
+ });
44002
44276
  return Promise.resolve({ cleared: true });
44003
44277
  }
44004
44278
  }
@@ -44558,6 +44832,7 @@ class DeviceRebootToBootloader extends BaseMethod {
44558
44832
  const res = yield this.device.commands.typedCall('DeviceReboot', 'Success', {
44559
44833
  reboot_type: hdTransport.DeviceRebootType.Bootloader,
44560
44834
  });
44835
+ this.device.markProtocolV2Reboot(hdTransport.DeviceRebootType.Bootloader);
44561
44836
  return Promise.resolve(res.message);
44562
44837
  }
44563
44838
  const res = yield this.device.commands.typedCall('RebootToBootloader', 'Success');
@@ -44587,6 +44862,7 @@ class DeviceRebootToBoardloader extends BaseMethod {
44587
44862
  const res = yield this.device.commands.typedCall('DeviceReboot', 'Success', {
44588
44863
  reboot_type: hdTransport.DeviceRebootType.Romloader,
44589
44864
  });
44865
+ this.device.markProtocolV2Reboot(hdTransport.DeviceRebootType.Romloader);
44590
44866
  return Promise.resolve(res.message);
44591
44867
  }
44592
44868
  const res = yield this.device.commands.typedCall('BixinOutMessageSE', 'Success');
@@ -44681,7 +44957,15 @@ class DeviceSettings extends BaseMethod {
44681
44957
  { name: 'experimentalFeatures', type: 'boolean' },
44682
44958
  { name: 'autoShutdownDelayMs', type: 'number' },
44683
44959
  { name: 'changeBrightness', type: 'boolean' },
44960
+ { name: 'brightness', type: 'number' },
44684
44961
  { name: 'hapticFeedback', type: 'boolean' },
44962
+ { name: 'bluetoothEnabled', type: 'boolean' },
44963
+ { name: 'animationEnabled', type: 'boolean' },
44964
+ { name: 'tapToWake', type: 'boolean' },
44965
+ { name: 'deviceNameDisplayEnabled', type: 'boolean' },
44966
+ { name: 'fidoEnabled', type: 'boolean' },
44967
+ { name: 'usbLockEnabled', type: 'boolean' },
44968
+ { name: 'randomKeypad', type: 'boolean' },
44685
44969
  ]);
44686
44970
  this.params = Object.assign(Object.assign({ language: this.payload.language, label: this.payload.label, use_passphrase: this.payload.usePassphrase, homescreen: this.payload.homescreen, _passphrase_source: this.payload.passphraseSource, auto_lock_delay_ms: this.payload.autoLockDelayMs, display_rotation: this.payload.displayRotation, passphrase_always_on_device: this.payload.passphraseAlwaysOnDevice, safety_checks: this.payload.safetyChecks, experimental_features: this.payload.experimentalFeatures, auto_shutdown_delay_ms: this.payload.autoShutdownDelayMs }, (this.payload.changeBrightness
44687
44971
  ? { change_brightness: this.payload.changeBrightness }
@@ -44701,7 +44985,19 @@ class DeviceSettings extends BaseMethod {
44701
44985
  var _a, _b, _c, _d, _e;
44702
44986
  return __awaiter(this, void 0, void 0, function* () {
44703
44987
  try {
44988
+ if (this.device.isProtocolV2()) {
44989
+ const settings = mapCommonSettingsToProtocolV2(this.payload);
44990
+ if (Object.keys(settings).length === 0) {
44991
+ throw invalidParameter('No Protocol V2 compatible setting provided.');
44992
+ }
44993
+ const res = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
44994
+ settings,
44995
+ });
44996
+ this.device.updateState(mapDeviceSettingsToState(settings), 'apply-settings');
44997
+ return res.message;
44998
+ }
44704
44999
  const res = yield this.device.commands.typedCall('ApplySettings', 'Success', Object.assign({}, this.params));
45000
+ this.device.updateState(mapApplySettingsToState(this.params), 'apply-settings');
44705
45001
  return res.message;
44706
45002
  }
44707
45003
  catch (error) {
@@ -46847,6 +47143,20 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
46847
47143
  }
46848
47144
  }
46849
47145
 
47146
+ const ProtocolV2FirmwareTargetType = {
47147
+ FW_MGMT_TARGET_INVALID: 0,
47148
+ FW_MGMT_TARGET_CRATE: 1,
47149
+ FW_MGMT_TARGET_ROMLOADER: 2,
47150
+ FW_MGMT_TARGET_BOOTLOADER: 3,
47151
+ FW_MGMT_TARGET_APPLICATION_P1: 4,
47152
+ FW_MGMT_TARGET_APPLICATION_P2: 5,
47153
+ FW_MGMT_TARGET_COPROCESSOR: 6,
47154
+ FW_MGMT_TARGET_SE01: 7,
47155
+ FW_MGMT_TARGET_SE02: 8,
47156
+ FW_MGMT_TARGET_SE03: 9,
47157
+ FW_MGMT_TARGET_SE04: 10,
47158
+ };
47159
+
46850
47160
  const DEVICE_REBOOT_TYPES = {
46851
47161
  Normal: hdTransport.DeviceRebootType.Normal,
46852
47162
  normal: hdTransport.DeviceRebootType.Normal,
@@ -47604,9 +47914,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
47604
47914
  return !!((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.bootloaderMode);
47605
47915
  }
47606
47916
  enterProtocolV2BootloaderMode() {
47917
+ var _a;
47607
47918
  return __awaiter(this, void 0, void 0, function* () {
47608
- if (this.isProtocolV2BootloaderMode()) {
47609
- Log$5.debug('Protocol V2 device is already in bootloader mode, skip reboot to bootloader');
47919
+ if (this.isProtocolV2BootloaderMode() || ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.mode) === 'romloader') {
47920
+ Log$5.debug('Protocol V2 device is already in loader mode, skip reboot to bootloader');
47610
47921
  return false;
47611
47922
  }
47612
47923
  try {
@@ -47762,12 +48073,15 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
47762
48073
  var _a;
47763
48074
  return __awaiter(this, void 0, void 0, function* () {
47764
48075
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
47765
- const { message: deviceStatus } = yield typedCall('DeviceStatusGet', 'DeviceStatus', {}, { timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT });
47766
48076
  const deviceInfo = yield requestProtocolV2DeviceInfo({
47767
48077
  commands: this.device.getCommands(),
47768
48078
  timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
47769
- request: PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
47770
48079
  });
48080
+ if (isProtocolV2LoaderDeviceInfo(deviceInfo, null)) {
48081
+ this.device.updateProtocolV2Features(deviceInfo, null);
48082
+ return false;
48083
+ }
48084
+ const { message: deviceStatus } = yield typedCall('DeviceStatusGet', 'DeviceStatus', {}, { timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT });
47771
48085
  const features = this.device.updateProtocolV2Features(deviceInfo, deviceStatus);
47772
48086
  assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedDeviceId, (_a = features.deviceId) !== null && _a !== void 0 ? _a : undefined);
47773
48087
  if (this.isProtocolV2NormalModeFeatures(features)) {
@@ -48066,10 +48380,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
48066
48380
  const res = yield typedCall('DeviceReboot', 'Success', {
48067
48381
  reboot_type: rebootType,
48068
48382
  });
48383
+ this.device.markProtocolV2Reboot(rebootType);
48069
48384
  return res.message;
48070
48385
  }
48071
48386
  catch (error) {
48072
48387
  if (isProtocolV2DeviceDisconnectedError(error) || isProtocolV2ReconnectProbeError(error)) {
48388
+ this.device.markProtocolV2Reboot(rebootType);
48073
48389
  return { message: 'Device rebooted successfully' };
48074
48390
  }
48075
48391
  throw error;
@@ -48194,113 +48510,16 @@ class DeviceReboot extends BaseMethod {
48194
48510
  run() {
48195
48511
  var _a;
48196
48512
  return __awaiter(this, void 0, void 0, function* () {
48513
+ const rebootType = normalizeRebootType((_a = this.params.reboot_type) !== null && _a !== void 0 ? _a : this.params.rebootType);
48197
48514
  const res = yield this.device.commands.typedCall('DeviceReboot', 'Success', {
48198
- reboot_type: normalizeRebootType((_a = this.params.reboot_type) !== null && _a !== void 0 ? _a : this.params.rebootType),
48515
+ reboot_type: rebootType,
48199
48516
  });
48517
+ this.device.markProtocolV2Reboot(rebootType);
48200
48518
  return Promise.resolve(res.message);
48201
48519
  });
48202
48520
  }
48203
48521
  }
48204
48522
 
48205
- const TARGET_KEYS = [
48206
- 'hw',
48207
- 'fw',
48208
- 'coprocessor',
48209
- 'se1',
48210
- 'se2',
48211
- 'se3',
48212
- 'se4',
48213
- 'status',
48214
- ];
48215
- const TYPE_KEYS = ['version', 'build_id', 'hash', 'specific'];
48216
- const DEFAULT_TARGETS = {
48217
- hw: true,
48218
- fw: true,
48219
- coprocessor: true,
48220
- };
48221
- const DEFAULT_TYPES = {
48222
- version: true,
48223
- specific: true,
48224
- };
48225
- function pickBooleanKeys(value, keys) {
48226
- if (!value || typeof value !== 'object' || Array.isArray(value))
48227
- return undefined;
48228
- const source = value;
48229
- const result = {};
48230
- let hasKey = false;
48231
- for (const key of keys) {
48232
- if (source[key]) {
48233
- result[key] = true;
48234
- hasKey = true;
48235
- }
48236
- }
48237
- return hasKey ? result : undefined;
48238
- }
48239
- function assertKnownKeys(value, keys, name) {
48240
- if (value == null)
48241
- return;
48242
- if (typeof value !== 'object' || Array.isArray(value)) {
48243
- throw invalidParameter(`Parameter [${name}] must be an object.`);
48244
- }
48245
- const allowed = new Set(keys);
48246
- const unknownKeys = Object.keys(value).filter(key => !allowed.has(key));
48247
- if (unknownKeys.length > 0) {
48248
- throw invalidParameter(`Parameter [${name}] contains unsupported key(s): ${unknownKeys.join(', ')}.`);
48249
- }
48250
- }
48251
- function normalizeTargets(value) {
48252
- assertKnownKeys(value, TARGET_KEYS.map(key => String(key)), 'targets');
48253
- return pickBooleanKeys(value, TARGET_KEYS);
48254
- }
48255
- function normalizeTypes(value) {
48256
- assertKnownKeys(value, TYPE_KEYS.map(key => String(key)), 'types');
48257
- return pickBooleanKeys(value, TYPE_KEYS);
48258
- }
48259
- class DeviceInfoGet extends BaseMethod {
48260
- init() {
48261
- var _a, _b;
48262
- this.requireProtocolV2 = true;
48263
- this.allowDeviceMode = [
48264
- ...this.allowDeviceMode,
48265
- UI_REQUEST.NOT_INITIALIZE,
48266
- UI_REQUEST.BOOTLOADER,
48267
- ];
48268
- this.useDevicePassphraseState = false;
48269
- this.skipForceUpdateCheck = true;
48270
- this.params = {
48271
- targets: (_a = normalizeTargets(this.payload.targets)) !== null && _a !== void 0 ? _a : DEFAULT_TARGETS,
48272
- types: (_b = normalizeTypes(this.payload.types)) !== null && _b !== void 0 ? _b : DEFAULT_TYPES,
48273
- };
48274
- }
48275
- run() {
48276
- return __awaiter(this, void 0, void 0, function* () {
48277
- if (!this.device.isProtocolV2()) {
48278
- throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
48279
- }
48280
- const res = yield this.device.commands.typedCall('DeviceInfoGet', 'DeviceInfo', {
48281
- targets: this.params.targets,
48282
- types: this.params.types,
48283
- }, { timeoutMs: PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS });
48284
- return Promise.resolve(res.message);
48285
- });
48286
- }
48287
- }
48288
-
48289
- class DeviceStatusGet extends BaseMethod {
48290
- init() {
48291
- this.requireProtocolV2 = true;
48292
- this.useDevicePassphraseState = false;
48293
- this.skipForceUpdateCheck = true;
48294
- }
48295
- run() {
48296
- return __awaiter(this, void 0, void 0, function* () {
48297
- const { message } = yield this.device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
48298
- this.device.updateProtocolV2Status(message);
48299
- return message;
48300
- });
48301
- }
48302
- }
48303
-
48304
48523
  class DeviceGetOnboardingStatus extends BaseMethod {
48305
48524
  init() {
48306
48525
  this.requireProtocolV2 = true;
@@ -48497,22 +48716,6 @@ class DeviceFactoryInfoGet extends BaseMethod {
48497
48716
  }
48498
48717
  }
48499
48718
 
48500
- class DeviceSettingsGet extends BaseMethod {
48501
- init() {
48502
- this.requireProtocolV2 = true;
48503
- this.unlockPolicy = 'retry-on-locked';
48504
- this.skipForceUpdateCheck = true;
48505
- this.useDevicePassphraseState = false;
48506
- this.params = undefined;
48507
- }
48508
- run() {
48509
- return __awaiter(this, void 0, void 0, function* () {
48510
- const res = yield this.device.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
48511
- return Promise.resolve(res.message);
48512
- });
48513
- }
48514
- }
48515
-
48516
48719
  class DeviceSettingsSet extends BaseMethod {
48517
48720
  init() {
48518
48721
  const { settings } = this.payload;
@@ -48542,6 +48745,7 @@ class DeviceSettingsSet extends BaseMethod {
48542
48745
  run() {
48543
48746
  return __awaiter(this, void 0, void 0, function* () {
48544
48747
  const res = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', this.params);
48748
+ this.device.updateState(mapDeviceSettingsToState(this.params.settings), 'apply-settings');
48545
48749
  return Promise.resolve(res.message);
48546
48750
  });
48547
48751
  }
@@ -58533,7 +58737,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
58533
58737
  preInitialize: PreInitialize,
58534
58738
  searchDevices: SearchDevices,
58535
58739
  getFeatures: GetFeatures,
58536
- getDeviceInfo: GetDeviceInfo,
58740
+ getDeviceState: GetDeviceState,
58537
58741
  getOnekeyFeatures: GetOnekeyFeatures,
58538
58742
  getPassphraseState: GetPassphraseState,
58539
58743
  getLogs: GetLogs,
@@ -58573,15 +58777,12 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
58573
58777
  protocolInfoRequest: ProtocolInfoRequest,
58574
58778
  ping: Ping,
58575
58779
  deviceReboot: DeviceReboot,
58576
- deviceInfoGet: DeviceInfoGet,
58577
- deviceStatusGet: DeviceStatusGet,
58578
58780
  deviceGetOnboardingStatus: DeviceGetOnboardingStatus,
58579
58781
  deviceSessionOpen: DeviceSessionOpen,
58580
58782
  deviceFirmwareUpdate: DeviceFirmwareUpdate,
58581
58783
  deviceGetFirmwareUpdateStatus: DeviceGetFirmwareUpdateStatus,
58582
58784
  deviceFactoryInfoSet: DeviceFactoryInfoSet,
58583
58785
  deviceFactoryInfoGet: DeviceFactoryInfoGet,
58584
- deviceSettingsGet: DeviceSettingsGet,
58585
58786
  deviceSettingsSet: DeviceSettingsSet,
58586
58787
  deviceSettingsPageShow: DeviceSettingsPageShow,
58587
58788
  deviceUploadWallpaper: DeviceUploadWallpaper,
@@ -58696,12 +58897,139 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
58696
58897
  neoSignTransaction: NeoSignTransaction
58697
58898
  });
58698
58899
 
58900
+ const TARGET_KEYS = [
58901
+ 'hw',
58902
+ 'fw',
58903
+ 'coprocessor',
58904
+ 'se1',
58905
+ 'se2',
58906
+ 'se3',
58907
+ 'se4',
58908
+ ];
58909
+ const TYPE_KEYS = ['version', 'build_id', 'hash', 'specific'];
58910
+ const DEFAULT_TARGETS = {
58911
+ hw: true,
58912
+ fw: true,
58913
+ coprocessor: true,
58914
+ };
58915
+ const DEFAULT_TYPES = {
58916
+ version: true,
58917
+ specific: true,
58918
+ };
58919
+ function pickBooleanKeys(value, keys) {
58920
+ if (!value || typeof value !== 'object' || Array.isArray(value))
58921
+ return undefined;
58922
+ const source = value;
58923
+ const result = {};
58924
+ let hasKey = false;
58925
+ for (const key of keys) {
58926
+ if (source[key]) {
58927
+ result[key] = true;
58928
+ hasKey = true;
58929
+ }
58930
+ }
58931
+ return hasKey ? result : undefined;
58932
+ }
58933
+ function assertKnownKeys(value, keys, name) {
58934
+ if (value == null)
58935
+ return;
58936
+ if (typeof value !== 'object' || Array.isArray(value)) {
58937
+ throw invalidParameter(`Parameter [${name}] must be an object.`);
58938
+ }
58939
+ const allowed = new Set(keys);
58940
+ const unknownKeys = Object.keys(value).filter(key => !allowed.has(key));
58941
+ if (unknownKeys.length > 0) {
58942
+ throw invalidParameter(`Parameter [${name}] contains unsupported key(s): ${unknownKeys.join(', ')}.`);
58943
+ }
58944
+ }
58945
+ function normalizeTargets(value) {
58946
+ assertKnownKeys(value, TARGET_KEYS.map(key => String(key)), 'targets');
58947
+ return pickBooleanKeys(value, TARGET_KEYS);
58948
+ }
58949
+ function normalizeTypes(value) {
58950
+ assertKnownKeys(value, TYPE_KEYS.map(key => String(key)), 'types');
58951
+ return pickBooleanKeys(value, TYPE_KEYS);
58952
+ }
58953
+ class DeviceInfoGet extends BaseMethod {
58954
+ init() {
58955
+ var _a, _b;
58956
+ this.requireProtocolV2 = true;
58957
+ this.unlockPolicy = 'none';
58958
+ this.allowDeviceMode = [
58959
+ ...this.allowDeviceMode,
58960
+ UI_REQUEST.NOT_INITIALIZE,
58961
+ UI_REQUEST.BOOTLOADER,
58962
+ ];
58963
+ this.useDevicePassphraseState = false;
58964
+ this.skipForceUpdateCheck = true;
58965
+ this.params = {
58966
+ targets: (_a = normalizeTargets(this.payload.targets)) !== null && _a !== void 0 ? _a : DEFAULT_TARGETS,
58967
+ types: (_b = normalizeTypes(this.payload.types)) !== null && _b !== void 0 ? _b : DEFAULT_TYPES,
58968
+ };
58969
+ }
58970
+ run() {
58971
+ return __awaiter(this, void 0, void 0, function* () {
58972
+ if (!this.device.isProtocolV2()) {
58973
+ throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
58974
+ }
58975
+ const res = yield this.device.commands.typedCall('DeviceInfoGet', 'DeviceInfo', {
58976
+ targets: this.params.targets,
58977
+ types: this.params.types,
58978
+ }, { timeoutMs: PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS });
58979
+ return Promise.resolve(res.message);
58980
+ });
58981
+ }
58982
+ }
58983
+
58984
+ class DeviceStatusGet extends BaseMethod {
58985
+ init() {
58986
+ this.requireProtocolV2 = true;
58987
+ this.unlockPolicy = 'none';
58988
+ this.useDevicePassphraseState = false;
58989
+ this.skipForceUpdateCheck = true;
58990
+ }
58991
+ run() {
58992
+ return __awaiter(this, void 0, void 0, function* () {
58993
+ const { message } = yield this.device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
58994
+ this.device.updateProtocolV2Status(message);
58995
+ return message;
58996
+ });
58997
+ }
58998
+ }
58999
+
59000
+ class DeviceSettingsGet extends BaseMethod {
59001
+ init() {
59002
+ this.requireProtocolV2 = true;
59003
+ this.unlockPolicy = 'none';
59004
+ this.skipForceUpdateCheck = true;
59005
+ this.useDevicePassphraseState = false;
59006
+ this.params = undefined;
59007
+ }
59008
+ run() {
59009
+ return __awaiter(this, void 0, void 0, function* () {
59010
+ const res = yield this.device.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
59011
+ this.device.updateState(mapDeviceSettingsToState(res.message), 'apply-settings');
59012
+ return Promise.resolve(res.message);
59013
+ });
59014
+ }
59015
+ }
59016
+
59017
+ var InternalApiMethods = /*#__PURE__*/Object.freeze({
59018
+ __proto__: null,
59019
+ deviceInfoGet: DeviceInfoGet,
59020
+ deviceStatusGet: DeviceStatusGet,
59021
+ deviceSettingsGet: DeviceSettingsGet
59022
+ });
59023
+
59024
+ const publicMethodRegistry = ApiMethods;
59025
+ const internalMethodRegistry = InternalApiMethods;
58699
59026
  function findMethod(message) {
59027
+ var _a;
58700
59028
  const { method } = message.payload;
58701
59029
  if (typeof method !== 'string') {
58702
59030
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
58703
59031
  }
58704
- const MethodConstructor = ApiMethods[method];
59032
+ const MethodConstructor = (_a = publicMethodRegistry[method]) !== null && _a !== void 0 ? _a : internalMethodRegistry[method];
58705
59033
  if (MethodConstructor) {
58706
59034
  return new MethodConstructor(message);
58707
59035
  }
@@ -59404,6 +59732,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
59404
59732
  attachPinOnDevice: onEnterAttachPinOnDeviceHandler,
59405
59733
  });
59406
59734
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
59735
+ device.on(DEVICE.STATE, onDeviceStateHandler);
59407
59736
  device.on(DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE, onSelectDeviceInBootloaderForWebDeviceHandler);
59408
59737
  const protocolV2UiCoordinator = new ProtocolV2UiInteractionCoordinator(device, postMessage);
59409
59738
  device.on(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE, onSelectDeviceForSwitchFirmwareWebDeviceHandler);
@@ -59488,7 +59817,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
59488
59817
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
59489
59818
  }
59490
59819
  if (method.deviceId && method.checkDeviceId) {
59491
- const isSameDeviceID = device.checkDeviceId(method.deviceId);
59820
+ const isSameDeviceID = yield checkLiveDeviceId(device, method.deviceId);
59492
59821
  if (!isSameDeviceID) {
59493
59822
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError));
59494
59823
  }
@@ -59995,6 +60324,9 @@ const onDeviceButtonHandler = (...[device, request]) => {
59995
60324
  const onDeviceFeaturesHandler = (...[_, features]) => {
59996
60325
  postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
59997
60326
  };
60327
+ const onDeviceStateHandler = (...[_, stateEvent]) => {
60328
+ postMessage(createDeviceMessage(DEVICE.STATE, stateEvent));
60329
+ };
59998
60330
  const onDevicePassphraseHandler = (...[device, requestPayload, callback]) => __awaiter(void 0, void 0, void 0, function* () {
59999
60331
  Log.debug('onDevicePassphraseHandler');
60000
60332
  const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PASSPHRASE, device);