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

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 (84) hide show
  1. package/__tests__/protocol-v2.test.ts +147 -264
  2. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  3. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  4. package/dist/api/FirmwareUpdateV4.d.ts +2 -2
  5. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  6. package/dist/api/GetDeviceInfo.d.ts.map +1 -1
  7. package/dist/api/GetFeatures.d.ts +1 -1
  8. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  9. package/dist/api/GetPassphraseState.d.ts +4 -4
  10. package/dist/api/device/DeviceUnlock.d.ts +1 -1
  11. package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
  12. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  13. package/dist/api/protocol-v2/helpers.d.ts +2 -3
  14. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  15. package/dist/constants/index.d.ts +2 -1
  16. package/dist/constants/index.d.ts.map +1 -1
  17. package/dist/core/index.d.ts.map +1 -1
  18. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  19. package/dist/device/Device.d.ts +11 -15
  20. package/dist/device/Device.d.ts.map +1 -1
  21. package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -0
  22. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
  23. package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -4
  24. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  25. package/dist/deviceProfile/index.d.ts +1 -1
  26. package/dist/deviceProfile/index.d.ts.map +1 -1
  27. package/dist/index.d.ts +579 -502
  28. package/dist/index.js +881 -931
  29. package/dist/protocols/protocol-v2/features.d.ts +2 -2
  30. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  31. package/dist/types/api/getDeviceInfo.d.ts +2 -2
  32. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  33. package/dist/types/api/getPassphraseState.d.ts +4 -4
  34. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  35. package/dist/types/api/protocolV2.d.ts +3 -3
  36. package/dist/types/api/protocolV2.d.ts.map +1 -1
  37. package/dist/types/device.d.ts +87 -8
  38. package/dist/types/device.d.ts.map +1 -1
  39. package/dist/types/settings.d.ts +1 -0
  40. package/dist/types/settings.d.ts.map +1 -1
  41. package/dist/utils/capabilitieUtils.d.ts.map +1 -1
  42. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  43. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  44. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  45. package/dist/utils/findDefectiveBatchDevice.d.ts +1 -1
  46. package/dist/utils/patch.d.ts +1 -1
  47. package/dist/utils/patch.d.ts.map +1 -1
  48. package/package.json +4 -4
  49. package/src/api/FirmwareUpdateV2.ts +9 -2
  50. package/src/api/FirmwareUpdateV3.ts +2 -1
  51. package/src/api/FirmwareUpdateV4.ts +24 -31
  52. package/src/api/GetDeviceInfo.ts +6 -13
  53. package/src/api/GetOnekeyFeatures.ts +3 -14
  54. package/src/api/GetPassphraseState.ts +4 -4
  55. package/src/api/firmware/bootloaderHelper.ts +3 -2
  56. package/src/api/firmware/getBinary.ts +1 -1
  57. package/src/api/firmware/releaseHelper.ts +3 -3
  58. package/src/api/firmware/uploadFirmware.ts +5 -2
  59. package/src/api/protocol-v2/DeviceReboot.ts +3 -3
  60. package/src/api/protocol-v2/helpers.ts +1 -26
  61. package/src/constants/index.ts +10 -1
  62. package/src/core/index.ts +5 -7
  63. package/src/data/messages/messages-protocol-v2.json +329 -323
  64. package/src/data-manager/DataManager.ts +4 -4
  65. package/src/data-manager/connectSettings.ts +6 -0
  66. package/src/device/Device.ts +86 -241
  67. package/src/device/DevicePool.ts +9 -9
  68. package/src/deviceProfile/buildDeviceFeatures.ts +368 -0
  69. package/src/deviceProfile/buildDeviceProfile.ts +101 -155
  70. package/src/deviceProfile/index.ts +4 -1
  71. package/src/protocols/protocol-v2/features.ts +14 -16
  72. package/src/types/api/getDeviceInfo.ts +2 -2
  73. package/src/types/api/getPassphraseState.ts +4 -4
  74. package/src/types/api/protocolV2.ts +2 -3
  75. package/src/types/device.ts +97 -34
  76. package/src/types/settings.ts +5 -0
  77. package/src/utils/capabilitieUtils.ts +1 -2
  78. package/src/utils/deviceFeaturesUtils.ts +11 -17
  79. package/src/utils/deviceInfoUtils.ts +11 -29
  80. package/src/utils/deviceVersionUtils.ts +7 -25
  81. package/src/utils/findDefectiveBatchDevice.ts +6 -6
  82. package/dist/deviceProfile/legacyFeaturesView.d.ts +0 -5
  83. package/dist/deviceProfile/legacyFeaturesView.d.ts.map +0 -1
  84. package/src/deviceProfile/legacyFeaturesView.ts +0 -123
