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

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 (192) hide show
  1. package/__tests__/connectSettings.test.ts +19 -0
  2. package/__tests__/device-wallet-session-store.test.ts +131 -0
  3. package/__tests__/preInitialize.test.ts +33 -0
  4. package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
  5. package/__tests__/protocol-v2.test.ts +1930 -765
  6. package/dist/api/ClearSessionCache.d.ts +9 -0
  7. package/dist/api/ClearSessionCache.d.ts.map +1 -0
  8. package/dist/api/FileRead.d.ts.map +1 -1
  9. package/dist/api/FileWrite.d.ts.map +1 -1
  10. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  11. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  12. package/dist/api/FirmwareUpdateV4.d.ts +26 -5
  13. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  14. package/dist/api/GetDeviceInfo.d.ts.map +1 -1
  15. package/dist/api/GetFeatures.d.ts +1 -1
  16. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  17. package/dist/api/GetPassphraseState.d.ts +4 -4
  18. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  19. package/dist/api/device/DeviceUnlock.d.ts +1 -1
  20. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +1 -0
  21. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  22. package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
  23. package/dist/api/firmware/getBinary.d.ts +4 -0
  24. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  25. package/dist/api/firmware/progressThrottle.d.ts +3 -0
  26. package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
  27. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  28. package/dist/api/index.d.ts +8 -10
  29. package/dist/api/index.d.ts.map +1 -1
  30. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
  31. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
  32. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
  33. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
  34. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -1
  35. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
  36. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +3 -2
  37. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  38. package/dist/api/protocol-v2/{DeviceGetDeviceInfo.d.ts → DeviceInfoGet.d.ts} +10 -10
  39. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
  40. package/dist/api/protocol-v2/DeviceSessionGet.d.ts +9 -0
  41. package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +1 -0
  42. package/dist/api/protocol-v2/DeviceStatusGet.d.ts +6 -0
  43. package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
  44. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
  45. package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
  46. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
  47. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
  48. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
  49. package/dist/api/protocol-v2/helpers.d.ts +27 -19
  50. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  51. package/dist/api/ton/TonSignData.d.ts +1 -5
  52. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  53. package/dist/api/tron/TronSignMessage.d.ts +0 -1
  54. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  55. package/dist/api/tron/TronSignTransaction.d.ts +0 -1
  56. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  57. package/dist/constants/index.d.ts +2 -1
  58. package/dist/constants/index.d.ts.map +1 -1
  59. package/dist/core/index.d.ts.map +1 -1
  60. package/dist/data-manager/DataManager.d.ts +1 -1
  61. package/dist/data-manager/DataManager.d.ts.map +1 -1
  62. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  63. package/dist/device/Device.d.ts +17 -18
  64. package/dist/device/Device.d.ts.map +1 -1
  65. package/dist/device/DeviceWalletSessionStore.d.ts +15 -0
  66. package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
  67. package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -0
  68. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
  69. package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -4
  70. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  71. package/dist/deviceProfile/index.d.ts +1 -1
  72. package/dist/deviceProfile/index.d.ts.map +1 -1
  73. package/dist/index.d.ts +657 -539
  74. package/dist/index.js +2579 -2161
  75. package/dist/inject.d.ts.map +1 -1
  76. package/dist/protocols/protocol-v2/features.d.ts +12 -14
  77. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  78. package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
  79. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  80. package/dist/protocols/protocol-v2/index.d.ts +1 -0
  81. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  82. package/dist/protocols/protocol-v2/walletSession.d.ts +13 -0
  83. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
  84. package/dist/types/api/firmwareUpdate.d.ts +4 -6
  85. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  86. package/dist/types/api/getDeviceInfo.d.ts +4 -2
  87. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  88. package/dist/types/api/getPassphraseState.d.ts +4 -4
  89. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  90. package/dist/types/api/index.d.ts +11 -11
  91. package/dist/types/api/index.d.ts.map +1 -1
  92. package/dist/types/api/protocolV2.d.ts +16 -17
  93. package/dist/types/api/protocolV2.d.ts.map +1 -1
  94. package/dist/types/api/sessionCache.d.ts +10 -0
  95. package/dist/types/api/sessionCache.d.ts.map +1 -0
  96. package/dist/types/device.d.ts +88 -8
  97. package/dist/types/device.d.ts.map +1 -1
  98. package/dist/types/params.d.ts +1 -0
  99. package/dist/types/params.d.ts.map +1 -1
  100. package/dist/types/settings.d.ts +21 -1
  101. package/dist/types/settings.d.ts.map +1 -1
  102. package/dist/utils/capabilitieUtils.d.ts.map +1 -1
  103. package/dist/utils/deviceFeaturesUtils.d.ts +2 -0
  104. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  105. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  106. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  107. package/dist/utils/findDefectiveBatchDevice.d.ts +1 -1
  108. package/dist/utils/patch.d.ts +1 -1
  109. package/dist/utils/patch.d.ts.map +1 -1
  110. package/package.json +4 -4
  111. package/src/api/ClearSessionCache.ts +28 -0
  112. package/src/api/FileRead.ts +16 -3
  113. package/src/api/FileWrite.ts +14 -1
  114. package/src/api/FirmwareUpdateV2.ts +9 -2
  115. package/src/api/FirmwareUpdateV3.ts +2 -1
  116. package/src/api/FirmwareUpdateV4.ts +1089 -285
  117. package/src/api/GetDeviceInfo.ts +6 -13
  118. package/src/api/GetOnekeyFeatures.ts +3 -14
  119. package/src/api/GetPassphraseState.ts +7 -4
  120. package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
  121. package/src/api/device/DeviceRebootToBootloader.ts +4 -4
  122. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +18 -4
  123. package/src/api/firmware/bootloaderHelper.ts +3 -2
  124. package/src/api/firmware/getBinary.ts +1 -1
  125. package/src/api/firmware/progressThrottle.ts +44 -0
  126. package/src/api/firmware/releaseHelper.ts +3 -3
  127. package/src/api/firmware/uploadFirmware.ts +5 -2
  128. package/src/api/index.ts +8 -10
  129. package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +3 -3
  130. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
  131. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +3 -5
  132. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +39 -5
  133. package/src/api/protocol-v2/{DeviceGetDeviceInfo.ts → DeviceInfoGet.ts} +52 -22
  134. package/src/api/protocol-v2/DeviceReboot.ts +2 -2
  135. package/src/api/protocol-v2/DeviceSessionGet.ts +26 -0
  136. package/src/api/protocol-v2/DeviceStatusGet.ts +14 -0
  137. package/src/api/protocol-v2/FilesystemFormat.ts +4 -1
  138. package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +2 -2
  139. package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +2 -2
  140. package/src/api/protocol-v2/helpers.ts +58 -59
  141. package/src/api/ton/TonSignData.ts +1 -5
  142. package/src/api/tron/TronSignMessage.ts +0 -1
  143. package/src/api/tron/TronSignTransaction.ts +0 -1
  144. package/src/constants/index.ts +10 -1
  145. package/src/core/index.ts +22 -10
  146. package/src/data/messages/messages-protocol-v2.json +992 -1420
  147. package/src/data/messages/messages.json +8 -0
  148. package/src/data-manager/DataManager.ts +11 -4
  149. package/src/data-manager/connectSettings.ts +4 -0
  150. package/src/device/Device.ts +158 -294
  151. package/src/device/DevicePool.ts +9 -9
  152. package/src/device/DeviceWalletSessionStore.ts +78 -0
  153. package/src/deviceProfile/buildDeviceFeatures.ts +365 -0
  154. package/src/deviceProfile/buildDeviceProfile.ts +165 -200
  155. package/src/deviceProfile/index.ts +4 -1
  156. package/src/inject.ts +13 -16
  157. package/src/protocols/protocol-v2/features.ts +28 -67
  158. package/src/protocols/protocol-v2/firmware.ts +12 -36
  159. package/src/protocols/protocol-v2/index.ts +1 -0
  160. package/src/protocols/protocol-v2/walletSession.ts +83 -0
  161. package/src/types/api/firmwareUpdate.ts +16 -20
  162. package/src/types/api/getDeviceInfo.ts +4 -2
  163. package/src/types/api/getPassphraseState.ts +4 -4
  164. package/src/types/api/index.ts +17 -20
  165. package/src/types/api/protocolV2.ts +35 -40
  166. package/src/types/api/sessionCache.ts +14 -0
  167. package/src/types/device.ts +98 -34
  168. package/src/types/params.ts +4 -0
  169. package/src/types/settings.ts +42 -30
  170. package/src/utils/capabilitieUtils.ts +1 -2
  171. package/src/utils/deviceFeaturesUtils.ts +54 -29
  172. package/src/utils/deviceInfoUtils.ts +11 -29
  173. package/src/utils/deviceVersionUtils.ts +7 -25
  174. package/src/utils/findDefectiveBatchDevice.ts +6 -6
  175. package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
  176. package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
  177. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
  178. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
  179. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
  180. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
  181. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
  182. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
  183. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
  184. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
  185. package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
  186. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
  187. package/dist/deviceProfile/legacyFeaturesView.d.ts +0 -5
  188. package/dist/deviceProfile/legacyFeaturesView.d.ts.map +0 -1
  189. package/src/api/protocol-v2/DevReboot.ts +0 -24
  190. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -16
  191. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
  192. package/src/deviceProfile/legacyFeaturesView.ts +0 -123
