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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/__tests__/protocol-v2.test.ts +56 -178
  2. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  3. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  4. package/dist/api/FirmwareUpdateV4.d.ts +2 -2
  5. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  6. package/dist/api/GetDeviceInfo.d.ts.map +1 -1
  7. package/dist/api/GetFeatures.d.ts +1 -1
  8. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  9. package/dist/api/device/DeviceUnlock.d.ts +1 -1
  10. package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
  11. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  12. package/dist/api/tron/TronSignMessage.d.ts +0 -1
  13. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  14. package/dist/api/tron/TronSignTransaction.d.ts +0 -1
  15. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  16. package/dist/core/index.d.ts.map +1 -1
  17. package/dist/device/Device.d.ts +10 -15
  18. package/dist/device/Device.d.ts.map +1 -1
  19. package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -0
  20. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
  21. package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -4
  22. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  23. package/dist/deviceProfile/index.d.ts +1 -1
  24. package/dist/deviceProfile/index.d.ts.map +1 -1
  25. package/dist/index.d.ts +571 -496
  26. package/dist/index.js +502 -571
  27. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  28. package/dist/types/api/getDeviceInfo.d.ts +2 -2
  29. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  30. package/dist/types/device.d.ts +87 -8
  31. package/dist/types/device.d.ts.map +1 -1
  32. package/dist/utils/capabilitieUtils.d.ts.map +1 -1
  33. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  34. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  35. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  36. package/dist/utils/findDefectiveBatchDevice.d.ts +1 -1
  37. package/dist/utils/patch.d.ts +1 -1
  38. package/package.json +4 -4
  39. package/src/api/FirmwareUpdateV2.ts +9 -2
  40. package/src/api/FirmwareUpdateV3.ts +2 -1
  41. package/src/api/FirmwareUpdateV4.ts +24 -31
  42. package/src/api/GetDeviceInfo.ts +6 -13
  43. package/src/api/GetOnekeyFeatures.ts +3 -14
  44. package/src/api/GetPassphraseState.ts +2 -2
  45. package/src/api/firmware/bootloaderHelper.ts +3 -2
  46. package/src/api/firmware/getBinary.ts +1 -1
  47. package/src/api/firmware/releaseHelper.ts +3 -3
  48. package/src/api/firmware/uploadFirmware.ts +5 -2
  49. package/src/api/tron/TronSignMessage.ts +0 -1
  50. package/src/api/tron/TronSignTransaction.ts +0 -1
  51. package/src/core/index.ts +3 -7
  52. package/src/data-manager/DataManager.ts +4 -4
  53. package/src/device/Device.ts +74 -240
  54. package/src/device/DevicePool.ts +3 -3
  55. package/src/deviceProfile/buildDeviceFeatures.ts +367 -0
  56. package/src/deviceProfile/buildDeviceProfile.ts +102 -155
  57. package/src/deviceProfile/index.ts +4 -1
  58. package/src/protocols/protocol-v2/features.ts +6 -9
  59. package/src/types/api/getDeviceInfo.ts +2 -2
  60. package/src/types/device.ts +97 -34
  61. package/src/utils/capabilitieUtils.ts +1 -2
  62. package/src/utils/deviceFeaturesUtils.ts +11 -17
  63. package/src/utils/deviceInfoUtils.ts +11 -29
  64. package/src/utils/deviceVersionUtils.ts +7 -25
  65. package/src/utils/findDefectiveBatchDevice.ts +6 -6
  66. package/dist/deviceProfile/legacyFeaturesView.d.ts +0 -5
  67. package/dist/deviceProfile/legacyFeaturesView.d.ts.map +0 -1
  68. package/src/deviceProfile/legacyFeaturesView.ts +0 -123
@@ -123,15 +123,13 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
123
123
 
124
124
  // Attach to pin try to fix internal state
125
125
  const deviceId = device.getCurrentDeviceId();
126
- if (deviceId) {
127
- device.updateInternalState(
128
- device.getCurrentPassphraseProtection() ?? false,
129
- passphraseState,
130
- deviceId,
131
- newSession,
132
- device.features?.session_id
133
- );
134
- }
126
+ device.updateInternalState(
127
+ device.getCurrentPassphraseProtection() ?? false,
128
+ passphraseState,
129
+ deviceId,
130
+ newSession,
131
+ device.features?.sessionId
132
+ );
135
133
 
136
134
  return { passphraseState, newSession, unlockedAttachPin };
