@onekeyfe/hd-core 1.2.0-alpha.32 → 1.2.0-alpha.34

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 (75) hide show
  1. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +31 -0
  2. package/__tests__/core-dispose.test.ts +3 -3
  3. package/__tests__/device-lifecycle-events.test.ts +52 -0
  4. package/__tests__/device-pool-state.test.ts +14 -2
  5. package/__tests__/device-settings.test.ts +22 -0
  6. package/__tests__/device-state-mapper.test.ts +13 -2
  7. package/__tests__/device-state-projector.test.ts +2 -2
  8. package/__tests__/device-utils.test.ts +1 -0
  9. package/__tests__/device-wallet-session-store.test.ts +64 -17
  10. package/__tests__/kaspaSignTransaction.test.ts +9 -0
  11. package/__tests__/known-device-public-types.type-test.ts +3 -0
  12. package/__tests__/logBlockEvent.test.ts +89 -5
  13. package/__tests__/open-wallet-session.test.ts +334 -30
  14. package/__tests__/pro2Wallpaper.test.ts +1 -1
  15. package/__tests__/protocol-v2.test.ts +708 -75
  16. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  17. package/dist/api/FirmwareUpdateV4.d.ts +1 -0
  18. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  19. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  20. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  21. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  22. package/dist/core/index.d.ts.map +1 -1
  23. package/dist/device/Device.d.ts +7 -2
  24. package/dist/device/Device.d.ts.map +1 -1
  25. package/dist/device/DeviceConnector.d.ts +1 -1
  26. package/dist/device/DeviceConnector.d.ts.map +1 -1
  27. package/dist/device/DevicePool.d.ts +1 -0
  28. package/dist/device/DevicePool.d.ts.map +1 -1
  29. package/dist/device/DeviceStateMapper.d.ts.map +1 -1
  30. package/dist/device/DeviceStateProjector.d.ts.map +1 -1
  31. package/dist/device/DeviceWalletSessionStore.d.ts +8 -0
  32. package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -1
  33. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  34. package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts +7 -0
  35. package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -0
  36. package/dist/events/logBlockEvent.d.ts +2 -0
  37. package/dist/events/logBlockEvent.d.ts.map +1 -1
  38. package/dist/index.d.ts +19 -7
  39. package/dist/index.js +456 -222
  40. package/dist/protocols/protocol-v2/walletSession.d.ts +0 -10
  41. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  42. package/dist/types/api/openWalletSession.d.ts +1 -1
  43. package/dist/types/api/openWalletSession.d.ts.map +1 -1
  44. package/dist/types/device.d.ts +4 -2
  45. package/dist/types/device.d.ts.map +1 -1
  46. package/dist/types/params.d.ts.map +1 -1
  47. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
  48. package/dist/utils/deviceFeaturesUtils.d.ts +0 -5
  49. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  50. package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
  51. package/package.json +4 -4
  52. package/src/api/CheckAllFirmwareRelease.ts +11 -81
  53. package/src/api/FirmwareUpdateV4.ts +33 -17
  54. package/src/api/GetPassphraseState.ts +1 -3
  55. package/src/api/OpenWalletSession.ts +3 -3
  56. package/src/api/device/DeviceSettings.ts +8 -1
  57. package/src/api/kaspa/KaspaSignTransaction.ts +7 -0
  58. package/src/core/index.ts +7 -5
  59. package/src/device/Device.ts +37 -9
  60. package/src/device/DeviceConnector.ts +10 -7
  61. package/src/device/DevicePool.ts +5 -3
  62. package/src/device/DeviceStateMapper.ts +5 -3
  63. package/src/device/DeviceStateProjector.ts +0 -7
  64. package/src/device/DeviceWalletSessionStore.ts +57 -4
  65. package/src/deviceProfile/buildDeviceFeatures.ts +10 -3
  66. package/src/deviceProfile/protocolV2DeviceIdentity.ts +32 -0
  67. package/src/events/logBlockEvent.ts +84 -1
  68. package/src/protocols/protocol-v2/deviceSession.ts +1 -1
  69. package/src/protocols/protocol-v2/walletSession.ts +116 -34
  70. package/src/types/api/openWalletSession.ts +1 -1
  71. package/src/types/device.ts +6 -2
  72. package/src/types/params.ts +2 -1
  73. package/src/utils/deviceFeaturesCompat.ts +8 -1
  74. package/src/utils/pro2Wallpaper.ts +3 -9
  75. package/tsconfig.type-tests.json +5 -1
package/dist/index.js CHANGED
@@ -1473,10 +1473,14 @@ const resolveDeviceBleName = (features) => {
1473
1473
  return ((_a = firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name)) !== null && _a !== void 0 ? _a : null);
1474
1474
  };
1475
1475
  const resolveDeviceFirmwareVersion = (features) => {
1476
+ var _a;
1476
1477
  if (!features)
1477
1478
  return null;
1478
1479
  const compatible = asCompatibleFeatures(features);
1479
- return firstMeaningfulVersion$1(compatible.firmwareVersion, compatible.onekey_firmware_version, compatible.onekey_version, versionFromParts(compatible.major_version, compatible.minor_version, compatible.patch_version));
1480
+ const bootloaderMode = (_a = compatible.bootloaderMode) !== null && _a !== void 0 ? _a : compatible.bootloader_mode;
1481
+ return firstMeaningfulVersion$1(compatible.firmwareVersion, compatible.onekey_firmware_version, compatible.onekey_version, bootloaderMode
1482
+ ? null
1483
+ : versionFromParts(compatible.major_version, compatible.minor_version, compatible.patch_version));
1480
1484
  };
1481
1485
  const resolveDeviceBootloaderVersion = (features) => {
1482
1486
  var _a;
@@ -40047,9 +40051,60 @@ const createFirmwareMessage = (type, payload) => ({
40047
40051
  });
40048
40052
 
40049
40053
  const LogBlockEvent = new Set([
40054
+ UI_REQUEST.REQUEST_PASSPHRASE,
40055
+ UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE,
40050
40056
  UI_RESPONSE.RECEIVE_PIN,
40051
40057
  UI_RESPONSE.RECEIVE_PASSPHRASE,
40052
40058
  ]);
40059
+ const LogLabelMethod = new Set([
40060
+ 'openWalletSession',
40061
+ 'deviceUploadWallpaper',
40062
+ 'uploadPortfolio',
40063
+ 'fileWrite',
40064
+ 'fileRead',
40065
+ ]);
40066
+ const SensitiveLogKeys = new Set([
40067
+ 'devicestate',
40068
+ 'entropy',
40069
+ 'expectedpassphrasestate',
40070
+ 'mnemonic',
40071
+ 'passphrase',
40072
+ 'passphrasestate',
40073
+ 'password',
40074
+ 'pin',
40075
+ 'privatekey',
40076
+ 'seed',
40077
+ 'session',
40078
+ 'sessionid',
40079
+ 'walletsessionid',
40080
+ 'xprv',
40081
+ ]);
40082
+ const normalizeLogKey = (key) => key.replace(/[_-]/g, '').toLowerCase();
40083
+ const isSigningMethod = (methodName) => /sign/i.test(methodName);
40084
+ const redactLogValue = (value, seen) => {
40085
+ if (ArrayBuffer.isView(value)) {
40086
+ return `[BINARY:${value.byteLength}]`;
40087
+ }
40088
+ if (value instanceof ArrayBuffer) {
40089
+ return `[BINARY:${value.byteLength}]`;
40090
+ }
40091
+ if (Array.isArray(value)) {
40092
+ return value.map(item => redactLogValue(item, seen));
40093
+ }
40094
+ if (!value || typeof value !== 'object')
40095
+ return value;
40096
+ if (seen.has(value))
40097
+ return '[CIRCULAR]';
40098
+ seen.add(value);
40099
+ const redacted = Object.fromEntries(Object.entries(value).map(([key, item]) => [
40100
+ key,
40101
+ SensitiveLogKeys.has(normalizeLogKey(key)) && item !== null && item !== undefined
40102
+ ? '[REDACTED]'
40103
+ : redactLogValue(item, seen),
40104
+ ]));
40105
+ seen.delete(value);
40106
+ return redacted;
40107
+ };
40053
40108
  function getLogBlockLabel(message) {
40054
40109
  if (!message || typeof message !== 'object')
40055
40110
  return undefined;
@@ -40058,7 +40113,26 @@ function getLogBlockLabel(message) {
40058
40113
  return type;
40059
40114
  }
40060
40115
  const methodName = method !== null && method !== void 0 ? method : payload === null || payload === void 0 ? void 0 : payload.method;
40061
- return methodName;
40116
+ if (methodName && (LogLabelMethod.has(methodName) || isSigningMethod(methodName))) {
40117
+ return methodName;
40118
+ }
40119
+ return undefined;
40120
+ }
40121
+ function getSafeLogPayload(value, blockLabel) {
40122
+ if (blockLabel && (LogBlockEvent.has(blockLabel) || isSigningMethod(blockLabel))) {
40123
+ return { method: blockLabel, payload: '[REDACTED]' };
40124
+ }
40125
+ const redactedValue = redactLogValue(value, new WeakSet());
40126
+ if (blockLabel &&
40127
+ redactedValue &&
40128
+ typeof redactedValue === 'object' &&
40129
+ !Array.isArray(redactedValue)) {
40130
+ return Object.assign(Object.assign({}, redactedValue), { method: blockLabel });
40131
+ }
40132
+ return redactedValue;
40133
+ }
40134
+ function formatLogMethodLabel(label, methodName) {
40135
+ return methodName ? `${label} [${methodName}]` : label;
40062
40136
  }
40063
40137
 
40064
40138
  function assertCompleteDeviceSession(message) {
@@ -40066,7 +40140,7 @@ function assertCompleteDeviceSession(message) {
40066
40140
  !message.session_id ||
40067
40141
  typeof message.btc_test_address !== 'string' ||
40068
40142
  !message.btc_test_address) {
40069
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'DeviceSessionGet returned an incomplete DeviceSession response.');
40143
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device returned an incomplete DeviceSession response.');
40070
40144
  }
40071
40145
  }