@@ -3,11 +3,12 @@ import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
3
3
  import { UI_REQUEST } from '../../constants/ui-request';
4
4
  import { PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS } from '../../protocols/protocol-v2';
5
5
  import { BaseMethod } from '../BaseMethod';
6
+ import { invalidParameter } from '../helpers/filesystemValidation';
6
7
 
7
- export type DeviceGetDeviceInfoTargets = {
8
+ export type DeviceInfoGetTargets = {
8
9
  hw?: boolean;
9
10
  fw?: boolean;
10
- bt?: boolean;
11
+ coprocessor?: boolean;
11
12
  se1?: boolean;
12
13
  se2?: boolean;
13
14
  se3?: boolean;
@@ -15,22 +16,22 @@ export type DeviceGetDeviceInfoTargets = {
15
16
  status?: boolean;
16
17
  };
17
18
 
18
- export type DeviceGetDeviceInfoTypes = {
19
+ export type DeviceInfoGetTypes = {
19
20
  version?: boolean;
20
21
  build_id?: boolean;
21
22
  hash?: boolean;
22
23
  specific?: boolean;
23
24
  };
24
25
 
25
- export type DeviceGetDeviceInfoParams = {
26
- targets?: DeviceGetDeviceInfoTargets;
27
- types?: DeviceGetDeviceInfoTypes;
26
+ export type DeviceInfoGetParams = {
27
+ targets?: DeviceInfoGetTargets;
28
+ types?: DeviceInfoGetTypes;
28
29
  };
29
30
 
30
- const TARGET_KEYS: (keyof DeviceGetDeviceInfoTargets)[] = [
31
+ const TARGET_KEYS: (keyof DeviceInfoGetTargets)[] = [
31
32
  'hw',
32
33
  'fw',
33
- 'bt',
34
+ 'coprocessor',
34
35
  'se1',
35
36
  'se2',
36
37
  'se3',
@@ -38,16 +39,16 @@ const TARGET_KEYS: (keyof DeviceGetDeviceInfoTargets)[] = [
38
39
  'status',
39
40
  ];
40
41
 
41
- const TYPE_KEYS: (keyof DeviceGetDeviceInfoTypes)[] = ['version', 'build_id', 'hash', 'specific'];
42
+ const TYPE_KEYS: (keyof DeviceInfoGetTypes)[] = ['version', 'build_id', 'hash', 'specific'];
42
43
 
43
- const DEFAULT_TARGETS: DeviceGetDeviceInfoTargets = {
44
+ const DEFAULT_TARGETS: DeviceInfoGetTargets = {
44
45
  hw: true,
45
46
  fw: true,
46
- bt: true,
47
+ coprocessor: true,
47
48
  status: true,
48
49
  };
49
50
 
50
- const DEFAULT_TYPES: DeviceGetDeviceInfoTypes = {
51
+ const DEFAULT_TYPES: DeviceInfoGetTypes = {
51
52
  version: true,
52
53
  specific: true,
53
54
  };
@@ -69,16 +70,48 @@ function pickBooleanKeys<T extends Record<string, boolean | undefined>>(
69
70
  return hasKey ? result : undefined;
70
71
  }
71
72
 
73
+ function assertKnownKeys(value: unknown, keys: string[], name: string) {
74
+ if (value == null) return;
75
+ if (typeof value !== 'object' || Array.isArray(value)) {
76
+ throw invalidParameter(`Parameter [${name}] must be an object.`);
77
+ }
78
+ const allowed = new Set(keys);
79
+ const unknownKeys = Object.keys(value).filter(key => !allowed.has(key));
80
+ if (unknownKeys.length > 0) {
81
+ throw invalidParameter(
82
+ `Parameter [${name}] contains unsupported key(s): ${unknownKeys.join(', ')}.`
83
+ );
84
+ }
85
+ }
86
+
87
+ function normalizeTargets(value: unknown): DeviceInfoGetTargets | undefined {
88
+ assertKnownKeys(
89
+ value,
90
+ TARGET_KEYS.map(key => String(key)),
91
+ 'targets'
92
+ );
93
+ return pickBooleanKeys<DeviceInfoGetTargets>(value, TARGET_KEYS);
94
+ }
95
+
96
+ function normalizeTypes(value: unknown): DeviceInfoGetTypes | undefined {
97
+ assertKnownKeys(
98
+ value,
99
+ TYPE_KEYS.map(key => String(key)),
100
+ 'types'
101
+ );
102
+ return pickBooleanKeys<DeviceInfoGetTypes>(value, TYPE_KEYS);
103
+ }
104
+
72
105
  /**
73
- * 原生 DevGetDeviceInfo(Protocol V2 only)。
106
+ * 原生 DeviceInfoGet(Protocol V2 only)。
74
107
  *
75
108
  * 与 getDeviceInfo 不同:不构建 DeviceProfile、不更新设备缓存,
76
109
  * 按调用方给定的 targets/types 原样请求并返回未加工的 DeviceInfo 消息,
77
110
  * 用于调试固件字段上报。
78
111
  */
79
- export default class DeviceGetDeviceInfo extends BaseMethod<{
80
- targets: DeviceGetDeviceInfoTargets;
81
- types: DeviceGetDeviceInfoTypes;
112
+ export default class DeviceInfoGet extends BaseMethod<{
113
+ targets: DeviceInfoGetTargets;
114
+ types: DeviceInfoGetTypes;
82
115
  }> {
83
116
  init() {
84
117
  // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
@@ -91,11 +124,8 @@ export default class DeviceGetDeviceInfo extends BaseMethod<{
91
124
  this.useDevicePassphraseState = false;
92
125
  this.skipForceUpdateCheck = true;
93
126
  this.params = {
94
- targets:
95
- pickBooleanKeys<DeviceGetDeviceInfoTargets>(this.payload.targets, TARGET_KEYS) ??
96
- DEFAULT_TARGETS,
97
- types:
98
- pickBooleanKeys<DeviceGetDeviceInfoTypes>(this.payload.types, TYPE_KEYS) ?? DEFAULT_TYPES,
127
+ targets: normalizeTargets(this.payload.targets) ?? DEFAULT_TARGETS,
128
+ types: normalizeTypes(this.payload.types) ?? DEFAULT_TYPES,
99
129
  };
100
130
  }
101
131
 
@@ -105,7 +135,7 @@ export default class DeviceGetDeviceInfo extends BaseMethod<{
105
135
  }
106
136
 
107
137
  const res = await this.device.commands.typedCall(
108
- 'DevGetDeviceInfo',
138
+ 'DeviceInfoGet',
109
139
  'DeviceInfo',
110
140
  {
111
141
  targets: this.params.targets,
@@ -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
 
@@ -17,7 +17,7 @@ export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
17
17
 
18
18
  async run() {
19
19
  const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
20
- reboot_type: normalizeDeviceRebootType(this.params.reboot_type ?? this.params.rebootType),
20
+ reboot_type: normalizeRebootType(this.params.reboot_type ?? this.params.rebootType),
21
21
  });
22
22
  return Promise.resolve(res.message);
23
23
  }
@@ -0,0 +1,26 @@
1
+ import { BaseMethod } from '../BaseMethod';
2
+
3
+ export type DeviceSessionGetParams = {
4
+ sessionId?: string;
5
+ };
6
+
7
+ export default class DeviceSessionGet extends BaseMethod<DeviceSessionGetParams> {
8
+ init() {
9
+ this.requireProtocolV2 = true;
10
+ this.useDevicePassphraseState = false;
11
+ this.skipForceUpdateCheck = true;
12
+ this.params = {
13
+ sessionId: this.payload.sessionId,
14
+ };
15
+ }
16
+
17
+ async run() {
18
+ const payload = this.params.sessionId ? { session_id: this.params.sessionId } : {};
19
+ const { message } = await this.device.commands.typedCall(
20
+ 'DeviceSessionGet',
21
+ 'DeviceSession',
22
+ payload
23
+ );
24
+ return message;
25
+ }
26
+ }
@@ -0,0 +1,14 @@
1
+ import { BaseMethod } from '../BaseMethod';
2
+
3
+ export default class DeviceStatusGet extends BaseMethod {
4
+ init() {
5
+ this.requireProtocolV2 = true;
6
+ this.useDevicePassphraseState = false;
7
+ this.skipForceUpdateCheck = true;
8
+ }
9
+
10
+ async run() {
11
+ const { message } = await this.device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
12
+ return message;
13
+ }
14
+ }
@@ -10,7 +10,10 @@ export default class FilesystemFormat extends BaseMethod {
10
10
  }
11
11
 
12
12
  async run() {
13
- const res = await this.device.commands.typedCall('FilesystemFormat', 'Success', {});
13
+ const res = await this.device.commands.typedCall('FilesystemFormat', 'Success', {
14
+ data: true,
15
+ user: true,
16
+ });
14
17
  return Promise.resolve(res.message);
15
18
  }
16
19
  }
@@ -1,6 +1,6 @@
1
1
  import { BaseMethod } from '../BaseMethod';
2
2
 
3
- export default class FilesystemFixPermission extends BaseMethod {
3
+ export default class FilesystemPermissionFix extends BaseMethod {
4
4
  init() {
5
5
  // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
6
6
  this.requireProtocolV2 = true;
@@ -10,7 +10,7 @@ export default class FilesystemFixPermission extends BaseMethod {
10
10
  }
11
11
 
12
12
  async run() {
13
- const res = await this.device.commands.typedCall('FilesystemFixPermission', 'Success', {});
13
+ const res = await this.device.commands.typedCall('FilesystemPermissionFix', 'Success', {});
14
14
  return Promise.resolve(res.message);
15
15
  }
16
16
  }
@@ -1,6 +1,6 @@
1
1
  import { BaseMethod } from '../BaseMethod';
2
2
 
3
- export default class GetProtoVersion extends BaseMethod {
3
+ export default class ProtocolInfoRequest extends BaseMethod {
4
4
  init() {
5
5
  // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
6
6
  this.requireProtocolV2 = true;
@@ -10,7 +10,7 @@ export default class GetProtoVersion extends BaseMethod {
10
10
  }
11
11
 
12
12
  async run() {
13
- const res = await this.device.commands.typedCall('GetProtoVersion', 'ProtoVersion', {});
13
+ const res = await this.device.commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {});
14
14
  return Promise.resolve(res.message);
15
15
  }
16
16
  }
@@ -1,20 +1,16 @@
1
- import { DevRebootType, DeviceRebootType } from '@onekeyfe/hd-transport';
1
+ import { DeviceRebootType } from '@onekeyfe/hd-transport';
2
2
 
3
3
  import { invalidParameter, validateNonEmptyString } from '../helpers/filesystemValidation';
4
+ import { ProtocolV2FirmwareTargetType } from '../../protocols/protocol-v2/firmware';
4
5
 
5
6
  import type {
6
- DevFirmwareTarget,
7
- DevFirmwareTargetType,
7
+ DeviceFirmwareTarget,
8
+ DeviceFirmwareTargetType,
9
+ DeviceFirmwareUpdateRecordFields,
8
10
  TransportCallOptions,
9
11
  } from '@onekeyfe/hd-transport';
10
12
 
11
- export type RebootTypeInput =
12
- | DevRebootType
13
- | DeviceRebootType
14
- | keyof typeof DevRebootType
15
- | keyof typeof DeviceRebootType
16
- | string
17
- | number;
13
+ export type RebootTypeInput = DeviceRebootType | keyof typeof DeviceRebootType | string | number;
18
14
 
19
15
  export type DeviceRebootParams = {
20
16
  rebootType?: RebootTypeInput;
@@ -22,38 +18,37 @@ export type DeviceRebootParams = {
22
18
  };
23
19
 
24
20
  export type DeviceFirmwareTargetInput =
25
- | DevFirmwareTarget
21
+ | DeviceFirmwareTarget
26
22
  | {
27
- targetId?: DevFirmwareTargetType | string | number;
28
- target_id?: DevFirmwareTargetType | string | number;
23
+ targetId?: DeviceFirmwareTargetType | string | number;
24
+ target_id?: DeviceFirmwareTargetType | string | number;
29
25
  path: string;
30
26
  };
31
27
 
32
28
  export type DeviceFirmwareUpdateParams = {
33
29
  targets?: DeviceFirmwareTargetInput[];
34
- targetId?: DevFirmwareTargetType | string | number;
35
- target_id?: DevFirmwareTargetType | string | number;
30
+ targetId?: DeviceFirmwareTargetType | string | number;
31
+ target_id?: DeviceFirmwareTargetType | string | number;
36
32
  path?: string;
37
33
  };
38
34
 
39
- export type FactoryDeviceInfoSettingsParams = {
40
- serial_no?: string;
41
- serialNo?: string;
42
- cpu_info?: string;
43
- cpuInfo?: string;
44
- pre_firmware?: string;
45
- preFirmware?: string;
35
+ export type DeviceFirmwareUpdateStatusGetParams = {
36
+ fields?: DeviceFirmwareUpdateRecordFields;
46
37
  };
47
38
 
48
- const DEV_REBOOT_TYPES: Record<string, DevRebootType> = {
49
- Normal: DevRebootType.Normal,
50
- normal: DevRebootType.Normal,
51
- Romloader: DevRebootType.Boardloader,
52
- romloader: DevRebootType.Boardloader,
53
- Boardloader: DevRebootType.Boardloader,
54
- boardloader: DevRebootType.Boardloader,
55
- Bootloader: DevRebootType.Bootloader,
56
- bootloader: DevRebootType.Bootloader,
39
+ export type DeviceFactoryInfoSetParams = {
40
+ version?: number;
41
+ serial_number?: string;
42
+ burn_in_completed?: boolean;
43
+ factory_test_completed?: boolean;
44
+ manufacture_time?: {
45
+ year: number;
46
+ month: number;
47
+ day: number;
48
+ hour: number;
49
+ minute: number;
50
+ second: number;
51
+ };
57
52
  };
58
53
 
59
54
  const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
@@ -68,13 +63,13 @@ const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
68
63
  };
69
64
 
70
65
  export const PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS: TransportCallOptions = {
71
- intermediateTypes: ['DevFirmwareInstallProgress'],
66
+ intermediateTypes: ['DeviceFirmwareUpdateStatus'],
72
67
  };
73
68
 
74
69
  export const PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES: (
75
70
  | 'Success'
76
- | 'DevFirmwareUpdateStatus'
77
- )[] = ['Success', 'DevFirmwareUpdateStatus'];
71
+ | 'DeviceFirmwareUpdateStatus'
72
+ )[] = ['Success', 'DeviceFirmwareUpdateStatus'];
78
73
 
79
74
  export const getProtocolV2UnknownErrorText = (error: unknown) => {
80
75
  if (!error) {
@@ -133,19 +128,7 @@ export const isProtocolV2DeviceDisconnectedError = (error: unknown) => {
133
128
  );
134
129
  };
135
130
 
136
- export function normalizeRebootType(value: RebootTypeInput | undefined): DevRebootType {
137
- if (typeof value === 'number') return value;
138
- if (typeof value === 'string') {
139
- const numeric = Number(value);
140
- if (Number.isFinite(numeric)) return numeric;
141
- if (value in DEV_REBOOT_TYPES) return DEV_REBOOT_TYPES[value];
142
- }
143
- return DevRebootType.Normal;
144
- }
145
-
146
- export function normalizeDeviceRebootType(
147
- value: RebootTypeInput | undefined
148
- ): DeviceRebootType {
131
+ export function normalizeRebootType(value: RebootTypeInput | undefined): DeviceRebootType {
149
132
  if (typeof value === 'number') return value;
150
133
  if (typeof value === 'string') {
151
134
  const numeric = Number(value);
@@ -155,30 +138,46 @@ export function normalizeDeviceRebootType(
155
138
  return DeviceRebootType.Normal;
156
139
  }
157
140
 
158
- // 当前 firmware-pro2 子模块的 DevFirmwareTargetType 合法值。
159
- const VALID_FIRMWARE_TARGET_IDS = new Set<number>([0, 1, 2, 3, 4, 5, 6, 10]);
141
+ // firmware-pro2 proto_target_to_firmware_target 安装白名单保持一致。
142
+ const INSTALLABLE_FIRMWARE_TARGET_IDS = new Set<number>([
143
+ ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_CRATE,
144
+ ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
145
+ ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1,
146
+ ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P2,
147
+ ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR,
148
+ ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE01,
149
+ ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE02,
150
+ ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE03,
151
+ ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04,
152
+ ]);
153
+ const FIRMWARE_TARGET_ID_BY_NAME = new Map<string, DeviceFirmwareTargetType>(
154
+ Object.entries(ProtocolV2FirmwareTargetType).flatMap(([key, value]) =>
155
+ INSTALLABLE_FIRMWARE_TARGET_IDS.has(value) ? [[key, value as DeviceFirmwareTargetType]] : []
156
+ )
157
+ );
160
158
 
161
159
  function normalizeTargetId(
162
- value: DevFirmwareTargetType | string | number | undefined,
160
+ value: DeviceFirmwareTargetType | string | number | undefined,
163
161
  name: string
164
- ): DevFirmwareTargetType {
162
+ ): DeviceFirmwareTargetType {
165
163
  if (value === undefined || value === null) {
166
164
  throw invalidParameter(`Missing required parameter: ${name}`);
167
165
  }
168
- const numeric = typeof value === 'number' ? value : Number(value);
169
- // 校验值域:仅接受 DevFirmwareTargetType 中定义的 target id,
170
- // 不再放行任意非负整数。
171
- if (Number.isSafeInteger(numeric) && VALID_FIRMWARE_TARGET_IDS.has(numeric)) {
172
- return numeric as DevFirmwareTargetType;
166
+ const named = typeof value === 'string' ? FIRMWARE_TARGET_ID_BY_NAME.get(value) : undefined;
167
+ const numeric = named ?? (typeof value === 'number' ? value : Number(value));
168
+ if (Number.isSafeInteger(numeric) && INSTALLABLE_FIRMWARE_TARGET_IDS.has(numeric)) {
169
+ return numeric as DeviceFirmwareTargetType;
173
170
  }
174
171
  throw invalidParameter(
175
- `Parameter [${name}] must be a valid firmware target id (one of ${[
176
- ...VALID_FIRMWARE_TARGET_IDS,
172
+ `Parameter [${name}] must be an installable firmware target id (one of ${[
173
+ ...INSTALLABLE_FIRMWARE_TARGET_IDS,
177
174
  ].join(', ')}).`
178
175
  );
179
176
  }
180
177
 
181
- export function normalizeFirmwareTargets(params: DeviceFirmwareUpdateParams): DevFirmwareTarget[] {
178
+ export function normalizeFirmwareTargets(
179
+ params: DeviceFirmwareUpdateParams
180
+ ): DeviceFirmwareTarget[] {
182
181
  const targets =
183
182
  params.targets ??
184
183
  (params.path
@@ -51,11 +51,7 @@ export default class TonSignData extends BaseMethod<HardwareTonSignData> {
51
51
  }
52
52
 
53
53
  getVersionRange() {
54
- return {
55
- pro2: {
56
- min: '0.0.0',
57
- },
58
- };
54
+ return {};
59
55
  }
60
56
 
61
57
  async run() {
@@ -47,7 +47,6 @@ export default class TronSignMessage extends BaseMethod<HardwareTronSignMessage>
47
47
  return {
48
48
  pro2: {
49
49
  min: '0.0.0',
50
- unsupported: true,
51
50
  },
52
51
  model_mini: {
53
52
  min: '2.5.0',
@@ -150,7 +150,6 @@ export default class TronSignTransaction extends BaseMethod<TronSignTx> {
150
150
  return {
151
151
  pro2: {
152
152
  min: '0.0.0',
153
- unsupported: true,
154
153
  },
155
154
  model_mini: {
156
155
  min: '2.5.0',
@@ -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
@@ -57,16 +57,12 @@ import DeviceConnector from '../device/DeviceConnector';
57
57
  import RequestQueue from './RequestQueue';
58
58
  import { getSynchronize } from '../utils/getSynchronize';
59
59
 
60
- import type { ConnectSettings, KnownDevice } from '../types';
60
+ import type { ConnectSettings, Features, KnownDevice } from '../types';
61
61
  import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
62
62
  import type { DeviceEvents, InitOptions, RunOptions } from '../device/Device';
63
63
  import type { SdkTracingContext } from '../utils/tracing';
64
64
  import type { Deferred } from '@onekeyfe/hd-shared';
65
- import type {
66
- Features,
67
- LowlevelTransportSharedPlugin,
68
- OneKeyDeviceInfo,
69
- } from '@onekeyfe/hd-transport';
65
+ import type { LowlevelTransportSharedPlugin, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
70
66
  import type { BaseMethod } from '../api/BaseMethod';
71
67
 
72
68
  const Log = getLogger(LoggerNames.Core);
@@ -99,6 +95,7 @@ const parseInitOptions = (method?: BaseMethod): InitOptions => ({
99
95
  deviceId: method?.payload.deviceId,
100
96
  deriveCardano: method && hasDeriveCardano(method),
101
97
  connectProtocol: method?.payload.connectProtocol,
98
+ protocolV2DeviceInfoTimeoutMs: method?.payload.protocolV2DeviceInfoTimeoutMs,
102
99
  });
103
100
 
104
101
  let _core: Core;
@@ -226,9 +223,15 @@ const handlePreWarmSignal = async (
226
223
  message: CoreMessage,
227
224
  method: BaseMethod
228
225
  ): Promise<any> => {
226
+ const createAckResponse = () => {
227
+ completeMethodRequestContext(method);
228
+ method.dispose();
229
+ return createResponseMessage(method.responseID, true, true);
230
+ };
231
+
229
232
  // no connectId: can't target a device safely, skip pre-warm (ack only)
230
233
  if (!method.connectId) {
231
- return createResponseMessage(method.responseID, true, true);
234
+ return createAckResponse();
232
235
  }
233
236
 
234
237
  const key = method.getPreWarmKey();
@@ -241,12 +244,12 @@ const handlePreWarmSignal = async (
241
244
  } catch {
242
245
  // pre-warm is best-effort; ignore its failure for the coalesced caller
243
246
  }
244
- return createResponseMessage(method.responseID, true, true);
247
+ return createAckResponse();
245
248
  }
246
249
 
247
250
  const doneAt = preWarmDoneAt.get(key);
248
251
  if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
249
- return createResponseMessage(method.responseID, true, true);
252
+ return createAckResponse();
250
253
  }
251
254
 
252
255
  const run = onCallDevice(context, message, method);
@@ -735,6 +738,15 @@ function initDevice(method: BaseMethod) {
735
738
 
736
739
  if (method.connectId) {
737
740
  device = _deviceList.getDevice(method.connectId);
741
+ if (!device && method.name === 'firmwareUpdateV4' && allDevices.length === 1) {
742
+ const [singleDevice] = allDevices;
743
+ if (singleDevice.isBootloader()) {
744
+ Log.debug(
745
+ 'firmwareUpdateV4 uses the only bootloader device when connectId changed after reboot'
746
+ );
747
+ device = singleDevice;
748
+ }
749
+ }
738
750
  } else if (allDevices.length === 1) {
739
751
  [device] = allDevices;
740
752
  } else if (allDevices.length > 1) {
@@ -1115,7 +1127,7 @@ const checkPassphraseEnableState = (method: BaseMethod, features?: Features) =>
1115
1127
 
1116
1128
  const passphraseProtection = method.device
1117
1129
  ? method.device.getCurrentPassphraseProtection()
1118
- : features?.passphrase_protection;
1130
+ : features?.passphraseProtection;
1119
1131
 
1120
1132
  if (passphraseProtection === true) {
1121
1133
  const hasNoPassphraseState =