137
135
  };
@@ -155,8 +153,8 @@ export const getPassphraseState = async (
155
153
  }> => {
156
154
  const { features, commands } = device;
157
155
 
158
- // 设备尚未建立任何状态(V1 无 features 且无 profile)时无法判定,保持旧的空返回语义
159
- if (!features && !device.profile)
156
+ // 设备尚未建立任何状态时无法判定,保持旧的空返回语义
157
+ if (!features)
160
158
  return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
161
159
 
162
160
  const firmwareVersion = device.getCurrentFirmwareVersionString() ?? '0.0.0';
@@ -340,12 +338,8 @@ export const fixFeaturesFirmwareVersion = (features: Features): Features => {
340
338
  // fix Touch、Pro device when bootloader version is lower than 2.5.2, the features returned do not have firmware_version error
341
339
  const tempFeatures = { ...features };
342
340
 
343
- if (tempFeatures.onekey_firmware_version && !semver.valid(tempFeatures.onekey_firmware_version)) {
344
- tempFeatures.onekey_firmware_version = fixVersion(tempFeatures.onekey_firmware_version);
345
- }
346
-
347
- if (tempFeatures.onekey_version && !semver.valid(tempFeatures.onekey_version)) {
348
- tempFeatures.onekey_version = fixVersion(tempFeatures.onekey_version);
341
+ if (tempFeatures.firmwareVersion && !semver.valid(tempFeatures.firmwareVersion)) {
342
+ tempFeatures.firmwareVersion = fixVersion(tempFeatures.firmwareVersion);
349
343
  }
350
344
 
351
345
  return tempFeatures;
@@ -14,30 +14,12 @@ export const getDeviceType = (features?: Features): IDeviceType => {
14
14
  if (!features || typeof features !== 'object') {
15
15
  return EDeviceType.Unknown;
16
16
  }
17
+ if (features.deviceType) {
18
+ return features.deviceType;
19
+ }
17
20
 
18
- // classic1s 3.5.0 pro 4.6.0
19
- switch (features.onekey_device_type) {
20
- case 'CLASSIC':
21
- return EDeviceType.Classic;
22
- case 'CLASSIC1S':
23
- return EDeviceType.Classic1s;
24
- case 'MINI':
25
- return EDeviceType.Mini;
26
- case 'TOUCH':
27
- return EDeviceType.Touch;
28
- case 'PRO':
29
- return EDeviceType.Pro;
30
- case 'PRO2':
31
- case 'pro2':
32
- return EDeviceType.Pro2;
33
- case 'PURE':
34
- return EDeviceType.ClassicPure;
35
- default:
36
- // future And old device onekey_device_type is empty
37
- if (!isEmpty(features.onekey_serial_no)) {
38
- return EDeviceType.Unknown;
39
- }
40
- // old device type
21
+ if (features.model === EDeviceType.Pro2 || features.model === 'pro2') {
22
+ return EDeviceType.Pro2;
41
23
  }
42
24
 
43
25
  // low version hardware
@@ -45,7 +27,7 @@ export const getDeviceType = (features?: Features): IDeviceType => {
45
27
  const serialNo = getDeviceUUID(features);
46
28
 
47
29
  // not exist serialNo, bootloader mode, model 1 is classic
48
- if (isEmpty(serialNo) && features.bootloader_mode === true && features.model === '1') {
30
+ if (isEmpty(serialNo) && features.bootloaderMode === true && features.model === '1') {
49
31
  return EDeviceType.Classic;
50
32
  }
51
33
 
@@ -59,6 +41,7 @@ export const getDeviceType = (features?: Features): IDeviceType => {
59
41
  if (miniFlag.toLowerCase() === 'mi') return EDeviceType.Mini;
60
42
  if (miniFlag.toLowerCase() === 'tc') return EDeviceType.Touch;
61
43
  if (miniFlag.toLowerCase() === 'pr') return EDeviceType.Pro;
44
+ if (miniFlag.toLowerCase() === 'p2') return EDeviceType.Pro2;
62
45
 
63
46
  // unknown device
64
47
  return EDeviceType.Unknown;
@@ -89,15 +72,14 @@ export const getDeviceTypeByBleName = (name?: string): IDeviceType => {
89
72
  */
90
73
  export const getDeviceBleName = (features?: Features): string | null => {
91
74
  if (features == null) return null;
92
- return features.onekey_ble_name || features.ble_name || null;
75
+ return features.bleName || null;
93
76
  };
94
77
 
95
78
  /**
96
79
  * Get Connected Device UUID by features
97
80
  */
98
81
  export const getDeviceUUID = (features: Features) => {
99
- const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no;
100
- return serialNo ?? '';
82
+ return features.serialNo ?? '';
101
83
  };
102
84
 
103
85
  /**
@@ -163,8 +145,8 @@ export const getFirmwareType = (features: Features | undefined) => {
163
145
  if (!features) {
164
146
  return EFirmwareType.Universal;
165
147
  }
166
- if (features.fw_vendor === 'OneKey Bitcoin-only') {
167
- return EFirmwareType.BitcoinOnly;
148
+ if (features.firmwareType) {
149
+ return features.firmwareType;
168
150
  }
169
151
  // old firmware
170
152
  return features?.capabilities?.length > 0 &&
@@ -8,12 +8,8 @@ import type { Features, IVersionArray } from '../types';
8
8
  export const getDeviceFirmwareVersion = (features: Features | undefined): IVersionArray => {
9
9
  if (!features) return [0, 0, 0];
10
10
 
11
- if (semver.valid(features.onekey_firmware_version)) {
12
- return features.onekey_firmware_version?.split('.') as unknown as IVersionArray;
13
- }
14
-
15
- if (semver.valid(features.onekey_version)) {
16
- return features.onekey_version?.split('.') as unknown as IVersionArray;
11
+ if (features.firmwareVersion && semver.valid(features.firmwareVersion)) {
12
+ return features.firmwareVersion.split('.').map(Number) as IVersionArray;
17
13
  }
18
14
 
19
15
  return [0, 0, 0];
@@ -23,7 +19,7 @@ export const getDeviceFirmwareVersion = (features: Features | undefined): IVersi
23
19
  * Get Connected Device bluetooth firmware version by features
24
20
  */
25
21
  export const getDeviceBLEFirmwareVersion = (features: Features): IVersionArray => {
26
- const bleVer = features?.onekey_ble_version || features?.ble_ver;
22
+ const bleVer = features?.bleVersion;
27
23
 
28
24
  if (!bleVer) {
29
25
  return [0, 0, 0];
@@ -46,24 +42,10 @@ export const getDeviceBootloaderVersion = (features: Features | undefined): IVer
46
42
  if (!features) return [0, 0, 0];
47
43
 
48
44
  // classic1s 3.5.0 pro 4.6.0
49
- if (semver.valid(features.onekey_boot_version)) {
50
- return features.onekey_boot_version?.split('.') as unknown as IVersionArray;
45
+ if (features.bootloaderVersion && semver.valid(features.bootloaderVersion)) {
46
+ return features.bootloaderVersion.split('.').map(Number) as IVersionArray;
51
47
  }
52
48
 
53
- // low version hardware
54
- if (!features.bootloader_version) {
55
- if (features.bootloader_mode) {
56
- return [
57
- features?.major_version ?? 0,
58
- features?.minor_version ?? 0,
59
- features?.patch_version ?? 0,
60
- ];
61
- }
62
- return [0, 0, 0];
63
- }
64
- if (semver.valid(features.bootloader_version)) {
65
- return features.bootloader_version?.split('.') as unknown as IVersionArray;
66
- }
67
49
  return [0, 0, 0];
68
50
  };
69
51
 
@@ -71,8 +53,8 @@ export const getDeviceBootloaderVersion = (features: Features | undefined): IVer
71
53
  * Get Connected Device boardloader version by features
72
54
  */
73
55
  export const getDeviceBoardloaderVersion = (features: Features): IVersionArray => {
74
- if (semver.valid(features?.onekey_board_version)) {
75
- return features?.onekey_board_version?.split('.') as unknown as IVersionArray;
56
+ if (features?.boardVersion && semver.valid(features.boardVersion)) {
57
+ return features.boardVersion.split('.').map(Number) as IVersionArray;
76
58
  }
77
59
 
78
60
  return [0, 0, 0];
@@ -5,7 +5,7 @@ import type { Features } from '../types';
5
5
  /**
6
6
  * 检测故障固件设备
7
7
  * 检测规则:
8
- * - 序列号范围:21032200001 到 21032201500 (从 onekey_serial 字段提取)
8
+ * - 序列号范围:21032200001 到 21032201500
9
9
  * - SE版本为 1.1.0.2
10
10
  *
11
11
  * 对齐之前版本的检测逻辑
@@ -13,13 +13,13 @@ import type { Features } from '../types';
13
13
  export const findDefectiveBatchDevice = (features: Features) => {
14
14
  if (!features) return;
15
15
 
16
- const { onekey_serial: onekeySerial, se_ver: seVer } = features;
17
- if (!onekeySerial) return;
16
+ const { serialNo, seVersion } = features;
17
+ if (!serialNo) return;
18
18
 
19
- const versionNum = +onekeySerial.slice(5);
19
+ const versionNum = +serialNo.slice(5);
20
20
  if (Number.isNaN(versionNum)) return;
21
21
 
22
- return versionNum >= 21032200001 && versionNum <= 21032201500 && seVer === '1.1.0.2';
22
+ return versionNum >= 21032200001 && versionNum <= 21032201500 && seVersion === '1.1.0.2';
23
23
  };
24
24
 
25
25
  /**
@@ -29,7 +29,7 @@ export const getDefectiveDeviceInfo = (features: Features) => {
29
29
  if (!findDefectiveBatchDevice(features)) return null;
30
30
  const serialNo = getDeviceUUID(features);
31
31
  const deviceType = getDeviceType(features);
32
- const seVersion = features.se_ver;
32
+ const { seVersion } = features;
33
33
 
34
34
  return {
35
35
  serialNo,
@@ -1,5 +0,0 @@
1
- import type { Features } from '../types';
2
- import type { DeviceProfile } from '../types/api/getDeviceInfo';
3
- import type { ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
4
- export declare const buildProtocolV2GetFeaturesPayload: (profile: DeviceProfile, deviceInfo?: ProtocolV2DeviceInfo) => Features;
5
- //# sourceMappingURL=legacyFeaturesView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacyFeaturesView.d.ts","sourceRoot":"","sources":["../../src/deviceProfile/legacyFeaturesView.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAmBnE,eAAO,MAAM,iCAAiC,YACnC,aAAa,eACT,oBAAoB,KAChC,QA8FF,CAAC"}
@@ -1,123 +0,0 @@
1
- import { EDeviceType } from '@onekeyfe/hd-shared';
2
-
3
- import { getProtocolV2SeState, getProtocolV2SeType } from '../protocols/protocol-v2/features';
4
-
5
- import type { Features } from '../types';
6
- import type { DeviceProfile } from '../types/api/getDeviceInfo';
7
- import type { ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
8
-
9
- const parseProtocolV2Version = (version?: string | null): [number, number, number] => {
10
- if (!version) return [0, 0, 0];
11
- const [major = 0, minor = 0, patch = 0] = version.split('.').map(part => Number(part) || 0);
12
- return [major, minor, patch];
13
- };
14
-
15
- /**
16
- * Protocol V2 的 legacy `Features` 兼容视图。
17
- *
18
- * SDK 内部标准模型是 DeviceProfile;该函数只为 getFeatures() 等旧 API
19
- * 临时合成 Features 形状的数据,不应被内部逻辑消费。
20
- *
21
- * 注意:以下字段在 V2 协议中没有等价信息,使用保守占位值——
22
- * bootloader_mode/firmware_present 恒 false、unlocked 恒 false、
23
- * capabilities 恒空、pin_protection/safety_checks 等恒 null。
24
- * 内部判断请使用 device.profile / getCurrent* accessor,而不是这些占位值。
25
- */
26
- export const buildProtocolV2GetFeaturesPayload = (
27
- profile: DeviceProfile,
28
- deviceInfo?: ProtocolV2DeviceInfo
29
- ): Features => {
30
- const firmwareVersion = profile.versions.firmware;
31
- const [fwMajor, fwMinor, fwPatch] = parseProtocolV2Version(firmwareVersion);
32
-
33
- return {
34
- vendor: 'onekey.so',
35
- major_version: fwMajor,
36
- minor_version: fwMinor,
37
- patch_version: fwPatch,
38
- bootloader_mode: false,
39
- device_id: profile.deviceId,
40
- pin_protection: null,
41
- passphrase_protection: profile.status.passphraseProtection,
42
- language: profile.status.language,
43
- label: profile.label,
44
- initialized: profile.status.initialized ?? false,
45
- revision: null,
46
- bootloader_hash: null,
47
- imported: null,
48
- unlocked: false,
49
- firmware_present: false,
50
- needs_backup: profile.status.backupRequired,
51
- flags: null,
52
- model: 'pro2',
53
- fw_major: fwMajor,
54
- fw_minor: fwMinor,
55
- fw_patch: fwPatch,
56
- fw_vendor: null,
57
- unfinished_backup: null,
58
- no_backup: null,
59
- recovery_mode: null,
60
- capabilities: [],
61
- backup_type: null,
62
- sd_card_present: null,
63
- sd_protection: null,
64
- wipe_code_protection: null,
65
- session_id: null,
66
- passphrase_always_on_device: null,
67
- safety_checks: null,
68
- auto_lock_delay_ms: null,
69
- display_rotation: null,
70
- experimental_features: null,
71
- protocol_version: deviceInfo?.protocol_version ?? null,
72
- onekey_device_type: EDeviceType.Pro2,
73
- onekey_serial_no: profile.serialNo,
74
- serial_no: profile.serialNo,
75
- ble_enable: profile.status.bleEnabled ?? undefined,
76
- onekey_ble_name: profile.bleName ?? undefined,
77
- ble_name: profile.bleName ?? undefined,
78
- onekey_firmware_version: firmwareVersion ?? undefined,
79
- onekey_firmware_build_id: profile.verify?.firmwareBuildId,
80
- onekey_firmware_hash: profile.verify?.firmwareHash,
81
- onekey_boot_version: profile.versions.bootloader ?? undefined,
82
- bootloader_version: profile.versions.bootloader ?? undefined,
83
- onekey_boot_build_id: profile.verify?.bootloaderBuildId,
84
- onekey_boot_hash: profile.verify?.bootloaderHash,
85
- onekey_board_version: profile.versions.board ?? undefined,
86
- onekey_board_build_id: profile.verify?.boardBuildId,
87
- onekey_board_hash: profile.verify?.boardHash,
88
- onekey_ble_version: profile.versions.ble ?? undefined,
89
- ble_ver: profile.versions.ble ?? undefined,
90
- onekey_ble_build_id: profile.verify?.bleBuildId,
91
- onekey_ble_hash: profile.verify?.bleHash,
92
- // Pro2 的 SE 类型在 DevGetDeviceInfo 的 se1.type 上报(如 THD89)
93
- onekey_se_type: getProtocolV2SeType(deviceInfo?.se1),
94
- onekey_se01_version: profile.versions.se01 ?? undefined,
95
- onekey_se01_hash: profile.verify?.se01Hash,
96
- onekey_se01_build_id: profile.verify?.se01BuildId,
97
- onekey_se01_boot_version: profile.versions.se01Boot ?? undefined,
98
- onekey_se01_boot_hash: profile.verify?.se01BootHash,
99
- onekey_se01_boot_build_id: profile.verify?.se01BootBuildId,
100
- onekey_se01_state: getProtocolV2SeState(deviceInfo?.se1),
101
- onekey_se02_version: profile.versions.se02 ?? undefined,
102
- onekey_se02_hash: profile.verify?.se02Hash,
103
- onekey_se02_build_id: profile.verify?.se02BuildId,
104
- onekey_se02_boot_version: profile.versions.se02Boot ?? undefined,
105
- onekey_se02_boot_hash: profile.verify?.se02BootHash,
106
- onekey_se02_boot_build_id: profile.verify?.se02BootBuildId,
107
- onekey_se02_state: getProtocolV2SeState(deviceInfo?.se2),
108
- onekey_se03_version: profile.versions.se03 ?? undefined,
109
- onekey_se03_hash: profile.verify?.se03Hash,
110
- onekey_se03_build_id: profile.verify?.se03BuildId,
111
- onekey_se03_boot_version: profile.versions.se03Boot ?? undefined,
112
- onekey_se03_boot_hash: profile.verify?.se03BootHash,
113
- onekey_se03_boot_build_id: profile.verify?.se03BootBuildId,
114
- onekey_se03_state: getProtocolV2SeState(deviceInfo?.se3),
115
- onekey_se04_version: profile.versions.se04 ?? undefined,
116
- onekey_se04_hash: profile.verify?.se04Hash,
117
- onekey_se04_build_id: profile.verify?.se04BuildId,
118
- onekey_se04_boot_version: profile.versions.se04Boot ?? undefined,
119
- onekey_se04_boot_hash: profile.verify?.se04BootHash,
120
- onekey_se04_boot_build_id: profile.verify?.se04BootBuildId,
121
- onekey_se04_state: getProtocolV2SeState(deviceInfo?.se4),
122
- };
123
- };