40072
40146
 
@@ -40077,6 +40151,37 @@ function isDeviceLockedError(error) {
40077
40151
  error.errorCode === hdShared.HardwareErrorCode.DeviceLocked);
40078
40152
  }
40079
40153
 
40154
+ const HOST_PASSPHRASE_MAX_BYTES = 50;
40155
+ const utf8ByteLength = (value) => {
40156
+ var _a;
40157
+ let length = 0;
40158
+ for (const character of value) {
40159
+ const codePoint = (_a = character.codePointAt(0)) !== null && _a !== void 0 ? _a : 0;
40160
+ if (codePoint >= 0xd800 && codePoint <= 0xdfff)
40161
+ return undefined;
40162
+ if (codePoint <= 0x7f)
40163
+ length += 1;
40164
+ else if (codePoint <= 0x7ff)
40165
+ length += 2;
40166
+ else if (codePoint <= 0xffff)
40167
+ length += 3;
40168
+ else
40169
+ length += 4;
40170
+ }
40171
+ return length;
40172
+ };
40173
+ function requestProtocolV2DeviceStatus$1(device) {
40174
+ return __awaiter(this, void 0, void 0, function* () {
40175
+ const { message } = yield device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
40176
+ return message;
40177
+ });
40178
+ }
40179
+ function refreshProtocolV2DeviceStatus(device) {
40180
+ return __awaiter(this, void 0, void 0, function* () {
40181
+ const status = yield requestProtocolV2DeviceStatus$1(device);
40182
+ return device.updateProtocolV2Status(status);
40183
+ });
40184
+ }
40080
40185
  const negotiateEventlessWalletSession = (device) => __awaiter(void 0, void 0, void 0, function* () {
40081
40186
  yield device.commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {
40082
40187
  eventless_wallet_session: true,
@@ -40087,7 +40192,7 @@ const getDeviceSession = (device, request) => __awaiter(void 0, void 0, void 0,
40087
40192
  return yield device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
40088
40193
  }
40089
40194
  catch (error) {
40090
- if (!isDeviceLockedError(error)) {
40195
+ if (!isDeviceLockedError(error) || !request.session_id) {
40091
40196
  throw error;
40092
40197
  }
40093
40198
  yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main);
@@ -40097,25 +40202,31 @@ const getDeviceSession = (device, request) => __awaiter(void 0, void 0, void 0,
40097
40202
  const askDevicePassphrase = (device, passphrase) => __awaiter(void 0, void 0, void 0, function* () {
40098
40203
  const request = () => device.commands.typedCall('DeviceSessionAskPassphrase', 'Success', passphrase ? { passphrase, on_device: false } : { on_device: true });
40099
40204
  try {
40100
- return yield request();
40205
+ yield request();
40101
40206
  }
40102
40207
  catch (error) {
40103
40208
  if (!isDeviceLockedError(error)) {
40104
40209
  throw error;
40105
40210
  }
40106
40211
  yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main);
40107
- return request();
40212
+ yield request();
40108
40213
  }
40214
+ yield refreshProtocolV2DeviceStatus(device);
40109
40215
  });
40110
- const selectDeviceSession = (device) => __awaiter(void 0, void 0, void 0, function* () {
40216
+ const selectDeviceSession = (device, expectedPassphraseState) => __awaiter(void 0, void 0, void 0, function* () {
40111
40217
  var _a;
40112
40218
  const existsAttachPinUser = ((_a = device.features) === null || _a === void 0 ? void 0 : _a.attachToPinEnabled) === true;
40113
- const metadata = {
40114
- source: 'wallet-session-coordinator',
40115
- reason: 'open-wallet',
40116
- };
40117
- const response = yield device.commands.promptPassphrase(Object.assign({ existsAttachPinUser, deviceOnly: true }, metadata), { cancelDeviceOnReject: false });
40118
- const hasHostPassphrase = typeof response.passphrase === 'string' && response.passphrase.length > 0;
40219
+ const metadata = Object.assign({ source: 'wallet-session-coordinator', reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet' }, (expectedPassphraseState ? { expectedPassphraseState } : {}));
40220
+ const response = yield device.commands.promptPassphrase(Object.assign({ existsAttachPinUser, deviceOnly: false }, metadata), { cancelDeviceOnReject: false });
40221
+ const hostPassphrase = typeof response.passphrase === 'string' ? response.passphrase.normalize('NFKD') : undefined;
40222
+ const hasHostPassphrase = typeof hostPassphrase === 'string' && hostPassphrase.length > 0;
40223
+ const hostPassphraseByteLength = hasHostPassphrase ? utf8ByteLength(hostPassphrase) : undefined;
40224
+ if (hasHostPassphrase &&
40225
+ (hostPassphrase.includes('\0') ||
40226
+ hostPassphraseByteLength === undefined ||
40227
+ hostPassphraseByteLength > HOST_PASSPHRASE_MAX_BYTES)) {
40228
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Host passphrase must contain 1 to ${HOST_PASSPHRASE_MAX_BYTES} valid UTF-8 bytes without NUL.`);
40229
+ }
40119
40230
  const selections = [
40120
40231
  hasHostPassphrase,
40121
40232
  response.passphraseOnDevice === true,
@@ -40133,7 +40244,7 @@ const selectDeviceSession = (device) => __awaiter(void 0, void 0, void 0, functi
40133
40244
  return getDeviceSession(device, {});
40134
40245
  }
40135
40246
  if (hasHostPassphrase) {
40136
- yield askDevicePassphrase(device, response.passphrase);
40247
+ yield askDevicePassphrase(device, hostPassphrase);
40137
40248
  return getDeviceSession(device, {});
40138
40249
  }
40139
40250
  device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, metadata);
@@ -40141,34 +40252,55 @@ const selectDeviceSession = (device) => __awaiter(void 0, void 0, void 0, functi
40141
40252
  return getDeviceSession(device, {});
40142
40253
  });
40143
40254
  function getProtocolV2WalletSession(device, options) {
40144
- var _a, _b, _c, _d, _e, _f;
40255
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
40145
40256
  return __awaiter(this, void 0, void 0, function* () {
40146
40257
  if (options === null || options === void 0 ? void 0 : options.initSession) {
40147
- device.clearInternalState();
40258
+ if (options.onlyMainPin) {
40259
+ (_a = device.clearStandardInternalState) === null || _a === void 0 ? void 0 : _a.call(device);
40260
+ }
40261
+ else {
40262
+ device.clearInternalState();
40263
+ }
40148
40264
  device.passphraseState = undefined;
40149
40265
  }
40150
40266
  yield negotiateEventlessWalletSession(device);
40151
40267
  if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40152
40268
  device.passphraseState = undefined;
40153
40269
  }
40154
- const expectedPassphraseState = (options === null || options === void 0 ? void 0 : options.onlyMainPin)
40270
+ let expectedPassphraseState = (options === null || options === void 0 ? void 0 : options.onlyMainPin)
40155
40271
  ? undefined
40156
- : (_a = options === null || options === void 0 ? void 0 : options.expectedPassphraseState) !== null && _a !== void 0 ? _a : device.passphraseState;
40157
- if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.unlocked) === false) {
40158
- yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main);
40159
- }
40160
- if ((options === null || options === void 0 ? void 0 : options.onlyMainPin) || device.getCurrentPassphraseProtection() === false) {
40161
- return {
40162
- passphraseState: undefined,
40163
- newSession: undefined,
40164
- unlockedAttachPin: (_d = (_c = device.features) === null || _c === void 0 ? void 0 : _c.unlockedAttachPin) !== null && _d !== void 0 ? _d : false,
40165
- resumed: false,
40166
- };
40167
- }
40168
- const cachedSessionId = typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
40272
+ : (_b = options === null || options === void 0 ? void 0 : options.expectedPassphraseState) !== null && _b !== void 0 ? _b : device.passphraseState;
40273
+ const cachedStandardSession = (options === null || options === void 0 ? void 0 : options.onlyMainPin)
40274
+ ? (_c = device.getStandardInternalState) === null || _c === void 0 ? void 0 : _c.call(device)
40275
+ : undefined;
40276
+ const cachedSessionId = !(options === null || options === void 0 ? void 0 : options.onlyMainPin) && typeof device.getInternalState === 'function'
40277
+ ? device.getInternalState()
40278
+ : undefined;
40169
40279
  let response;
40170
40280
  let resumed = false;
40171
- if (cachedSessionId && expectedPassphraseState) {
40281
+ if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40282
+ expectedPassphraseState = cachedStandardSession === null || cachedStandardSession === void 0 ? void 0 : cachedStandardSession.passphraseState;
40283
+ if (cachedStandardSession) {
40284
+ try {
40285
+ if (((_d = device.features) === null || _d === void 0 ? void 0 : _d.unlockedAttachPin) === true) {
40286
+ yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main);
40287
+ }
40288
+ response = yield getDeviceSession(device, {
40289
+ session_id: cachedStandardSession.sessionId,
40290
+ });
40291
+ resumed = true;
40292
+ }
40293
+ catch (error) {
40294
+ (_e = device.clearStandardInternalState) === null || _e === void 0 ? void 0 : _e.call(device);
40295
+ throw error;
40296
+ }
40297
+ }
40298
+ if (!response) {
40299
+ yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main);
40300
+ response = yield getDeviceSession(device, {});
40301
+ }
40302
+ }
40303
+ else if (cachedSessionId && expectedPassphraseState) {
40172
40304
  try {
40173
40305
  response = yield getDeviceSession(device, { session_id: cachedSessionId });
40174
40306
  resumed = true;
@@ -40183,25 +40315,72 @@ function getProtocolV2WalletSession(device, options) {
40183
40315
  device.clearInternalState();
40184
40316
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
40185
40317
  }
40186
- response = yield selectDeviceSession(device);
40318
+ response = yield selectDeviceSession(device, expectedPassphraseState);
40187
40319
  }
40188
- const { message } = response;
40320
+ let { message } = response;
40189
40321
  try {
40190
40322
  assertCompleteDeviceSession(message);
40191
40323
  }
40192
40324
  catch (error) {
40193
- device.clearInternalState();
40325
+ if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40326
+ (_f = device.clearStandardInternalState) === null || _f === void 0 ? void 0 : _f.call(device);
40327
+ }
40328
+ else {
40329
+ device.clearInternalState();
40330
+ }
40194
40331
  throw error;
40195
40332
  }
40196
40333
  if (expectedPassphraseState && expectedPassphraseState !== message.btc_test_address) {
40197
- device.clearInternalState();
40198
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
40334
+ resumed = false;
40335
+ if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40336
+ (_g = device.clearStandardInternalState) === null || _g === void 0 ? void 0 : _g.call(device);
40337
+ yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main);
40338
+ response = yield getDeviceSession(device, {});
40339
+ }
40340
+ else {
40341
+ device.clearInternalState();
40342
+ response = yield selectDeviceSession(device, expectedPassphraseState);
40343
+ }
40344
+ message = response.message;
40345
+ try {
40346
+ assertCompleteDeviceSession(message);
40347
+ }
40348
+ catch (error) {
40349
+ if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40350
+ (_h = device.clearStandardInternalState) === null || _h === void 0 ? void 0 : _h.call(device);
40351
+ }
40352
+ else {
40353
+ device.clearInternalState();
40354
+ }
40355
+ throw error;
40356
+ }
40357
+ if (expectedPassphraseState !== message.btc_test_address) {
40358
+ if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40359
+ (_j = device.clearStandardInternalState) === null || _j === void 0 ? void 0 : _j.call(device);
40360
+ }
40361
+ else {
40362
+ device.clearInternalState();
40363
+ }
40364
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
40365
+ }
40366
+ }
40367
+ const internalStateArgs = [
40368
+ true,
40369
+ message.btc_test_address,
40370
+ device.getCurrentDeviceId(),
40371
+ message.session_id,
40372
+ (options === null || options === void 0 ? void 0 : options.initSession) ? null : cachedSessionId !== null && cachedSessionId !== void 0 ? cachedSessionId : null,
40373
+ ];
40374
+ if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40375
+ device.updateInternalState(...internalStateArgs, 'standard');
40376
+ }
40377
+ else {
40378
+ device.updateInternalState(...internalStateArgs);
40199
40379
  }
40200
- device.updateInternalState(true, message.btc_test_address, device.getCurrentDeviceId(), message.session_id, (options === null || options === void 0 ? void 0 : options.initSession) ? null : cachedSessionId !== null && cachedSessionId !== void 0 ? cachedSessionId : null);
40201
40380
  return {
40202
40381
  passphraseState: message.btc_test_address,
40203
40382
  newSession: message.session_id,
40204
- unlockedAttachPin: (_f = (_e = device.features) === null || _e === void 0 ? void 0 : _e.unlockedAttachPin) !== null && _f !== void 0 ? _f : undefined,
40383
+ unlockedAttachPin: (_l = (_k = device.features) === null || _k === void 0 ? void 0 : _k.unlockedAttachPin) !== null && _l !== void 0 ? _l : undefined,
40205
40384
  resumed,
40206
40385
  };
40207
40386
  });
@@ -40849,15 +41028,9 @@ function encodePro2Wallpaper(options) {
40849
41028
  for (let x = 0; x < width; x += 1) {
40850
41029
  const sourceOffset = (y * width + x) * 4;
40851
41030
  const thresholdIndex = ((y & 7) << 3) + (x & 7);
40852
- let red = Math.min(rgba[sourceOffset] + RED_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
40853
- let green = Math.min(rgba[sourceOffset + 1] + GREEN_THRESHOLD[thresholdIndex], 0xff) & 0xfc;
40854
- let blue = Math.min(rgba[sourceOffset + 2] + BLUE_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
40855
- if (!hasTransparency) {
40856
- const alpha = rgba[sourceOffset + 3];
40857
- red = (red * alpha) >> 8;
40858
- green = (green * alpha) >> 8;
40859
- blue = (blue * alpha) >> 8;
40860
- }
41031
+ const red = Math.min(rgba[sourceOffset] + RED_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
41032
+ const green = Math.min(rgba[sourceOffset + 1] + GREEN_THRESHOLD[thresholdIndex], 0xff) & 0xfc;
41033
+ const blue = Math.min(rgba[sourceOffset + 2] + BLUE_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
40861
41034
  const rgb565 = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
40862
41035
  const rgbOffset = 12 + y * stride + x * 2;
40863
41036
  data[rgbOffset] = rgb565 & 0xff;
@@ -41453,9 +41626,12 @@ class DevicePool extends events.exports {
41453
41626
  this.connectedPool = [];
41454
41627
  this.disconnectPool = [];
41455
41628
  this.devicesCache = {};
41456
- this.emitter.removeAllListeners();
41457
41629
  Log$h.debug('DevicePool state has been reset');
41458
41630
  }
41631
+ static dispose() {
41632
+ this.resetState();
41633
+ this.emitter.removeAllListeners();
41634
+ }
41459
41635
  }
41460
41636
  DevicePool.current = null;
41461
41637
  DevicePool.upcoming = [];
@@ -42159,6 +42335,34 @@ function mergeDeviceFeaturesPatch(previous, patch) {
42159
42335
  return next;
42160
42336
  }
42161
42337
 
42338
+ const resolveProtocolV2DeviceIdentity = (deviceType) => {
42339
+ switch (deviceType) {
42340
+ case hdTransport.DeviceType.CLASSIC1:
42341
+ case 'CLASSIC1':
42342
+ return { deviceType: hdShared.EDeviceType.Classic, model: 'classic' };
42343
+ case hdTransport.DeviceType.CLASSIC1S:
42344
+ case 'CLASSIC1S':
42345
+ return { deviceType: hdShared.EDeviceType.Classic1s, model: 'classic1s' };
42346
+ case hdTransport.DeviceType.CLASSIC1S_PURE:
42347
+ case 'CLASSIC1S_PURE':
42348
+ return { deviceType: hdShared.EDeviceType.ClassicPure, model: 'classicpure' };
42349
+ case hdTransport.DeviceType.MINI:
42350
+ case 'MINI':
42351
+ return { deviceType: hdShared.EDeviceType.Mini, model: 'mini' };
42352
+ case hdTransport.DeviceType.TOUCH:
42353
+ case 'TOUCH':
42354
+ return { deviceType: hdShared.EDeviceType.Touch, model: 'touch' };
42355
+ case hdTransport.DeviceType.PRO:
42356
+ case 'PRO':
42357
+ return { deviceType: hdShared.EDeviceType.Pro, model: 'pro' };
42358
+ case hdTransport.DeviceType.PRO2:
42359
+ case 'PRO2':
42360
+ return { deviceType: hdShared.EDeviceType.Pro2, model: 'pro2' };
42361
+ default:
42362
+ return { deviceType: hdShared.EDeviceType.Unknown, model: null };
42363
+ }
42364
+ };
42365
+
42162
42366
  const firstMeaningfulVersion = (...versions) => { var _a; return (_a = versions.find(version => Boolean(version && version !== '0.0.0'))) !== null && _a !== void 0 ? _a : null; };
42163
42367
  const getProtocolV1Mode = (features) => {
42164
42368
  if (features.bootloader_mode === true)
@@ -42229,7 +42433,7 @@ const sanitizeRawFeatures = (features) => {
42229
42433
  return raw;
42230
42434
  };
42231
42435
  const imageVersion = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : undefined; };
42232
- const bytesToHex$3 = (value) => {
42436
+ const bytesToHex$2 = (value) => {
42233
42437
  if (!value)
42234
42438
  return undefined;
42235
42439
  if (typeof value === 'string')
@@ -42242,7 +42446,7 @@ const bytesToHex$3 = (value) => {
42242
42446
  return undefined;
42243
42447
  };
42244
42448
  const imageBuildId = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
42245
- const imageHash = (image) => bytesToHex$3(image === null || image === void 0 ? void 0 : image.hash);
42449
+ const imageHash = (image) => bytesToHex$2(image === null || image === void 0 ? void 0 : image.hash);
42246
42450
  const getFeaturesMode = (features) => {
42247
42451
  if (features.mode !== undefined && features.mode !== null)
42248
42452
  return features.mode;
@@ -42384,18 +42588,19 @@ const mapProtocolV1OnekeyFeaturesToState = (features) => {
42384
42588
  }) }, (Object.keys(verification).length > 0 ? { verification } : {})), { raw: { protocolV1OneKeyFeatures: features } });
42385
42589
  };
42386
42590
  const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
42387
- 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;
42591
+ 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;
42388
42592
  const loader = mode === 'bootloader' || mode === 'romloader';
42593
+ const identity = resolveProtocolV2DeviceIdentity((_a = info.hw) === null || _a === void 0 ? void 0 : _a.Device_type);
42389
42594
  return {
42390
42595
  protocol: 'V2',
42391
42596
  protocolVersion: info.protocol_version,
42392
42597
  identity: definedEntries({
42393
- deviceType: hdShared.EDeviceType.Pro2,
42598
+ deviceType: identity.deviceType,
42394
42599
  firmwareType: hdShared.EFirmwareType.Universal,
42395
- model: 'pro2',
42600
+ model: identity.model,
42396
42601
  vendor: 'onekey.so',
42397
- serialNo: (_a = info.hw) === null || _a === void 0 ? void 0 : _a.serial_no,
42398
- bleName: (_b = info.coprocessor) === null || _b === void 0 ? void 0 : _b.bt_adv_name,
42602
+ serialNo: (_b = info.hw) === null || _b === void 0 ? void 0 : _b.serial_no,
42603
+ bleName: (_c = info.coprocessor) === null || _c === void 0 ? void 0 : _c.bt_adv_name,
42399
42604
  deviceId: loader ? null : undefined,
42400
42605
  }),
42401
42606
  status: loader
@@ -42415,50 +42620,50 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
42415
42620
  }
42416
42621
  : { mode },
42417
42622
  versions: definedEntries({
42418
- firmware: imageVersion((_c = info.fw) === null || _c === void 0 ? void 0 : _c.application),
42419
- applicationP1: imageVersion((_d = info.fw) === null || _d === void 0 ? void 0 : _d.application),
42420
- applicationP2: imageVersion((_e = info.fw) === null || _e === void 0 ? void 0 : _e.application_data),
42421
- bootloader: imageVersion((_f = info.fw) === null || _f === void 0 ? void 0 : _f.bootloader),
42422
- board: imageVersion((_g = info.fw) === null || _g === void 0 ? void 0 : _g.romloader),
42423
- ble: imageVersion((_h = info.coprocessor) === null || _h === void 0 ? void 0 : _h.application),
42424
- se01: imageVersion((_j = info.se1) === null || _j === void 0 ? void 0 : _j.application),
42425
- se02: imageVersion((_k = info.se2) === null || _k === void 0 ? void 0 : _k.application),
42426
- se03: imageVersion((_l = info.se3) === null || _l === void 0 ? void 0 : _l.application),
42427
- se04: imageVersion((_m = info.se4) === null || _m === void 0 ? void 0 : _m.application),
42428
- se01Boot: imageVersion((_o = info.se1) === null || _o === void 0 ? void 0 : _o.bootloader),
42429
- se02Boot: imageVersion((_p = info.se2) === null || _p === void 0 ? void 0 : _p.bootloader),
42430
- se03Boot: imageVersion((_q = info.se3) === null || _q === void 0 ? void 0 : _q.bootloader),
42431
- se04Boot: imageVersion((_r = info.se4) === null || _r === void 0 ? void 0 : _r.bootloader),
42623
+ firmware: imageVersion((_d = info.fw) === null || _d === void 0 ? void 0 : _d.application),
42624
+ applicationP1: imageVersion((_e = info.fw) === null || _e === void 0 ? void 0 : _e.application),
42625
+ applicationP2: imageVersion((_f = info.fw) === null || _f === void 0 ? void 0 : _f.application_data),
42626
+ bootloader: imageVersion((_g = info.fw) === null || _g === void 0 ? void 0 : _g.bootloader),
42627
+ board: imageVersion((_h = info.fw) === null || _h === void 0 ? void 0 : _h.romloader),
42628
+ ble: imageVersion((_j = info.coprocessor) === null || _j === void 0 ? void 0 : _j.application),
42629
+ se01: imageVersion((_k = info.se1) === null || _k === void 0 ? void 0 : _k.application),
42630
+ se02: imageVersion((_l = info.se2) === null || _l === void 0 ? void 0 : _l.application),
42631
+ se03: imageVersion((_m = info.se3) === null || _m === void 0 ? void 0 : _m.application),
42632
+ se04: imageVersion((_o = info.se4) === null || _o === void 0 ? void 0 : _o.application),
42633
+ se01Boot: imageVersion((_p = info.se1) === null || _p === void 0 ? void 0 : _p.bootloader),
42634
+ se02Boot: imageVersion((_q = info.se2) === null || _q === void 0 ? void 0 : _q.bootloader),
42635
+ se03Boot: imageVersion((_r = info.se3) === null || _r === void 0 ? void 0 : _r.bootloader),
42636
+ se04Boot: imageVersion((_s = info.se4) === null || _s === void 0 ? void 0 : _s.bootloader),
42432
42637
  }),
42433
42638
  verification: definedEntries({
42434
- firmwareBuildId: imageBuildId((_s = info.fw) === null || _s === void 0 ? void 0 : _s.application),
42435
- firmwareHash: imageHash((_t = info.fw) === null || _t === void 0 ? void 0 : _t.application),
42436
- applicationP1BuildId: imageBuildId((_u = info.fw) === null || _u === void 0 ? void 0 : _u.application),
42437
- applicationP1Hash: imageHash((_v = info.fw) === null || _v === void 0 ? void 0 : _v.application),
42438
- applicationP2BuildId: imageBuildId((_w = info.fw) === null || _w === void 0 ? void 0 : _w.application_data),
42439
- applicationP2Hash: imageHash((_x = info.fw) === null || _x === void 0 ? void 0 : _x.application_data),
42440
- bootloaderBuildId: imageBuildId((_y = info.fw) === null || _y === void 0 ? void 0 : _y.bootloader),
42441
- bootloaderHash: imageHash((_z = info.fw) === null || _z === void 0 ? void 0 : _z.bootloader),
42442
- boardBuildId: imageBuildId((_0 = info.fw) === null || _0 === void 0 ? void 0 : _0.romloader),
42443
- boardHash: imageHash((_1 = info.fw) === null || _1 === void 0 ? void 0 : _1.romloader),
42444
- bleBuildId: imageBuildId((_2 = info.coprocessor) === null || _2 === void 0 ? void 0 : _2.application),
42445
- bleHash: imageHash((_3 = info.coprocessor) === null || _3 === void 0 ? void 0 : _3.application),
42446
- se01BuildId: imageBuildId((_4 = info.se1) === null || _4 === void 0 ? void 0 : _4.application),
42447
- se01Hash: imageHash((_5 = info.se1) === null || _5 === void 0 ? void 0 : _5.application),
42448
- se02BuildId: imageBuildId((_6 = info.se2) === null || _6 === void 0 ? void 0 : _6.application),
42449
- se02Hash: imageHash((_7 = info.se2) === null || _7 === void 0 ? void 0 : _7.application),
42450
- se03BuildId: imageBuildId((_8 = info.se3) === null || _8 === void 0 ? void 0 : _8.application),
42451
- se03Hash: imageHash((_9 = info.se3) === null || _9 === void 0 ? void 0 : _9.application),
42452
- se04BuildId: imageBuildId((_10 = info.se4) === null || _10 === void 0 ? void 0 : _10.application),
42453
- se04Hash: imageHash((_11 = info.se4) === null || _11 === void 0 ? void 0 : _11.application),
42454
- se01BootBuildId: imageBuildId((_12 = info.se1) === null || _12 === void 0 ? void 0 : _12.bootloader),
42455
- se01BootHash: imageHash((_13 = info.se1) === null || _13 === void 0 ? void 0 : _13.bootloader),
42456
- se02BootBuildId: imageBuildId((_14 = info.se2) === null || _14 === void 0 ? void 0 : _14.bootloader),
42457
- se02BootHash: imageHash((_15 = info.se2) === null || _15 === void 0 ? void 0 : _15.bootloader),
42458
- se03BootBuildId: imageBuildId((_16 = info.se3) === null || _16 === void 0 ? void 0 : _16.bootloader),
42459
- se03BootHash: imageHash((_17 = info.se3) === null || _17 === void 0 ? void 0 : _17.bootloader),
42460
- se04BootBuildId: imageBuildId((_18 = info.se4) === null || _18 === void 0 ? void 0 : _18.bootloader),
42461
- se04BootHash: imageHash((_19 = info.se4) === null || _19 === void 0 ? void 0 : _19.bootloader),
42639
+ firmwareBuildId: imageBuildId((_t = info.fw) === null || _t === void 0 ? void 0 : _t.application),
42640
+ firmwareHash: imageHash((_u = info.fw) === null || _u === void 0 ? void 0 : _u.application),
42641
+ applicationP1BuildId: imageBuildId((_v = info.fw) === null || _v === void 0 ? void 0 : _v.application),
42642
+ applicationP1Hash: imageHash((_w = info.fw) === null || _w === void 0 ? void 0 : _w.application),
42643
+ applicationP2BuildId: imageBuildId((_x = info.fw) === null || _x === void 0 ? void 0 : _x.application_data),
42644
+ applicationP2Hash: imageHash((_y = info.fw) === null || _y === void 0 ? void 0 : _y.application_data),
42645
+ bootloaderBuildId: imageBuildId((_z = info.fw) === null || _z === void 0 ? void 0 : _z.bootloader),
42646
+ bootloaderHash: imageHash((_0 = info.fw) === null || _0 === void 0 ? void 0 : _0.bootloader),
42647
+ boardBuildId: imageBuildId((_1 = info.fw) === null || _1 === void 0 ? void 0 : _1.romloader),
42648
+ boardHash: imageHash((_2 = info.fw) === null || _2 === void 0 ? void 0 : _2.romloader),
42649
+ bleBuildId: imageBuildId((_3 = info.coprocessor) === null || _3 === void 0 ? void 0 : _3.application),
42650
+ bleHash: imageHash((_4 = info.coprocessor) === null || _4 === void 0 ? void 0 : _4.application),
42651
+ se01BuildId: imageBuildId((_5 = info.se1) === null || _5 === void 0 ? void 0 : _5.application),
42652
+ se01Hash: imageHash((_6 = info.se1) === null || _6 === void 0 ? void 0 : _6.application),
42653
+ se02BuildId: imageBuildId((_7 = info.se2) === null || _7 === void 0 ? void 0 : _7.application),
42654
+ se02Hash: imageHash((_8 = info.se2) === null || _8 === void 0 ? void 0 : _8.application),
42655
+ se03BuildId: imageBuildId((_9 = info.se3) === null || _9 === void 0 ? void 0 : _9.application),
42656
+ se03Hash: imageHash((_10 = info.se3) === null || _10 === void 0 ? void 0 : _10.application),
42657
+ se04BuildId: imageBuildId((_11 = info.se4) === null || _11 === void 0 ? void 0 : _11.application),
42658
+ se04Hash: imageHash((_12 = info.se4) === null || _12 === void 0 ? void 0 : _12.application),
42659
+ se01BootBuildId: imageBuildId((_13 = info.se1) === null || _13 === void 0 ? void 0 : _13.bootloader),
42660
+ se01BootHash: imageHash((_14 = info.se1) === null || _14 === void 0 ? void 0 : _14.bootloader),
42661
+ se02BootBuildId: imageBuildId((_15 = info.se2) === null || _15 === void 0 ? void 0 : _15.bootloader),
42662
+ se02BootHash: imageHash((_16 = info.se2) === null || _16 === void 0 ? void 0 : _16.bootloader),
42663
+ se03BootBuildId: imageBuildId((_17 = info.se3) === null || _17 === void 0 ? void 0 : _17.bootloader),
42664
+ se03BootHash: imageHash((_18 = info.se3) === null || _18 === void 0 ? void 0 : _18.bootloader),
42665
+ se04BootBuildId: imageBuildId((_19 = info.se4) === null || _19 === void 0 ? void 0 : _19.bootloader),
42666
+ se04BootHash: imageHash((_20 = info.se4) === null || _20 === void 0 ? void 0 : _20.bootloader),
42462
42667
  }),
42463
42668
  raw: Object.assign({ protocolV2DeviceInfo: info }, (loader ? { protocolV2DeviceStatus: null } : {})),
42464
42669
  };
@@ -42568,13 +42773,11 @@ const projectFeatures = (state) => {
42568
42773
  delete publicRawFeatures.session_id;
42569
42774
  delete publicRawFeatures.sessionId;
42570
42775
  delete publicRawFeatures.passphraseState;
42571
- const publicRaw = snapshot.raw
42572
- ? Object.assign(Object.assign({}, snapshot.raw), { protocolV1Features: publicRawFeatures }) : undefined;
42573
42776
  const rawOneKeyFeatures = (_d = (_c = snapshot.raw) === null || _c === void 0 ? void 0 : _c.protocolV1OneKeyFeatures) !== null && _d !== void 0 ? _d : {};
42574
42777
  const bootloaderMode = snapshot.protocol === 'V1'
42575
42778
  ? (_e = rawFeatures.bootloader_mode) !== null && _e !== void 0 ? _e : null
42576
42779
  : getBootloaderMode(snapshot);
42577
- return Object.assign(Object.assign(Object.assign({}, publicRawFeatures), rawOneKeyFeatures), { protocol: snapshot.protocol, protocolVersion: (_f = snapshot.protocolVersion) !== null && _f !== void 0 ? _f : (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: (_g = snapshot.status.unlockedAttachPin) !== null && _g !== void 0 ? _g : 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: (_h = snapshot.versions.se) !== null && _h !== void 0 ? _h : null, verify: snapshot.verification, raw: publicRaw, device_id: (_j = snapshot.identity.deviceId) !== null && _j !== void 0 ? _j : undefined, ble_name: (_k = snapshot.identity.bleName) !== null && _k !== void 0 ? _k : undefined, passphrase_protection: (_l = snapshot.status.passphraseProtection) !== null && _l !== void 0 ? _l : undefined, bootloader_mode: bootloaderMode, sessionId: null, session_id: null });
42780
+ return Object.assign(Object.assign(Object.assign({}, publicRawFeatures), rawOneKeyFeatures), { protocol: snapshot.protocol, protocolVersion: (_f = snapshot.protocolVersion) !== null && _f !== void 0 ? _f : (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: (_g = snapshot.status.unlockedAttachPin) !== null && _g !== void 0 ? _g : 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: (_h = snapshot.versions.se) !== null && _h !== void 0 ? _h : null, verify: snapshot.verification, device_id: (_j = snapshot.identity.deviceId) !== null && _j !== void 0 ? _j : undefined, ble_name: (_k = snapshot.identity.bleName) !== null && _k !== void 0 ? _k : undefined, passphrase_protection: (_l = snapshot.status.passphraseProtection) !== null && _l !== void 0 ? _l : undefined, bootloader_mode: bootloaderMode, sessionId: null, session_id: null });
42578
42781
  };
42579
42782
 
42580
42783
  function createEmptyDeviceState(identity = {}) {
@@ -42730,6 +42933,7 @@ const createPublicDeviceState = (state) => {
42730
42933
  class DeviceWalletSessionStore {
42731
42934
  constructor() {
42732
42935
  this.walletSessions = new Map();
42936
+ this.standardWalletSessions = new Map();
42733
42937
  this.pendingSessions = new Map();
42734
42938
  }
42735
42939
  get(deviceKey, passphraseState) {
@@ -42739,6 +42943,7 @@ class DeviceWalletSessionStore {
42739
42943
  return (_a = this.walletSessions.get(deviceKey)) === null || _a === void 0 ? void 0 : _a.get(passphraseState);
42740
42944
  }
42741
42945
  set(deviceKey, passphraseState, sessionId) {
42946
+ var _a;
42742
42947
  if (!deviceKey || !passphraseState || !sessionId)
42743
42948
  return;
42744
42949
  let deviceSessions = this.walletSessions.get(deviceKey);
@@ -42746,8 +42951,29 @@ class DeviceWalletSessionStore {
42746
42951
  deviceSessions = new Map();
42747
42952
  this.walletSessions.set(deviceKey, deviceSessions);
42748
42953
  }
42954
+ if (!deviceSessions.has(passphraseState) &&
42955
+ deviceSessions.size >= DeviceWalletSessionStore.MAX_SESSIONS_PER_DEVICE) {
42956
+ const oldestPassphraseState = deviceSessions.keys().next().value;
42957
+ if (oldestPassphraseState) {
42958
+ deviceSessions.delete(oldestPassphraseState);
42959
+ if (((_a = this.standardWalletSessions.get(deviceKey)) === null || _a === void 0 ? void 0 : _a.passphraseState) === oldestPassphraseState) {
42960
+ this.standardWalletSessions.delete(deviceKey);
42961
+ }
42962
+ }
42963
+ }
42749
42964
  deviceSessions.set(passphraseState, sessionId);
42750
42965
  }
42966
+ getStandard(deviceKey) {
42967
+ if (!deviceKey)
42968
+ return undefined;
42969
+ return this.standardWalletSessions.get(deviceKey);
42970
+ }
42971
+ setStandard(deviceKey, passphraseState, sessionId) {
42972
+ if (!deviceKey || !passphraseState || !sessionId)
42973
+ return;
42974
+ this.set(deviceKey, passphraseState, sessionId);
42975
+ this.standardWalletSessions.set(deviceKey, { passphraseState, sessionId });
42976
+ }
42751
42977
  setPending(deviceKey, sessionId) {
42752
42978
  if (!deviceKey || !sessionId)
42753
42979
  return;
@@ -42761,6 +42987,10 @@ class DeviceWalletSessionStore {
42761
42987
  delete(deviceKey, passphraseState) {
42762
42988
  if (!deviceKey || !passphraseState)
42763
42989
  return;
42990
+ const standardWalletSession = this.standardWalletSessions.get(deviceKey);
42991
+ if ((standardWalletSession === null || standardWalletSession === void 0 ? void 0 : standardWalletSession.passphraseState) === passphraseState) {
42992
+ this.standardWalletSessions.delete(deviceKey);
42993
+ }
42764
42994
  const deviceSessions = this.walletSessions.get(deviceKey);
42765
42995
  if (!deviceSessions)
42766
42996
  return;
@@ -42769,6 +42999,15 @@ class DeviceWalletSessionStore {
42769
42999
  this.walletSessions.delete(deviceKey);
42770
43000
  }
42771
43001
  }
43002
+ deleteStandard(deviceKey) {
43003
+ if (!deviceKey)
43004
+ return;
43005
+ const standardWalletSession = this.standardWalletSessions.get(deviceKey);
43006
+ this.standardWalletSessions.delete(deviceKey);
43007
+ if (standardWalletSession) {
43008
+ this.delete(deviceKey, standardWalletSession.passphraseState);
43009
+ }
43010
+ }
42772
43011
  deletePending(deviceKey) {
42773
43012
  if (!deviceKey)
42774
43013
  return;
@@ -42778,23 +43017,28 @@ class DeviceWalletSessionStore {
42778
43017
  if (!deviceKey)
42779
43018
  return;
42780
43019
  this.walletSessions.delete(deviceKey);
43020
+ this.standardWalletSessions.delete(deviceKey);
42781
43021
  this.pendingSessions.delete(deviceKey);
42782
43022
  }
42783
43023
  migrateTemporaryDeviceKey(from, to) {
42784
- var _a;
42785
43024
  if (!from || !to || from === to)
42786
43025
  return;
42787
43026
  const sourceSessions = this.walletSessions.get(from);
42788
43027
  if (sourceSessions) {
42789
- const targetSessions = (_a = this.walletSessions.get(to)) !== null && _a !== void 0 ? _a : new Map();
42790
- this.walletSessions.set(to, targetSessions);
42791
43028
  sourceSessions.forEach((sessionId, passphraseState) => {
42792
- if (!targetSessions.has(passphraseState)) {
42793
- targetSessions.set(passphraseState, sessionId);
43029
+ if (!this.get(to, passphraseState)) {
43030
+ this.set(to, passphraseState, sessionId);
42794
43031
  }
42795
43032
  });
42796
43033
  this.walletSessions.delete(from);
42797
43034
  }
43035
+ const standardWalletSession = this.standardWalletSessions.get(from);
43036
+ if (standardWalletSession &&
43037
+ !this.standardWalletSessions.has(to) &&
43038
+ this.get(to, standardWalletSession.passphraseState) === standardWalletSession.sessionId) {
43039
+ this.standardWalletSessions.set(to, standardWalletSession);
43040
+ }
43041
+ this.standardWalletSessions.delete(from);
42798
43042
  const pendingSession = this.pendingSessions.get(from);
42799
43043
  if (pendingSession && !this.pendingSessions.has(to)) {
42800
43044
  this.pendingSessions.set(to, pendingSession);
@@ -42814,9 +43058,11 @@ class DeviceWalletSessionStore {
42814
43058
  }
42815
43059
  clear() {
42816
43060
  this.walletSessions.clear();
43061
+ this.standardWalletSessions.clear();
42817
43062
  this.pendingSessions.clear();
42818
43063
  }
42819
43064
  }
43065
+ DeviceWalletSessionStore.MAX_SESSIONS_PER_DEVICE = 3;
42820
43066
  const deviceWalletSessionStore = new DeviceWalletSessionStore();
42821
43067
 
42822
43068
  const getProtocolV2RuntimeMode = ({ deviceInfo: _deviceInfo, deviceStatusAvailable, }) => {
@@ -42947,7 +43193,7 @@ class Device extends events.exports {
42947
43193
  }
42948
43194
  toMessageObject() {
42949
43195
  var _a;
42950
- if (this.isUnacquired())
43196
+ if (this.isUnacquired() || !this.features)
42951
43197
  return null;
42952
43198
  const env = DataManager.getSettings('env');
42953
43199
  const deviceType = this.getCurrentDeviceType();
@@ -42960,6 +43206,7 @@ class Device extends events.exports {
42960
43206
  const state = this.state ? createPublicDeviceState(this.state) : undefined;
42961
43207
  return {
42962
43208
  connectId: DataManager.isBleConnect(env) ? this.mainId || null : connectId,
43209
+ connectProtocol: this.originalDescriptor.protocolType,
42963
43210
  serialNo,
42964
43211
  uuid: serialNo,
42965
43212
  commType: this.originalDescriptor.commType,
@@ -43015,21 +43262,21 @@ class Device extends events.exports {
43015
43262
  resolve(false);
43016
43263
  }));
43017
43264
  }
43018
- acquire(connectProtocol, options) {
43265
+ acquire(expectedProtocol, options) {
43019
43266
  var _a, _b, _c, _d, _e, _f, _g;
43020
43267
  return __awaiter(this, void 0, void 0, function* () {
43021
43268
  const env = DataManager.getSettings('env');
43022
43269
  const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
43023
- const expectedProtocol = connectProtocol !== null && connectProtocol !== void 0 ? connectProtocol : this.originalDescriptor.protocolType;
43270
+ const protocolHint = expectedProtocol ? undefined : this.originalDescriptor.protocolType;
43024
43271
  try {
43025
43272
  let acquireResult;
43026
43273
  if (DataManager.isBleConnect(env)) {
43027
- acquireResult = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id, undefined, true, expectedProtocol));
43274
+ acquireResult = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id, undefined, true, expectedProtocol, protocolHint));
43028
43275
  this.mainId = (_b = acquireResult === null || acquireResult === void 0 ? void 0 : acquireResult.uuid) !== null && _b !== void 0 ? _b : '';
43029
43276
  Log$e.debug('Expected uuid:', this.mainId);
43030
43277
  }
43031
43278
  else {
43032
- acquireResult = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session, undefined, expectedProtocol));
43279
+ acquireResult = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session, undefined, expectedProtocol, protocolHint));
43033
43280
  this.mainId = acquireResult;
43034
43281
  Log$e.debug('Expected session id:', this.mainId);
43035
43282
  }
@@ -43299,14 +43546,25 @@ class Device extends events.exports {
43299
43546
  return undefined;
43300
43547
  return deviceWalletSessionStore.get(deviceId, this.passphraseState);
43301
43548
  }
43302
- updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
43549
+ getStandardInternalState(_deviceId) {
43550
+ const deviceId = this.getSessionCacheDeviceKey(_deviceId);
43551
+ if (!deviceId)
43552
+ return undefined;
43553
+ return deviceWalletSessionStore.getStandard(deviceId);
43554
+ }
43555
+ updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null, walletType = 'hidden') {
43303
43556
  Log$e.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `hasPassphraseState: ${Boolean(passphraseState)}`, `hasSessionId: ${Boolean(sessionId)}`, `hasFeaturesSessionId: ${Boolean(featuresSessionId)}`);
43304
43557
  const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
43305
43558
  if (!cacheDeviceKey)
43306
43559
  return;
43307
43560
  if (enablePassphrase) {
43308
43561
  const walletSessionId = sessionId || featuresSessionId || deviceWalletSessionStore.getPending(cacheDeviceKey);
43309
- deviceWalletSessionStore.set(cacheDeviceKey, passphraseState, walletSessionId !== null && walletSessionId !== void 0 ? walletSessionId : undefined);
43562
+ if (walletType === 'standard') {
43563
+ deviceWalletSessionStore.setStandard(cacheDeviceKey, passphraseState, walletSessionId !== null && walletSessionId !== void 0 ? walletSessionId : undefined);
43564
+ }
43565
+ else {
43566
+ deviceWalletSessionStore.set(cacheDeviceKey, passphraseState, walletSessionId !== null && walletSessionId !== void 0 ? walletSessionId : undefined);
43567
+ }
43310
43568
  }
43311
43569
  deviceWalletSessionStore.deletePending(cacheDeviceKey);
43312
43570
  }
@@ -43334,6 +43592,12 @@ class Device extends events.exports {
43334
43592
  deviceWalletSessionStore.delete(deviceId, this.passphraseState);
43335
43593
  }
43336
43594
  }
43595
+ clearStandardInternalState(_deviceId) {
43596
+ const deviceId = this.getSessionCacheDeviceKey(_deviceId);
43597
+ if (!deviceId)
43598
+ return;
43599
+ deviceWalletSessionStore.deleteStandard(deviceId);
43600
+ }
43337
43601
  initialize(options) {
43338
43602
  return __awaiter(this, void 0, void 0, function* () {
43339
43603
  if (this.isProtocolV2()) {
@@ -43361,7 +43625,9 @@ class Device extends events.exports {
43361
43625
  const expectedDeviceId = options === null || options === void 0 ? void 0 : options.deviceId;
43362
43626
  if (expectedDeviceId) {
43363
43627
  this.passphraseState = undefined;
43364
- yield callInitialize({ is_contains_attach: true });
43628
+ const { message } = yield this.commands.typedCall('GetFeatures', 'Features', {});
43629
+ this._updateFeatures(message);
43630
+ yield TransportManager.reconfigure(this.features);
43365
43631
  if (!this.checkDeviceId(expectedDeviceId)) {
43366
43632
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError);
43367
43633
  }
@@ -44655,8 +44921,7 @@ class GetPassphraseState extends BaseMethod {
44655
44921
  initSession: this.payload.initSession === true,
44656
44922
  }
44657
44923
  : undefined);
44658
- const passphraseProtection = this.device.getCurrentPassphraseProtection();
44659
- return Promise.resolve(passphraseProtection === true ? passphraseState : undefined);
44924
+ return passphraseState;
44660
44925
  });
44661
44926
  }
44662
44927
  }
@@ -44697,7 +44962,7 @@ const formatAnyHex = value => {
44697
44962
  return value;
44698
44963
  };
44699
44964
  const hexes = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
44700
- function bytesToHex$2(uint8a) {
44965
+ function bytesToHex$1(uint8a) {
44701
44966
  if (!(uint8a instanceof Uint8Array))
44702
44967
  throw new Error('Uint8Array expected');
44703
44968
  let hex = '';
@@ -44902,7 +45167,7 @@ class OpenWalletSession extends BaseMethod {
44902
45167
  this.payload.useEmptyPassphrase = this.params.mode === OpenWalletSessionMode.Standard;
44903
45168
  }
44904
45169
  run() {
44905
- var _a;
45170
+ var _a, _b;
44906
45171
  return __awaiter(this, void 0, void 0, function* () {
44907
45172
  const isProtocolV2 = this.device.isProtocolV2();
44908
45173
  const state = yield this.device.getDeviceState({ refreshSections: ['status'] });
@@ -44932,7 +45197,7 @@ class OpenWalletSession extends BaseMethod {
44932
45197
  try {
44933
45198
  yield this.device.lockDevice();
44934
45199
  }
44935
- catch (_b) {
45200
+ catch (_c) {
44936
45201
  }
44937
45202
  this.device.clearInternalState();
44938
45203
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError);
@@ -44941,13 +45206,13 @@ class OpenWalletSession extends BaseMethod {
44941
45206
  protocol,
44942
45207
  walletType: 'standard',
44943
45208
  deviceId,
44944
- passphraseState: null,
45209
+ passphraseState: (_a = session.passphraseState) !== null && _a !== void 0 ? _a : null,
44945
45210
  resumed: wasResumed(session),
44946
45211
  };
44947
45212
  }
44948
45213
  if (this.params.mode === OpenWalletSessionMode.ResumeHidden) {
44949
45214
  if (isProtocolV2) {
44950
- if (((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.unlocked) === false) {
45215
+ if (((_b = this.device.features) === null || _b === void 0 ? void 0 : _b.unlocked) === false) {
44951
45216
  yield this.device.unlockDevice();
44952
45217
  }
44953
45218
  const refreshedDeviceId = yield refreshProtocolV2DeviceId();
@@ -44978,7 +45243,7 @@ class OpenWalletSession extends BaseMethod {
44978
45243
  expectPassphraseState: this.params.passphraseState,
44979
45244
  });
44980
45245
  const deviceId = requireDeviceId();
44981
- if (!session.passphraseState) {
45246
+ if (session.passphraseState !== this.params.passphraseState) {
44982
45247
  this.device.clearInternalState();
44983
45248
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
44984
45249
  }
@@ -44994,7 +45259,7 @@ class OpenWalletSession extends BaseMethod {
44994
45259
  deviceId,
44995
45260
  resumed: wasResumed(session),
44996
45261
  };
44997
- return this.device.getCurrentPassphraseProtection() === false
45262
+ return !isProtocolV2 && this.device.getCurrentPassphraseProtection() === false
44998
45263
  ? Object.assign(Object.assign({}, responseBase), { walletType: 'standard', passphraseState: null }) : Object.assign(Object.assign(Object.assign({}, responseBase), { walletType: 'hidden' }), requireHiddenWalletResponse(session));
44999
45264
  });
45000
45265
  }
@@ -45256,41 +45521,10 @@ const CURRENT_HASH_BY_COMPONENT_TARGET = {
45256
45521
  APPLICATION_P1: 'applicationP1Hash',
45257
45522
  APPLICATION_P2: 'applicationP2Hash',
45258
45523
  };
45259
- const PROTOCOL_V2_PACKAGE_METADATA_END = 0x27f;
45260
- const PROTOCOL_V2_PACKAGE_PAYLOAD_HASH_OFFSET = 0x200;
45261
- const PROTOCOL_V2_PACKAGE_PAYLOAD_HASH_SIZE = 64;
45262
- function bytesToHex$1(bytes) {
45263
- return Array.from(bytes)
45264
- .map(byte => byte.toString(16).padStart(2, '0'))
45265
- .join('');
45266
- }
45267
45524
  function normalizeHex(value) {
45268
45525
  const normalized = value === null || value === void 0 ? void 0 : value.replace(/^0x/i, '').toLowerCase();
45269
45526
  return normalized && /^[0-9a-f]+$/.test(normalized) ? normalized : undefined;
45270
45527
  }
45271
- function getRemoteComponentPayloadHash(url) {
45272
- return __awaiter(this, void 0, void 0, function* () {
45273
- try {
45274
- const binary = yield httpRequest$1(url, 'binary', {
45275
- headers: { Range: `bytes=0-${PROTOCOL_V2_PACKAGE_METADATA_END}` },
45276
- connectTimeoutMs: 5000,
45277
- readTimeoutMs: 5000,
45278
- overallTimeoutMs: 10000,
45279
- maxRetries: 1,
45280
- retryDelayMs: 250,
45281
- });
45282
- const bytes = new Uint8Array(binary);
45283
- if (bytes.byteLength <= PROTOCOL_V2_PACKAGE_METADATA_END ||
45284
- String.fromCharCode(...bytes.slice(0, 4)) !== 'OKPP') {
45285
- return null;
45286
- }
45287
- return bytesToHex$1(bytes.slice(PROTOCOL_V2_PACKAGE_PAYLOAD_HASH_OFFSET, PROTOCOL_V2_PACKAGE_PAYLOAD_HASH_OFFSET + PROTOCOL_V2_PACKAGE_PAYLOAD_HASH_SIZE));
45288
- }
45289
- catch (_a) {
45290
- return null;
45291
- }
45292
- });
45293
- }
45294
45528
  function toVersionString(version) {
45295
45529
  return (version === null || version === void 0 ? void 0 : version.length) ? version.join('.') : null;
45296
45530
  }
@@ -45331,20 +45565,22 @@ function buildComponentRelease({ configKey, component, currentVersions, currentV
45331
45565
  else if (semver__default["default"].gt(currentVersion, targetVersion)) {
45332
45566
  status = 'valid';
45333
45567
  }
45334
- else if (remotePayloadHash !== undefined) {
45568
+ else {
45335
45569
  const currentHashKey = CURRENT_HASH_BY_COMPONENT_TARGET[componentTarget];
45336
- const currentHash = normalizeHex(currentHashKey ? currentVerification[currentHashKey] : undefined);
45337
- const expectedHash = normalizeHex(remotePayloadHash !== null && remotePayloadHash !== void 0 ? remotePayloadHash : undefined);
45338
- if (currentHash && expectedHash) {
45339
- status = expectedHash.startsWith(currentHash) ? 'valid' : 'outdated';
45570
+ if (!currentHashKey) {
45571
+ status = 'valid';
45340
45572
  }
45341
45573
  else {
45342
- status = 'unknown';
45574
+ const currentHash = normalizeHex(currentVerification[currentHashKey]);
45575
+ const expectedHash = normalizeHex(remotePayloadHash !== null && remotePayloadHash !== void 0 ? remotePayloadHash : undefined);
45576
+ if (currentHash && expectedHash) {
45577
+ status = expectedHash.startsWith(currentHash) ? 'valid' : 'outdated';
45578
+ }
45579
+ else {
45580
+ status = 'unknown';
45581
+ }
45343
45582
  }
45344
45583
  }
45345
- else {
45346
- status = 'valid';
45347
- }
45348
45584
  }
45349
45585
  return {
45350
45586
  configKey,
@@ -45377,7 +45613,7 @@ function buildProtocolV2FirmwareRelease({ currentVersions, currentVerification =
45377
45613
  currentVerification,
45378
45614
  remotePayloadHash: Object.prototype.hasOwnProperty.call(remotePayloadHashes, configKey)
45379
45615
  ? remotePayloadHashes[configKey]
45380
- : undefined,
45616
+ : normalizeHex(component.payloadHash),
45381
45617
  releaseRequired: release.required,
45382
45618
  }));
45383
45619
  if (!currentVersions.applicationP2) {
@@ -45492,37 +45728,9 @@ class CheckAllFirmwareRelease extends BaseMethod {
45492
45728
  const { firmwareType: firmwareTypeParam } = this.payload;
45493
45729
  const firmwareType = (_a = firmwareTypeParam !== null && firmwareTypeParam !== void 0 ? firmwareTypeParam : state.identity.firmwareType) !== null && _a !== void 0 ? _a : hdShared.EFirmwareType.Universal;
45494
45730
  const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
45495
- const remotePayloadHashes = {};
45496
- if (release) {
45497
- yield Promise.all(getOrderedComponentEntries(release).map(([configKey, component]) => __awaiter(this, void 0, void 0, function* () {
45498
- var _b;
45499
- const componentTarget = component.target.toUpperCase();
45500
- if (!CURRENT_HASH_BY_COMPONENT_TARGET[componentTarget])
45501
- return;
45502
- const currentVersionKey = CURRENT_VERSION_BY_COMPONENT_TARGET[componentTarget];
45503
- const currentVersion = currentVersionKey
45504
- ? (_b = state.versions[currentVersionKey]) !== null && _b !== void 0 ? _b : (componentTarget === 'APPLICATION_P1' ? state.versions.firmware : null)
45505
- : null;
45506
- const targetVersion = toVersionString(component.version);
45507
- if (currentVersion &&
45508
- targetVersion &&
45509
- semver__default["default"].valid(currentVersion) &&
45510
- semver__default["default"].valid(targetVersion) &&
45511
- semver__default["default"].eq(currentVersion, targetVersion)) {
45512
- const configuredPayloadHash = normalizeHex(component.payloadHash);
45513
- if (configuredPayloadHash) {
45514
- remotePayloadHashes[configKey] = configuredPayloadHash;
45515
- }
45516
- else if (component.fingerprint && component.url) {
45517
- remotePayloadHashes[configKey] = yield getRemoteComponentPayloadHash(component.url);
45518
- }
45519
- }
45520
- })));
45521
- }
45522
45731
  const plan = buildProtocolV2FirmwareRelease({
45523
45732
  currentVersions: state.versions,
45524
45733
  currentVerification: state.verification,
45525
- remotePayloadHashes,
45526
45734
  firmwareType,
45527
45735
  release,
45528
45736
  });
@@ -46012,7 +46220,11 @@ class DeviceSettings extends BaseMethod {
46012
46220
  page: hdTransport.DeviceSettingsPage.DevicePassphrase,
46013
46221
  });
46014
46222
  const updated = yield this.device.getDeviceState({ refreshSections: ['status'] });
46015
- if (updated.status.passphraseProtection !== requestedPassphrase) {
46223
+ const lockedAfterDisabling = requestedPassphrase === false &&
46224
+ current.status.unlocked === true &&
46225
+ updated.status.unlocked === false;
46226
+ if (updated.status.passphraseProtection !== requestedPassphrase &&
46227
+ !lockedAfterDisabling) {
46016
46228
  throw hdShared.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 passphrase setting did not reach the requested value.');
46017
46229
  }
46018
46230
  return res.message;
@@ -46465,7 +46677,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload, r
46465
46677
  const header = new Uint8Array(payload.slice(0, HEADER_SIZE));
46466
46678
  try {
46467
46679
  const headerRes = yield typedCall('UpgradeFileHeader', 'Success', {
46468
- data: bytesToHex$2(header),
46680
+ data: bytesToHex$1(header),
46469
46681
  });
46470
46682
  const isUnknownMessage = (_b = (_a = headerRes.message) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.includes('Failure_UnknownMessage');
46471
46683
  if (headerRes.type !== 'Success' && !isUnknownMessage) {
@@ -46714,8 +46926,8 @@ const processResourceRequest = (typedCall, res, data) => __awaiter(void 0, void
46714
46926
  const payload = new Uint8Array(data.slice(offset, Math.min(offset + data_length, data.byteLength)));
46715
46927
  const digest = blake2s.blake2s(payload);
46716
46928
  const resourceAckParams = {
46717
- data_chunk: bytesToHex$2(payload),
46718
- hash: bytesToHex$2(digest),
46929
+ data_chunk: bytesToHex$1(payload),
46930
+ hash: bytesToHex$1(digest),
46719
46931
  };
46720
46932
  const response = yield typedCall('ResourceAck', ['ResourceRequest', 'Success'], Object.assign({}, resourceAckParams));
46721
46933
  return processResourceRequest(typedCall, response, data);
@@ -46726,8 +46938,8 @@ const updateResource = (typedCall, fileName, data, onConfirmAfter) => __awaiter(
46726
46938
  const res = yield typedCall('ResourceUpdate', ['ResourceRequest', 'Success'], {
46727
46939
  file_name: fileName,
46728
46940
  data_length: data.byteLength,
46729
- initial_data_chunk: bytesToHex$2(chunk),
46730
- hash: bytesToHex$2(digest),
46941
+ initial_data_chunk: bytesToHex$1(chunk),
46942
+ hash: bytesToHex$1(digest),
46731
46943
  });
46732
46944
  onConfirmAfter === null || onConfirmAfter === void 0 ? void 0 : onConfirmAfter();
46733
46945
  return processResourceRequest(typedCall, res, data);
@@ -48896,7 +49108,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
48896
49108
  });
48897
49109
  }
48898
49110
  prepareRemoteProtocolV2Binaries(firmwareType, features) {
48899
- var _a;
49111
+ var _a, _b;
48900
49112
  return __awaiter(this, void 0, void 0, function* () {
48901
49113
  const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
48902
49114
  let bootloaderBinary = null;
@@ -48912,10 +49124,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
48912
49124
  const entries = this.getRemoteComponentEntries(release);
48913
49125
  const targetsToUpdate = new Set((_a = this.params.targetsToUpdate) !== null && _a !== void 0 ? _a : []);
48914
49126
  for (const [key, component] of entries) {
48915
- const target = this.getRemoteComponentTarget(key, component);
48916
- const updateTarget = PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID.get(target.targetId);
48917
- const shouldInstall = updateTarget ? targetsToUpdate.has(updateTarget) : false;
48918
- if (shouldInstall) {
49127
+ const targetName = (_b = component.target) === null || _b === void 0 ? void 0 : _b.toUpperCase();
49128
+ const target = PROTOCOL_V2_REMOTE_COMPONENT_TARGETS[targetName];
49129
+ const updateTarget = target
49130
+ ? PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID.get(target.targetId)
49131
+ : undefined;
49132
+ if (updateTarget && targetsToUpdate.has(updateTarget)) {
48919
49133
  const remoteBinary = yield this.downloadRemoteProtocolV2Component(key, component);
48920
49134
  if (remoteBinary.kind === 'bootloader') {
48921
49135
  bootloaderBinary = remoteBinary.binary;
@@ -49290,7 +49504,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49290
49504
  while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
49291
49505
  try {
49292
49506
  yield this.reconnectProtocolV2Device();
49293
- yield this.verifyProtocolV2ReconnectIdentity();
49507
+ const deviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
49294
49508
  try {
49295
49509
  const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', {
49296
49510
  fields: {
@@ -49310,11 +49524,16 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49310
49524
  throw error;
49311
49525
  }
49312
49526
  if (isProtocolV2FirmwareStatusEndpointUnavailable(error)) {
49313
- Log$5.log('[FirmwareUpdateV4] firmware status endpoint unavailable after reboot; continue with normal-mode verification');
49314
- return;
49527
+ if (yield this.probeProtocolV2NormalMode(deviceInfo)) {
49528
+ Log$5.log('[FirmwareUpdateV4] firmware status endpoint unavailable after confirmed App reboot');
49529
+ return;
49530
+ }
49531
+ lastError = new Error('Protocol V2 firmware status endpoint is unavailable while the device remains in loader mode');
49532
+ }
49533
+ else {
49534
+ lastError = error;
49535
+ Log$5.log('[FirmwareUpdateV4] DeviceFirmwareUpdateStatusGet unavailable during install: ', error);
49315
49536
  }
49316
- lastError = error;
49317
- Log$5.log('[FirmwareUpdateV4] DeviceFirmwareUpdateStatusGet unavailable during install: ', error);
49318
49537
  }
49319
49538
  }
49320
49539
  catch (error) {
@@ -49339,6 +49558,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49339
49558
  yield this.protocolV2Reboot(hdTransport.DeviceRebootType.Normal);
49340
49559
  });
49341
49560
  }
49561
+ probeProtocolV2NormalMode(deviceInfo) {
49562
+ return __awaiter(this, void 0, void 0, function* () {
49563
+ const features = yield this.device.probeProtocolV2RuntimeState(deviceInfo, PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT);
49564
+ return features.mode === 'normal' && !features.bootloaderMode;
49565
+ });
49566
+ }
49342
49567
  waitForProtocolV2FinalFeatures() {
49343
49568
  return __awaiter(this, void 0, void 0, function* () {
49344
49569
  const features = yield this.waitForProtocolV2ReconnectAndFeatures(PROTOCOL_V2_FINAL_RECONNECT_TIMEOUT);
@@ -49521,9 +49746,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49521
49746
  const env = DataManager.getSettings('env');
49522
49747
  if (DataManager.isBleConnect(env)) {
49523
49748
  yield hdShared.wait(3000);
49524
- yield this.acquireProtocolV2BleDevice();
49525
- yield this.device.initialize();
49526
49749
  }
49750
+ yield this.reconnectProtocolV2Device();
49751
+ yield this.verifyProtocolV2ReconnectIdentity();
49752
+ yield this.device.initialize();
49527
49753
  yield hdShared.wait(2000);
49528
49754
  });
49529
49755
  }
@@ -57431,7 +57657,11 @@ class KaspaSignTransaction extends BaseMethod {
57431
57657
  });
57432
57658
  const outputs = payload.outputs.map(output => {
57433
57659
  var _a;
57660
+ const address = getOutputAddress(output);
57434
57661
  const addressN = getOutputAddressN(output);
57662
+ if (address !== undefined && addressN !== undefined) {
57663
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: outputs must not contain both address and addressN');
57664
+ }
57435
57665
  validateParams(output, [
57436
57666
  { name: 'satoshis', required: true },
57437
57667
  { name: 'address', type: 'string' },
@@ -57944,7 +58174,7 @@ class NostrSignEvent extends BaseMethod {
57944
58174
  const addressN = validatePath(payload.path, 5);
57945
58175
  this.params = {
57946
58176
  address_n: addressN,
57947
- event: bytesToHex$2(Buffer.from(JSON.stringify(payload.event, null, 0), 'utf-8')),
58177
+ event: bytesToHex$1(Buffer.from(JSON.stringify(payload.event, null, 0), 'utf-8')),
57948
58178
  };
57949
58179
  }
57950
58180
  getVersionRange() {
@@ -58135,8 +58365,8 @@ class LnurlAuth1 extends BaseMethod {
58135
58365
  { name: 'k1', type: 'string', required: true },
58136
58366
  ]);
58137
58367
  this.params = {
58138
- domain: bytesToHex$2(Buffer.from(payload.domain, 'utf-8')),
58139
- data: bytesToHex$2(Buffer.from(payload.k1, 'hex')),
58368
+ domain: bytesToHex$1(Buffer.from(payload.domain, 'utf-8')),
58369
+ data: bytesToHex$1(Buffer.from(payload.k1, 'hex')),
58140
58370
  };
58141
58371
  }
58142
58372
  getVersionRange() {
@@ -59732,9 +59962,9 @@ class DeviceConnector {
59732
59962
  stop() {
59733
59963
  this.listening = false;
59734
59964
  }
59735
- acquire(path, session, forceCleanRunPromise, connectProtocol) {
59965
+ acquire(path, session, forceCleanRunPromise, expectedProtocol, protocolHint) {
59736
59966
  return __awaiter(this, void 0, void 0, function* () {
59737
- Log$3.debug('acquire', path, session, connectProtocol);
59967
+ Log$3.debug('acquire', path, session, expectedProtocol, protocolHint);
59738
59968
  const env = DataManager.getSettings('env');
59739
59969
  try {
59740
59970
  let res;
@@ -59742,20 +59972,22 @@ class DeviceConnector {
59742
59972
  res = yield this.transport.acquire({
59743
59973
  uuid: path,
59744
59974
  forceCleanRunPromise,
59745
- expectedProtocol: connectProtocol,
59975
+ expectedProtocol,
59976
+ protocolHint,
59746
59977
  });
59747
59978
  }
59748
59979
  else {
59749
59980
  res = yield this.transport.acquire({
59750
59981
  path,
59751
59982
  previous: session !== null && session !== void 0 ? session : null,
59752
- expectedProtocol: connectProtocol,
59983
+ expectedProtocol,
59984
+ protocolHint,
59753
59985
  });
59754
59986
  }
59755
- if (connectProtocol) {
59987
+ if (expectedProtocol) {
59756
59988
  const detectedProtocol = this.transport.getProtocolType(path);
59757
- if (detectedProtocol !== connectProtocol) {
59758
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${connectProtocol}, detected ${detectedProtocol}`);
59989
+ if (detectedProtocol !== expectedProtocol) {
59990
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expectedProtocol}, detected ${detectedProtocol}`);
59759
59991
  }
59760
59992
  }
59761
59993
  return res;
@@ -61100,10 +61332,10 @@ class Core extends events.exports {
61100
61332
  }
61101
61333
  case IFRAME.CALL: {
61102
61334
  const logBlockLabel = getLogBlockLabel(message);
61103
- Log.log(`[${Date.now()}][CALL_API]`, logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : message);
61335
+ Log.log(formatLogMethodLabel(`[${Date.now()}][CALL_API]`, logBlockLabel), getSafeLogPayload(message, logBlockLabel));
61104
61336
  const response = yield callAPI(this.getCoreContext(), message);
61105
61337
  const { success, payload } = response;
61106
- Log.log(`[${Date.now()}][CALL_API_RESPONSE]`, logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : response);
61338
+ Log.log(formatLogMethodLabel(`[${Date.now()}][CALL_API_RESPONSE]`, logBlockLabel), getSafeLogPayload(response, logBlockLabel));
61107
61339
  if (success) {
61108
61340
  return response;
61109
61341
  }
@@ -61149,7 +61381,7 @@ class Core extends events.exports {
61149
61381
  }
61150
61382
  _deviceList = undefined;
61151
61383
  _connector = undefined;
61152
- DevicePool.resetState();
61384
+ DevicePool.dispose();
61153
61385
  deviceCacheMap.clear();
61154
61386
  preWarmInflight.clear();
61155
61387
  preWarmDoneAt.clear();
@@ -61297,6 +61529,7 @@ exports["default"] = HardwareSdk;
61297
61529
  exports.enableLog = enableLog;
61298
61530
  exports.encodePro2Wallpaper = encodePro2Wallpaper;
61299
61531
  exports.executeCallback = executeCallback;
61532
+ exports.formatLogMethodLabel = formatLogMethodLabel;
61300
61533
  exports.formatRequestContext = formatRequestContext;
61301
61534
  exports.generateInstanceId = generateInstanceId;
61302
61535
  exports.generateSdkInstanceId = generateSdkInstanceId;
@@ -61329,6 +61562,7 @@ exports.getLogger = getLogger;
61329
61562
  exports.getMethodVersionRange = getMethodVersionRange;
61330
61563
  exports.getOutputScriptType = getOutputScriptType;
61331
61564
  exports.getSDKVersion = getSDKVersion;
61565
+ exports.getSafeLogPayload = getSafeLogPayload;
61332
61566
  exports.getScriptType = getScriptType;
61333
61567
  exports.getTimeStamp = getTimeStamp;
61334
61568
  exports.httpRequest = httpRequest;