@@ -4,7 +4,6 @@ import { UI_REQUEST } from '../constants/ui-request';
4
4
  import { fixVersion } from '../utils/deviceFeaturesUtils';
5
5
  import { PROTOCOL_V2_DEVICE_INFO_REQUEST } from '../protocols/protocol-v2';
6
6
  import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
7
- import { buildProfileFromProtocolV2, buildProtocolV2GetFeaturesPayload } from '../deviceProfile';
8
7
  import { BaseMethod } from './BaseMethod';
9
8
 
10
9
  import type { OnekeyFeatures } from '../types';
@@ -91,23 +90,13 @@ export default class GetOnekeyFeatures extends BaseMethod {
91
90
  async run() {
92
91
  if (this.device.isProtocolV2()) {
93
92
  // V2 没有 OnekeyGetFeatures 消息:
94
- // 取完整 DevGetDeviceInfo(含 SE/hash/build_id)后写入 features 兼容视图。
93
+ // 取完整 DevGetDeviceInfo(含 SE/hash/build_id)后刷新结构化 features 缓存。
95
94
  const deviceInfo = await requestProtocolV2DeviceInfo({
96
95
  commands: this.device.commands,
97
96
  request: PROTOCOL_V2_DEVICE_INFO_REQUEST,
98
97
  });
99
- const profile = this.device.applyProfileUpdate(
100
- buildProfileFromProtocolV2({
101
- deviceInfo,
102
- sources: ['deviceInfo'],
103
- scope: 'verify',
104
- fallbackSerialNo: this.device.originalDescriptor?.path,
105
- }),
106
- deviceInfo
107
- );
108
- return pickOnekeyFeatures(
109
- buildProtocolV2GetFeaturesPayload(profile, deviceInfo) as OnekeyFeatures
110
- );
98
+ const features = this.device.updateProtocolV2Features(deviceInfo);
99
+ return pickOnekeyFeatures(features as OnekeyFeatures);
111
100
  }
112
101
 
113
102
  const { message } = await this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
@@ -25,10 +25,10 @@ export default class GetPassphraseState extends BaseMethod {
25
25
 
26
26
  // refresh device info
27
27
  return Promise.resolve({
28
- passphrase_state: isProSeries || passphraseProtection === true ? passphraseState : undefined,
29
- session_id: newSession ?? features?.session_id ?? undefined,
30
- unlocked_attach_pin: unlockedAttachPin ?? features?.unlocked_attach_pin,
31
- passphrase_protection: passphraseProtection,
28
+ passphraseState: isProSeries || passphraseProtection === true ? passphraseState : undefined,
29
+ sessionId: newSession ?? features?.sessionId ?? undefined,
30
+ unlockedAttachPin: unlockedAttachPin ?? features?.unlockedAttachPin,
31
+ passphraseProtection,
32
32
  });
33
33
  }
34
34
  }
@@ -1,7 +1,7 @@
1
1
  import semver from 'semver';
2
2
  import { EDeviceType } from '@onekeyfe/hd-shared';
3
3
 
4
- import { getDeviceType } from '../../utils';
4
+ import { getDeviceBootloaderVersion, getDeviceType } from '../../utils';
5
5
 
6
6
  import type { Features, IVersionArray } from '../../types';
7
7
 
@@ -38,9 +38,10 @@ export function shouldUpdateBootloaderForClassicAndMini({
38
38
  export function isEnteredManuallyBoot(features: Features, updateType: string) {
39
39
  const deviceType = getDeviceType(features);
40
40
  const isMini = deviceType === EDeviceType.Mini;
41
+ const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
41
42
  const isBoot183ClassicUpBle =
42
43
  updateType === 'firmware' &&
43
44
  deviceType === EDeviceType.Classic &&
44
- features.bootloader_version === '1.8.3';
45
+ bootloaderVersion === '1.8.3';
45
46
  return isMini || isBoot183ClassicUpBle;
46
47
  }
@@ -41,7 +41,7 @@ export const getBinary = async ({
41
41
  }
42
42
 
43
43
  if (version && !semver.eq(releaseInfo.version.join('.'), version.join('.'))) {
44
- const touchWithoutVersion = getDeviceType(features) === 'touch' && !features.onekey_version;
44
+ const touchWithoutVersion = getDeviceType(features) === 'touch' && !features.firmwareVersion;
45
45
  if (!touchWithoutVersion) {
46
46
  throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'firmware version mismatch');
47
47
  }
@@ -12,7 +12,7 @@ export const getFirmwareReleaseInfo = (features: Features, firmwareType: EFirmwa
12
12
  const firmwareStatus = DataManager.getFirmwareStatus(features, firmwareType);
13
13
  const changelog = DataManager.getFirmwareChangelog(features, firmwareType);
14
14
  const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
15
- const bootloaderMode = !!features.bootloader_mode;
15
+ const bootloaderMode = !!features.bootloaderMode;
16
16
  return {
17
17
  status: firmwareStatus,
18
18
  changelog,
@@ -25,7 +25,7 @@ export const getBleFirmwareReleaseInfo = (features: Features) => {
25
25
  const firmwareStatus = DataManager.getBLEFirmwareStatus(features);
26
26
  const changelog = DataManager.getBleFirmwareChangelog(features);
27
27
  const release = DataManager.getBleFirmwareLatestRelease(features);
28
- const bootloaderMode = !!features.bootloader_mode;
28
+ const bootloaderMode = !!features.bootloaderMode;
29
29
  return {
30
30
  status: firmwareStatus,
31
31
  changelog,
@@ -52,7 +52,7 @@ export const getBootloaderReleaseInfo = ({
52
52
  Object.prototype.hasOwnProperty.call(item, 'en-US')
53
53
  );
54
54
 
55
- const bootloaderMode = !!features.bootloader_mode;
55
+ const bootloaderMode = !!features.bootloaderMode;
56
56
 
57
57
  let shouldUpdate = false;
58
58
 
@@ -9,6 +9,7 @@ import { DeviceModelToTypes } from '../../types';
9
9
  import { bytesToHex } from '../helpers/hexUtils';
10
10
  import { DataManager } from '../../data-manager';
11
11
  import { DevicePool } from '../../device/DevicePool';
12
+ import { buildProtocolV1FeaturesPayload } from '../../deviceProfile';
12
13
 
13
14
  import type { KnownDevice } from '../../types';
14
15
  import type { TypedCall, TypedResponseMessage } from '../../device/DeviceCommands';
@@ -34,7 +35,7 @@ const isDeviceDisconnectedError = (error: unknown) => {
34
35
 
35
36
  const postConfirmationMessage = (device: Device) => {
36
37
  // only if firmware is already installed. fresh device does not require button confirmation
37
- if (device.features?.firmware_present) {
38
+ if (device.features?.firmwarePresent) {
38
39
  device.emit(DEVICE.BUTTON, device, { code: 'ButtonRequest_FirmwareUpdate' });
39
40
  }
40
41
  };
@@ -109,7 +110,9 @@ export const uploadFirmware = async (
109
110
 
110
111
  if (isFirmware && !isUpdateBootloader) {
111
112
  const newFeatures = await typedCall('GetFeatures', 'Features', {});
112
- const deviceBootloaderVersion = getDeviceBootloaderVersion(newFeatures.message).join('.');
113
+ const deviceBootloaderVersion = getDeviceBootloaderVersion(
114
+ buildProtocolV1FeaturesPayload(newFeatures.message, device.features)
115
+ ).join('.');
113
116
  const supportUpgradeFileHeader = semver.gte(deviceBootloaderVersion, '2.1.0');
114
117
  Log.debug('supportUpgradeFileHeader:', supportUpgradeFileHeader);
115
118
 
@@ -1,5 +1,5 @@
1
1
  import { BaseMethod } from '../BaseMethod';
2
- import { normalizeDeviceRebootType } from './helpers';
2
+ import { normalizeRebootType } from './helpers';
3
3
 
4
4
  import type { DeviceRebootParams } from './helpers';
5
5
 
@@ -16,8 +16,8 @@ export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
16
16
  }
17
17
 
18
18
  async run() {
19
- const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
20
- reboot_type: normalizeDeviceRebootType(this.params.reboot_type ?? this.params.rebootType),
19
+ const res = await this.device.commands.typedCall('DevReboot', 'Success', {
20
+ reboot_type: normalizeRebootType(this.params.reboot_type ?? this.params.rebootType),
21
21
  });
22
22
  return Promise.resolve(res.message);
23
23
  }
@@ -1,4 +1,4 @@
1
- import { DevRebootType, DeviceRebootType } from '@onekeyfe/hd-transport';
1
+ import { DevRebootType } from '@onekeyfe/hd-transport';
2
2
 
3
3
  import { invalidParameter, validateNonEmptyString } from '../helpers/filesystemValidation';
4
4
 
@@ -10,9 +10,7 @@ import type {
10
10
 
11
11
  export type RebootTypeInput =
12
12
  | DevRebootType
13
- | DeviceRebootType
14
13
  | keyof typeof DevRebootType
15
- | keyof typeof DeviceRebootType
16
14
  | string
17
15
  | number;
18
16
 
@@ -56,17 +54,6 @@ const DEV_REBOOT_TYPES: Record<string, DevRebootType> = {
56
54
  bootloader: DevRebootType.Bootloader,
57
55
  };
58
56
 
59
- const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
60
- Normal: DeviceRebootType.Normal,
61
- normal: DeviceRebootType.Normal,
62
- Romloader: DeviceRebootType.Romloader,
63
- romloader: DeviceRebootType.Romloader,
64
- Boardloader: DeviceRebootType.Romloader,
65
- boardloader: DeviceRebootType.Romloader,
66
- Bootloader: DeviceRebootType.Bootloader,
67
- bootloader: DeviceRebootType.Bootloader,
68
- };
69
-
70
57
  export const PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS: TransportCallOptions = {
71
58
  intermediateTypes: ['DevFirmwareInstallProgress'],
72
59
  };
@@ -143,18 +130,6 @@ export function normalizeRebootType(value: RebootTypeInput | undefined): DevRebo
143
130
  return DevRebootType.Normal;
144
131
  }
145
132
 
146
- export function normalizeDeviceRebootType(
147
- value: RebootTypeInput | undefined
148
- ): DeviceRebootType {
149
- if (typeof value === 'number') return value;
150
- if (typeof value === 'string') {
151
- const numeric = Number(value);
152
- if (Number.isFinite(numeric)) return numeric;
153
- if (value in DEVICE_REBOOT_TYPES) return DEVICE_REBOOT_TYPES[value];
154
- }
155
- return DeviceRebootType.Normal;
156
- }
157
-
158
133
  // 当前 firmware-pro2 子模块的 DevFirmwareTargetType 合法值。
159
134
  const VALID_FIRMWARE_TARGET_IDS = new Set<number>([0, 1, 2, 3, 4, 5, 6, 10]);
160
135
 
@@ -1,2 +1,11 @@
1
1
  export { safeThrowError } from './errors';
2
- export { Messages as PROTO, TonSignDataType } from '@onekeyfe/hd-transport';
2
+ export {
3
+ Messages as PROTO,
4
+ ResourceType,
5
+ TonSignDataType,
6
+ TonWalletVersion,
7
+ } from '@onekeyfe/hd-transport';
8
+ export type {
9
+ HDNodeType,
10
+ Success as DeviceSuccess,
11
+ } from '@onekeyfe/hd-transport';
package/src/core/index.ts CHANGED
@@ -56,17 +56,14 @@ import TransportManager from '../data-manager/TransportManager';
56
56
  import DeviceConnector from '../device/DeviceConnector';
57
57
  import RequestQueue from './RequestQueue';
58
58
  import { getSynchronize } from '../utils/getSynchronize';
59
+ import { setProtocolV2DeviceInfoMock } from '../protocols/protocol-v2/features';
59
60
 
60
- import type { ConnectSettings, KnownDevice } from '../types';
61
+ import type { ConnectSettings, Features, KnownDevice } from '../types';
61
62
  import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
62
63
  import type { DeviceEvents, InitOptions, RunOptions } from '../device/Device';
63
64
  import type { SdkTracingContext } from '../utils/tracing';
64
65
  import type { Deferred } from '@onekeyfe/hd-shared';
65
- import type {
66
- Features,
67
- LowlevelTransportSharedPlugin,
68
- OneKeyDeviceInfo,
69
- } from '@onekeyfe/hd-transport';
66
+ import type { LowlevelTransportSharedPlugin, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
70
67
  import type { BaseMethod } from '../api/BaseMethod';
71
68
 
72
69
  const Log = getLogger(LoggerNames.Core);
@@ -1115,7 +1112,7 @@ const checkPassphraseEnableState = (method: BaseMethod, features?: Features) =>
1115
1112
 
1116
1113
  const passphraseProtection = method.device
1117
1114
  ? method.device.getCurrentPassphraseProtection()
1118
- : features?.passphrase_protection;
1115
+ : features?.passphraseProtection;
1119
1116
 
1120
1117
  if (passphraseProtection === true) {
1121
1118
  const hasNoPassphraseState =
@@ -1442,6 +1439,7 @@ export const init = async (
1442
1439
  try {
1443
1440
  try {
1444
1441
  await DataManager.load(settings);
1442
+ setProtocolV2DeviceInfoMock(settings.protocolV2DeviceInfoMockEnabled ?? false);
1445
1443
  initTransport(Transport, plugin);
1446
1444
  } catch {
1447
1445
  Log.error('DataManager.load error');