@onekeyfe/hd-core 1.1.26 → 1.1.27-alpha.31

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 (186) hide show
  1. package/__tests__/evmSignTransaction.test.ts +1 -1
  2. package/__tests__/evmSignTypedData.test.ts +1 -1
  3. package/__tests__/protocol-v2.test.ts +1096 -0
  4. package/dist/api/BaseMethod.d.ts +1 -3
  5. package/dist/api/BaseMethod.d.ts.map +1 -1
  6. package/dist/api/DirList.d.ts +10 -0
  7. package/dist/api/DirList.d.ts.map +1 -0
  8. package/dist/api/DirMake.d.ts +9 -0
  9. package/dist/api/DirMake.d.ts.map +1 -0
  10. package/dist/api/DirRemove.d.ts +9 -0
  11. package/dist/api/DirRemove.d.ts.map +1 -0
  12. package/dist/api/FileDelete.d.ts +9 -0
  13. package/dist/api/FileDelete.d.ts.map +1 -0
  14. package/dist/api/FileRead.d.ts +19 -0
  15. package/dist/api/FileRead.d.ts.map +1 -0
  16. package/dist/api/FileWrite.d.ts +23 -0
  17. package/dist/api/FileWrite.d.ts.map +1 -0
  18. package/dist/api/FirmwareUpdateV3.d.ts +1 -0
  19. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  20. package/dist/api/FirmwareUpdateV4.d.ts +32 -0
  21. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
  22. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  23. package/dist/api/GetPassphraseState.d.ts +6 -1
  24. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  25. package/dist/api/PathInfo.d.ts +9 -0
  26. package/dist/api/PathInfo.d.ts.map +1 -0
  27. package/dist/api/SearchDevices.d.ts +2 -1
  28. package/dist/api/SearchDevices.d.ts.map +1 -1
  29. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  30. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  31. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
  32. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  33. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  34. package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
  35. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  36. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
  37. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  38. package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
  39. package/dist/api/index.d.ts +26 -0
  40. package/dist/api/index.d.ts.map +1 -1
  41. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
  42. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
  43. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +7 -0
  44. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
  45. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
  46. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
  47. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
  48. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
  49. package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
  50. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
  51. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
  52. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
  53. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
  54. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
  55. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
  56. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
  57. package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
  58. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
  59. package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
  60. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
  61. package/dist/api/protocol-v2/Ping.d.ts +8 -0
  62. package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
  63. package/dist/api/protocol-v2/helpers.d.ts +49 -0
  64. package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
  65. package/dist/core/index.d.ts.map +1 -1
  66. package/dist/data-manager/DataManager.d.ts +7 -4
  67. package/dist/data-manager/DataManager.d.ts.map +1 -1
  68. package/dist/data-manager/MessagesConfig.d.ts +2 -2
  69. package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
  70. package/dist/data-manager/TransportManager.d.ts +5 -4
  71. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  72. package/dist/device/Device.d.ts +5 -3
  73. package/dist/device/Device.d.ts.map +1 -1
  74. package/dist/device/DeviceCommands.d.ts +8 -8
  75. package/dist/device/DeviceCommands.d.ts.map +1 -1
  76. package/dist/device/DeviceConnector.d.ts +2 -1
  77. package/dist/device/DeviceConnector.d.ts.map +1 -1
  78. package/dist/events/ui-request.d.ts +8 -0
  79. package/dist/events/ui-request.d.ts.map +1 -1
  80. package/dist/index.d.ts +198 -23
  81. package/dist/index.js +15726 -806
  82. package/dist/inject.d.ts.map +1 -1
  83. package/dist/protocols/protocol-v2/features.d.ts +57 -0
  84. package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
  85. package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
  86. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
  87. package/dist/protocols/protocol-v2/index.d.ts +3 -0
  88. package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
  89. package/dist/types/api/export.d.ts +1 -1
  90. package/dist/types/api/export.d.ts.map +1 -1
  91. package/dist/types/api/firmwareUpdate.d.ts +7 -0
  92. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  93. package/dist/types/api/getPassphraseState.d.ts +7 -1
  94. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  95. package/dist/types/api/index.d.ts +29 -1
  96. package/dist/types/api/index.d.ts.map +1 -1
  97. package/dist/types/api/protocolV2.d.ts +123 -0
  98. package/dist/types/api/protocolV2.d.ts.map +1 -0
  99. package/dist/types/api/searchDevices.d.ts +2 -2
  100. package/dist/types/api/searchDevices.d.ts.map +1 -1
  101. package/dist/types/device.d.ts +1 -1
  102. package/dist/types/device.d.ts.map +1 -1
  103. package/dist/types/params.d.ts +2 -0
  104. package/dist/types/params.d.ts.map +1 -1
  105. package/dist/types/settings.d.ts +1 -1
  106. package/dist/types/settings.d.ts.map +1 -1
  107. package/dist/utils/deviceFeaturesUtils.d.ts +3 -3
  108. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  109. package/dist/utils/deviceInfoUtils.d.ts +1 -0
  110. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  111. package/dist/utils/index.d.ts +1 -1
  112. package/dist/utils/index.d.ts.map +1 -1
  113. package/dist/utils/patch.d.ts +1 -1
  114. package/dist/utils/patch.d.ts.map +1 -1
  115. package/dist/utils/versionUtils.d.ts +1 -1
  116. package/package.json +4 -4
  117. package/src/api/BaseMethod.ts +12 -60
  118. package/src/api/DirList.ts +25 -0
  119. package/src/api/DirMake.ts +20 -0
  120. package/src/api/DirRemove.ts +20 -0
  121. package/src/api/FileDelete.ts +20 -0
  122. package/src/api/FileRead.ts +158 -0
  123. package/src/api/FileWrite.ts +191 -0
  124. package/src/api/FirmwareUpdateV3.ts +21 -4
  125. package/src/api/FirmwareUpdateV4.ts +810 -0
  126. package/src/api/GetOnekeyFeatures.ts +75 -3
  127. package/src/api/GetPassphraseState.ts +14 -2
  128. package/src/api/PathInfo.ts +24 -0
  129. package/src/api/SearchDevices.ts +7 -2
  130. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +25 -9
  131. package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
  132. package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
  133. package/src/api/device/DeviceRebootToBootloader.ts +10 -1
  134. package/src/api/dynex/DnxGetAddress.ts +7 -0
  135. package/src/api/dynex/DnxSignTransaction.ts +7 -0
  136. package/src/api/evm/EVMGetAddress.ts +1 -1
  137. package/src/api/evm/EVMGetPublicKey.ts +1 -1
  138. package/src/api/evm/EVMSignMessage.ts +1 -1
  139. package/src/api/evm/EVMSignTransaction.ts +1 -1
  140. package/src/api/evm/EVMSignTypedData.ts +6 -6
  141. package/src/api/evm/EVMVerifyMessage.ts +1 -1
  142. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
  143. package/src/api/helpers/batchGetPublickeys.ts +4 -2
  144. package/src/api/index.ts +28 -0
  145. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +33 -0
  146. package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +35 -0
  147. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +18 -0
  148. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
  149. package/src/api/protocol-v2/DeviceReboot.ts +22 -0
  150. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
  151. package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
  152. package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
  153. package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
  154. package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
  155. package/src/api/protocol-v2/Ping.ts +16 -0
  156. package/src/api/protocol-v2/helpers.ts +138 -0
  157. package/src/api/tron/TronSignMessage.ts +1 -1
  158. package/src/api/xrp/XrpSignTransaction.ts +1 -1
  159. package/src/core/index.ts +31 -5
  160. package/src/data/messages/messages-pro2.json +13106 -0
  161. package/src/data-manager/DataManager.ts +12 -7
  162. package/src/data-manager/MessagesConfig.ts +14 -14
  163. package/src/data-manager/TransportManager.ts +38 -12
  164. package/src/device/Device.ts +73 -9
  165. package/src/device/DeviceCommands.ts +162 -26
  166. package/src/device/DeviceConnector.ts +29 -4
  167. package/src/device/DevicePool.ts +1 -1
  168. package/src/events/ui-request.ts +8 -0
  169. package/src/inject.ts +42 -1
  170. package/src/protocols/protocol-v2/features.ts +267 -0
  171. package/src/protocols/protocol-v2/firmware.ts +26 -0
  172. package/src/protocols/protocol-v2/index.ts +2 -0
  173. package/src/types/api/export.ts +1 -0
  174. package/src/types/api/firmwareUpdate.ts +12 -0
  175. package/src/types/api/getPassphraseState.ts +10 -1
  176. package/src/types/api/index.ts +64 -1
  177. package/src/types/api/protocolV2.ts +221 -0
  178. package/src/types/api/searchDevices.ts +2 -2
  179. package/src/types/device.ts +3 -1
  180. package/src/types/params.ts +7 -0
  181. package/src/types/settings.ts +1 -1
  182. package/src/utils/deviceFeaturesUtils.ts +33 -15
  183. package/src/utils/deviceInfoUtils.ts +14 -5
  184. package/src/utils/index.ts +1 -0
  185. package/__tests__/DeviceCommands.test.ts +0 -99
  186. package/__tests__/evmLedgerLegacySafety.test.ts +0 -261
@@ -4,6 +4,76 @@ import { UI_REQUEST } from '../constants/ui-request';
4
4
  import { fixVersion } from '../utils/deviceFeaturesUtils';
5
5
  import { BaseMethod } from './BaseMethod';
6
6
 
7
+ import type { OnekeyFeatures } from '../types';
8
+
9
+ const ONEKEY_FEATURE_KEYS: Array<keyof OnekeyFeatures> = [
10
+ 'onekey_device_type',
11
+ 'onekey_board_version',
12
+ 'onekey_boot_version',
13
+ 'onekey_firmware_version',
14
+ 'onekey_board_hash',
15
+ 'onekey_boot_hash',
16
+ 'onekey_firmware_hash',
17
+ 'onekey_board_build_id',
18
+ 'onekey_boot_build_id',
19
+ 'onekey_firmware_build_id',
20
+ 'onekey_serial_no',
21
+ 'onekey_ble_name',
22
+ 'onekey_ble_version',
23
+ 'onekey_ble_build_id',
24
+ 'onekey_ble_hash',
25
+ 'onekey_se_type',
26
+ 'onekey_se01_state',
27
+ 'onekey_se02_state',
28
+ 'onekey_se03_state',
29
+ 'onekey_se04_state',
30
+ 'onekey_se01_version',
31
+ 'onekey_se02_version',
32
+ 'onekey_se03_version',
33
+ 'onekey_se04_version',
34
+ 'onekey_se01_hash',
35
+ 'onekey_se02_hash',
36
+ 'onekey_se03_hash',
37
+ 'onekey_se04_hash',
38
+ 'onekey_se01_build_id',
39
+ 'onekey_se02_build_id',
40
+ 'onekey_se03_build_id',
41
+ 'onekey_se04_build_id',
42
+ 'onekey_se01_boot_version',
43
+ 'onekey_se02_boot_version',
44
+ 'onekey_se03_boot_version',
45
+ 'onekey_se04_boot_version',
46
+ 'onekey_se01_boot_hash',
47
+ 'onekey_se02_boot_hash',
48
+ 'onekey_se03_boot_hash',
49
+ 'onekey_se04_boot_hash',
50
+ 'onekey_se01_boot_build_id',
51
+ 'onekey_se02_boot_build_id',
52
+ 'onekey_se03_boot_build_id',
53
+ 'onekey_se04_boot_build_id',
54
+ ];
55
+
56
+ function normalizeOnekeyFirmwareVersion(message: OnekeyFeatures) {
57
+ if (message.onekey_firmware_version && !semver.valid(message.onekey_firmware_version)) {
58
+ message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
59
+ }
60
+ }
61
+
62
+ function pickOnekeyFeatures(features?: OnekeyFeatures | null): OnekeyFeatures {
63
+ const message: OnekeyFeatures = {};
64
+ if (!features) return message;
65
+
66
+ for (const key of ONEKEY_FEATURE_KEYS) {
67
+ const value = features[key];
68
+ if (value !== undefined && value !== null) {
69
+ (message as Record<string, unknown>)[key] = value;
70
+ }
71
+ }
72
+
73
+ normalizeOnekeyFirmwareVersion(message);
74
+ return message;
75
+ }
76
+
7
77
  export default class GetOnekeyFeatures extends BaseMethod {
8
78
  init() {
9
79
  this.allowDeviceMode = [
@@ -16,10 +86,12 @@ export default class GetOnekeyFeatures extends BaseMethod {
16
86
  }
17
87
 
18
88
  async run() {
19
- const { message } = await this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
20
- if (!!message.onekey_firmware_version && !semver.valid(message.onekey_firmware_version)) {
21
- message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
89
+ if (this.device.originalDescriptor?.protocolType === 'V2') {
90
+ return Promise.resolve(pickOnekeyFeatures(this.device.features as OnekeyFeatures));
22
91
  }
92
+
93
+ const { message } = await this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
94
+ normalizeOnekeyFirmwareVersion(message);
23
95
  return Promise.resolve(message);
24
96
  }
25
97
  }
@@ -1,7 +1,8 @@
1
- import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
1
+ import { EDeviceType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
2
 
3
3
  import { UI_REQUEST } from '../constants/ui-request';
4
4
  import { getPassphraseStateWithRefreshDeviceInfo } from '../utils/deviceFeaturesUtils';
5
+ import { getDeviceType } from '../utils/deviceInfoUtils';
5
6
  import { BaseMethod } from './BaseMethod';
6
7
 
7
8
  export default class GetPassphraseState extends BaseMethod {
@@ -14,9 +15,20 @@ export default class GetPassphraseState extends BaseMethod {
14
15
  if (!this.device.features)
15
16
  return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
16
17
 
17
- const { passphraseState } = await getPassphraseStateWithRefreshDeviceInfo(this.device);
18
+ const { passphraseState, newSession, unlockedAttachPin } =
19
+ await getPassphraseStateWithRefreshDeviceInfo(this.device);
18
20
 
19
21
  const { features } = this.device;
22
+ const isPro2 = getDeviceType(features) === EDeviceType.Pro2;
23
+
24
+ if (isPro2) {
25
+ return Promise.resolve({
26
+ passphrase_state: passphraseState,
27
+ session_id: newSession ?? features?.session_id ?? undefined,
28
+ unlocked_attach_pin: unlockedAttachPin,
29
+ passphrase_protection: features?.passphrase_protection ?? null,
30
+ });
31
+ }
20
32
 
21
33
  // refresh device info
22
34
  if (features && features.passphrase_protection === true) {
@@ -0,0 +1,24 @@
1
+ import { BaseMethod } from './BaseMethod';
2
+
3
+ export type PathInfoParams = {
4
+ path: string;
5
+ };
6
+
7
+ export default class PathInfo extends BaseMethod<PathInfoParams> {
8
+ init() {
9
+ this.skipForceUpdateCheck = true;
10
+ this.useDevicePassphraseState = false;
11
+ this.params = { path: this.payload.path };
12
+ }
13
+
14
+ async run() {
15
+ const res = await this.device.commands.typedCall(
16
+ 'FilesystemPathInfoQuery',
17
+ 'FilesystemPathInfo',
18
+ {
19
+ path: this.params.path,
20
+ }
21
+ );
22
+ return Promise.resolve(res.message);
23
+ }
24
+ }
@@ -34,17 +34,22 @@ export default class SearchDevices extends BaseMethod {
34
34
  const lowerId = device.id?.toLowerCase();
35
35
  if (!seenIds.has(lowerId)) {
36
36
  seenIds.add(lowerId);
37
+ const bleName =
38
+ device.name ?? (device as unknown as { localName?: string }).localName ?? '';
37
39
  devices.push({
38
40
  ...device,
39
41
  connectId: device.id,
40
- deviceType: getDeviceTypeByBleName(device.name ?? ''),
42
+ name: bleName || device.name,
43
+ deviceType: getDeviceTypeByBleName(bleName),
41
44
  });
42
45
  }
43
46
  }
44
47
  return devices;
45
48
  }
46
49
 
47
- const { deviceList } = await DevicePool.getDevices(devicesDescriptor);
50
+ const { deviceList } = await DevicePool.getDevices(devicesDescriptor, undefined, {
51
+ connectProtocol: this.payload.connectProtocol,
52
+ });
48
53
  return deviceList.map(device => device.toMessageObject());
49
54
  }
50
55
  }
@@ -12,7 +12,12 @@ import { validateParams } from '../helpers/paramsValidator';
12
12
  import { PROTO } from '../../constants';
13
13
  import { findMethod } from '../utils';
14
14
  import { DEVICE, IFRAME, createUiMessage } from '../../events';
15
- import { getDeviceFirmwareVersion, getFirmwareType, getMethodVersionRange } from '../../utils';
15
+ import {
16
+ getDeviceFirmwareVersion,
17
+ getFirmwareType,
18
+ getMethodVersionRange,
19
+ shouldSkipMethodSupportCheck,
20
+ } from '../../utils';
16
21
  import { UI_REQUEST } from '../../constants/ui-request';
17
22
  import { onDeviceButtonHandler } from '../../core';
18
23
  import {
@@ -371,14 +376,6 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
371
376
  this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
372
377
 
373
378
  preCheckDeviceSupport(this.device, method);
374
- if (this.temporarySafetyCheckPrompted) {
375
- method.temporarySafetyCheckPrompted = true;
376
- } else {
377
- const appliedTemporarySafetyCheck = await method.checkSafetyLevelOnTestNet();
378
- if (appliedTemporarySafetyCheck) {
379
- this.temporarySafetyCheckPrompted = true;
380
- }
381
- }
382
379
 
383
380
  const response = await method.run();
384
381
 
@@ -463,6 +460,10 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
463
460
  * @param method BaseMethod
464
461
  */
465
462
  function preCheckDeviceSupport(device: Device, method: BaseMethod) {
463
+ if (shouldSkipMethodSupportCheck(device.features, device.originalDescriptor?.protocolType)) {
464
+ return;
465
+ }
466
+
466
467
  const versionRange = getMethodVersionRange(
467
468
  device.features,
468
469
  type => method.getVersionRange()[type]
@@ -491,9 +492,20 @@ function handleSkippableHardwareError(
491
492
  method: BaseMethod
492
493
  ): HardwareError | undefined {
493
494
  let error: HardwareError | undefined;
495
+ const skipMethodSupportCheck = shouldSkipMethodSupportCheck(
496
+ device.features,
497
+ device.originalDescriptor?.protocolType
498
+ );
494
499
 
495
500
  if (e instanceof HardwareError && e.errorCode !== HardwareErrorCode.RuntimeError) {
496
501
  const { errorCode } = e;
502
+ if (
503
+ skipMethodSupportCheck &&
504
+ (errorCode === HardwareErrorCode.CallMethodNeedUpgradeFirmware ||
505
+ errorCode === HardwareErrorCode.DeviceNotSupportMethod)
506
+ ) {
507
+ return undefined;
508
+ }
497
509
  if (errorCode === HardwareErrorCode.CallMethodNeedUpgradeFirmware) {
498
510
  error = e;
499
511
  } else if (errorCode === HardwareErrorCode.DeviceNotSupportMethod) {
@@ -503,6 +515,10 @@ function handleSkippableHardwareError(
503
515
  e.message?.includes('Failure_UnexpectedMessage') ||
504
516
  e.message?.includes('Failure_UnknownMessage')
505
517
  ) {
518
+ if (skipMethodSupportCheck) {
519
+ return undefined;
520
+ }
521
+
506
522
  const versionRange = getMethodVersionRange(
507
523
  device.features,
508
524
  type => method.getVersionRange()[type]
@@ -34,7 +34,7 @@ export default class ConfluxSignTransaction extends BaseMethod {
34
34
 
35
35
  // check if transaction is valid
36
36
  const schema: SchemaParam[] = [
37
- { name: 'to', type: 'hexString', required: true },
37
+ { name: 'to', type: 'string', required: true },
38
38
  { name: 'value', type: 'hexString', required: true },
39
39
  { name: 'gasLimit', type: 'hexString', required: true },
40
40
  { name: 'gasPrice', type: 'hexString', required: true },
@@ -47,7 +47,10 @@ export default class ConfluxSignTransaction extends BaseMethod {
47
47
 
48
48
  validateParams(tx, schema);
49
49
 
50
- this.formattedTx = formatAnyHex(tx);
50
+ this.formattedTx = {
51
+ ...formatAnyHex(tx),
52
+ to: tx.to,
53
+ };
51
54
  }
52
55
 
53
56
  processTxRequest = async (request: ConfluxTxRequest, data: string): Promise<ConfluxSignedTx> => {
@@ -1,3 +1,5 @@
1
+ import { DeviceRebootType } from '@onekeyfe/hd-transport';
2
+
1
3
  import { BaseMethod } from '../BaseMethod';
2
4
 
3
5
  import type { RebootToBoardloaderParams } from '../../types/api/deviceRebootToBoardloader';
@@ -21,10 +23,17 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
21
23
  }
22
24
 
23
25
  async run() {
26
+ // Protocol V2 uses DeviceReboot with reboot_type enum.
27
+ if (this.device.originalDescriptor?.protocolType === 'V2') {
28
+ const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
29
+ reboot_type: DeviceRebootType.Boardloader,
30
+ });
31
+ return Promise.resolve(res.message);
32
+ }
33
+
24
34
  // On Touch devices, messsage code 904 is RebootToBoardloader
25
35
  // so BininOutMessageSE message code 904 is used here
26
36
  const res = await this.device.commands.typedCall('BixinOutMessageSE', 'Success');
27
-
28
37
  return Promise.resolve(res.message);
29
38
  }
30
39
  }
@@ -1,3 +1,5 @@
1
+ import { DeviceRebootType } from '@onekeyfe/hd-transport';
2
+
1
3
  import { BaseMethod } from '../BaseMethod';
2
4
 
3
5
  import type { RebootToBootloader } from '@onekeyfe/hd-transport';
@@ -21,8 +23,15 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
21
23
  }
22
24
 
23
25
  async run() {
24
- const res = await this.device.commands.typedCall('RebootToBootloader', 'Success');
26
+ // Protocol V2 uses DeviceReboot with reboot_type enum.
27
+ if (this.device.originalDescriptor?.protocolType === 'V2') {
28
+ const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
29
+ reboot_type: DeviceRebootType.Bootloader,
30
+ });
31
+ return Promise.resolve(res.message);
32
+ }
25
33
 
34
+ const res = await this.device.commands.typedCall('RebootToBootloader', 'Success');
26
35
  return Promise.resolve(res.message);
27
36
  }
28
37
  }
@@ -1,7 +1,10 @@
1
+ import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
2
+
1
3
  import { UI_REQUEST } from '../../constants/ui-request';
2
4
  import { serializedPath, validatePath } from '../helpers/pathUtils';
3
5
  import { BaseMethod } from '../BaseMethod';
4
6
  import { validateParams, validateResult } from '../helpers/paramsValidator';
7
+ import { getFirmwareType } from '../../utils';
5
8
 
6
9
  import type { DnxGetAddress as HardwareDnxGetAddress } from '@onekeyfe/hd-transport';
7
10
  import type { DnxAddress, DnxGetAddressParams } from '../../types';
@@ -47,6 +50,10 @@ export default class DnxGetAddress extends BaseMethod<HardwareDnxGetAddress[]> {
47
50
  }
48
51
 
49
52
  async run() {
53
+ if (this.device.originalDescriptor?.protocolType === 'V2') {
54
+ throw createDeviceNotSupportMethodError(this.name, getFirmwareType(this.device.features));
55
+ }
56
+
50
57
  const responses: DnxAddress[] = [];
51
58
 
52
59
  for (let i = 0; i < this.params.length; i++) {
@@ -1,8 +1,11 @@
1
+ import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
2
+
1
3
  import { UI_REQUEST } from '../../constants/ui-request';
2
4
  import { serializedPath, validatePath } from '../helpers/pathUtils';
3
5
  import { BaseMethod } from '../BaseMethod';
4
6
  import { validateParams } from '../helpers/paramsValidator';
5
7
  import { stripHexPrefix } from '../helpers/hexUtils';
8
+ import { getFirmwareType } from '../../utils';
6
9
 
7
10
  import type { TypedResponseMessage } from '../../device/DeviceCommands';
8
11
  import type { DnxSignature } from '../../types';
@@ -115,6 +118,10 @@ export default class DnxSignTransaction extends BaseMethod<DnxSignTx> {
115
118
  }
116
119
 
117
120
  async run() {
121
+ if (this.device.originalDescriptor?.protocolType === 'V2') {
122
+ throw createDeviceNotSupportMethodError(this.name, getFirmwareType(this.device.features));
123
+ }
124
+
118
125
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
119
126
 
120
127
  const res = await this.device.commands.typedCall('DnxSignTx', 'DnxInputRequest', {
@@ -44,7 +44,7 @@ export default class EvmGetAddress extends BaseMethod<EthereumGetAddressOneKey[]
44
44
  }
45
45
 
46
46
  async getEvmAddress(param: EthereumGetAddressOneKey) {
47
- if (TransportManager.getMessageVersion() === 'v1') {
47
+ if (TransportManager.getProtocolV1MessageSchema() === 'protocolV1Legacy') {
48
48
  return getAddressLegacyV1({
49
49
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
50
50
  param,
@@ -57,7 +57,7 @@ export default class EVMGetPublicKey extends BaseMethod<EthereumGetPublicKeyOneK
57
57
  }
58
58
 
59
59
  getEvmPublicKey(param: EthereumGetPublicKey) {
60
- if (TransportManager.getMessageVersion() === 'v1') {
60
+ if (TransportManager.getProtocolV1MessageSchema() === 'protocolV1Legacy') {
61
61
  return getPublicKeyLegacyV1({
62
62
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
63
63
  param,
@@ -34,7 +34,7 @@ export default class EVMSignMessage extends BaseMethod<EthereumSignMessageOneKey
34
34
  }
35
35
 
36
36
  async run() {
37
- if (TransportManager.getMessageVersion() === 'v1') {
37
+ if (TransportManager.getProtocolV1MessageSchema() === 'protocolV1Legacy') {
38
38
  return signMessageLegacyV1({
39
39
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
40
40
  params: this.params,
@@ -120,7 +120,7 @@ export default class EVMSignTransaction extends BaseMethod {
120
120
 
121
121
  if (formattedTx == null) throw ERRORS.TypedError('Runtime', 'formattedTx is not set');
122
122
 
123
- if (TransportManager.getMessageVersion() === 'v1') {
123
+ if (TransportManager.getProtocolV1MessageSchema() === 'protocolV1Legacy') {
124
124
  return signTransactionLegacyV1({
125
125
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
126
126
  addressN,
@@ -260,8 +260,8 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
260
260
 
261
261
  let supportTrezor = false;
262
262
  let response: MessageResponse<MessageKey>;
263
- switch (TransportManager.getMessageVersion()) {
264
- case 'v1':
263
+ switch (TransportManager.getProtocolV1MessageSchema()) {
264
+ case 'protocolV1Legacy':
265
265
  supportTrezor = true;
266
266
  response = await signTypedDataLegacyV1({
267
267
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
@@ -272,7 +272,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
272
272
  });
273
273
  break;
274
274
 
275
- case 'latest':
275
+ case 'protocolV1Current':
276
276
  default:
277
277
  supportTrezor = false;
278
278
  response = await signTypedData({
@@ -308,8 +308,8 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
308
308
  }) {
309
309
  if (!domainHash) throw ERRORS.TypedError('Runtime', 'domainHash is required');
310
310
 
311
- switch (TransportManager.getMessageVersion()) {
312
- case 'v1':
311
+ switch (TransportManager.getProtocolV1MessageSchema()) {
312
+ case 'protocolV1Legacy':
313
313
  return signTypedHashLegacyV1({
314
314
  typedCall,
315
315
  addressN,
@@ -319,7 +319,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
319
319
  device: this.device,
320
320
  });
321
321
 
322
- case 'latest':
322
+ case 'protocolV1Current':
323
323
  default:
324
324
  return signTypedHash({
325
325
  typedCall,
@@ -31,7 +31,7 @@ export default class EVMSignMessage extends BaseMethod<EthereumVerifyMessageOneK
31
31
  }
32
32
 
33
33
  async run() {
34
- if (TransportManager.getMessageVersion() === 'v1') {
34
+ if (TransportManager.getProtocolV1MessageSchema() === 'protocolV1Legacy') {
35
35
  return verifyMessageLegacyV1({
36
36
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
37
37
  params: this.params,
@@ -28,6 +28,13 @@ const Log = getLogger(LoggerNames.Method);
28
28
  const SESSION_ERROR = 'session not found';
29
29
  const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
30
30
 
31
+ type FirmwareProgressMetadata = {
32
+ transferredBytes?: number;
33
+ totalBytes?: number;
34
+ rateBytesPerSecond?: number;
35
+ elapsedMs?: number;
36
+ };
37
+
31
38
  const isDeviceDisconnectedError = (error: unknown) => {
32
39
  const message = error instanceof Error ? error.message : String(error ?? '');
33
40
  return (
@@ -82,12 +89,17 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
82
89
  * @description Post the progress message
83
90
  * @param progress Post the percentage of the progress
84
91
  */
85
- postProgressMessage = (progress: number, progressType: IFirmwareUpdateProgressType) => {
92
+ postProgressMessage = (
93
+ progress: number,
94
+ progressType: IFirmwareUpdateProgressType,
95
+ metadata: FirmwareProgressMetadata = {}
96
+ ) => {
86
97
  this.postMessage(
87
98
  createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
88
99
  device: this.device.toMessageObject() as KnownDevice,
89
100
  progress,
90
101
  progressType,
102
+ ...metadata,
91
103
  })
92
104
  );
93
105
  };
@@ -325,10 +337,12 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
325
337
  filePath,
326
338
  processedSize,
327
339
  totalSize,
340
+ transferStartTime = Date.now(),
328
341
  }: PROTO.FirmwareUpload & {
329
342
  filePath: string;
330
343
  processedSize?: number;
331
344
  totalSize?: number;
345
+ transferStartTime?: number;
332
346
  }) {
333
347
  if (!filePath.startsWith('0:')) {
334
348
  throw new Error('filePath must start with 0:');
@@ -338,7 +352,6 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
338
352
  const chunkSize = 1024 * perPackageSize;
339
353
  const totalChunks = Math.ceil(payload.byteLength / chunkSize);
340
354
  let offset = 0;
341
- let currentFileProcessed = 0;
342
355
 
343
356
  for (let i = 0; i < totalChunks; i++) {
344
357
  const chunkStart = i * chunkSize;
@@ -350,7 +363,7 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
350
363
  // Calculate progress based on whether we're tracking overall progress or single file progress
351
364
  let progress: number;
352
365
  if (totalSize !== undefined && processedSize !== undefined) {
353
- currentFileProcessed = processedSize + chunkEnd;
366
+ const currentFileProcessed = processedSize + chunkEnd;
354
367
  progress = Math.min(Math.ceil((currentFileProcessed / totalSize) * 100), 99);
355
368
  } else {
356
369
  progress = Math.min(Math.ceil(((i + 1) / totalChunks) * 100), 99);
@@ -366,7 +379,17 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
366
379
  );
367
380
  // @ts-expect-error
368
381
  offset += writeRes.message.processed_byte;
369
- this.postProgressMessage(progress, 'transferData');
382
+ const elapsedMs = Date.now() - transferStartTime;
383
+ const transferredBytes =
384
+ totalSize !== undefined && processedSize !== undefined ? processedSize + offset : offset;
385
+ const totalBytes = totalSize ?? payload.byteLength;
386
+ this.postProgressMessage(progress, 'transferData', {
387
+ transferredBytes,
388
+ totalBytes,
389
+ rateBytesPerSecond:
390
+ elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
391
+ elapsedMs,
392
+ });
370
393
  }
371
394
 
372
395
  // Return processed size only if we're tracking overall progress
@@ -7,7 +7,7 @@ import {
7
7
  import { supportBatchPublicKey } from '../../utils/deviceFeaturesUtils';
8
8
  import { isEqualBip44CoinType } from './pathUtils';
9
9
  import { splitArray } from '../../utils/arrayUtils';
10
- import { getDeviceType, getFirmwareType } from '../../utils';
10
+ import { getDeviceType, getFirmwareType, shouldSkipMethodSupportCheck } from '../../utils';
11
11
  import { DeviceModelToTypes } from '../../types';
12
12
 
13
13
  import type { EcdsaPublicKeys, Path } from '@onekeyfe/hd-transport';
@@ -28,7 +28,9 @@ export async function batchGetPublickeys(
28
28
  throw TypedError(HardwareErrorCode.ForbiddenKeyPath, 'Path length must be greater than 3');
29
29
  }
30
30
 
31
- const supportsBatchPublicKey = supportBatchPublicKey(device.features, options);
31
+ const supportsBatchPublicKey =
32
+ shouldSkipMethodSupportCheck(device.features, device.originalDescriptor?.protocolType) ||
33
+ supportBatchPublicKey(device.features, options);
32
34
  if (!supportsBatchPublicKey) {
33
35
  throw createDeviceNotSupportMethodError('BatchGetPublickeys', getFirmwareType(device.features));
34
36
  }
package/src/api/index.ts CHANGED
@@ -37,8 +37,36 @@ export { default as getNextU2FCounter } from './u2f/GetNextU2FCounter';
37
37
  export { default as firmwareUpdate } from './FirmwareUpdate';
38
38
  export { default as firmwareUpdateV2 } from './FirmwareUpdateV2';
39
39
  export { default as firmwareUpdateV3 } from './FirmwareUpdateV3';
40
+ export { default as firmwareUpdateV4 } from './FirmwareUpdateV4';
40
41
  export { default as promptWebDeviceAccess } from './PromptWebDeviceAccess';
41
42
 
43
+ // File system & device control API (Protocol V2 only)
44
+ export { default as getProtoVersion } from './protocol-v2/GetProtoVersion';
45
+ export { default as ping } from './protocol-v2/Ping';
46
+ export { default as deviceReboot } from './protocol-v2/DeviceReboot';
47
+ export { default as deviceGetDeviceInfo } from './protocol-v2/DeviceGetDeviceInfo';
48
+ export { default as deviceGetOnboardingStatus } from './protocol-v2/DeviceGetOnboardingStatus';
49
+ export { default as deviceFirmwareUpdate } from './protocol-v2/DeviceFirmwareUpdate';
50
+ export { default as deviceGetFirmwareUpdateStatus } from './protocol-v2/DeviceGetFirmwareUpdateStatus';
51
+ export { default as factoryDeviceInfoSettings } from './protocol-v2/FactoryDeviceInfoSettings';
52
+ export { default as factoryGetDeviceInfo } from './protocol-v2/FactoryGetDeviceInfo';
53
+ export { default as filesystemFixPermission } from './protocol-v2/FilesystemFixPermission';
54
+ export { default as filesystemFormat } from './protocol-v2/FilesystemFormat';
55
+ export { default as fileRead } from './FileRead';
56
+ export { default as fileWrite } from './FileWrite';
57
+ export { default as fileDelete } from './FileDelete';
58
+ export { default as dirList } from './DirList';
59
+ export { default as dirMake } from './DirMake';
60
+ export { default as dirRemove } from './DirRemove';
61
+ export { default as pathInfo } from './PathInfo';
62
+ export { default as filesystemFileRead } from './FileRead';
63
+ export { default as filesystemFileWrite } from './FileWrite';
64
+ export { default as filesystemFileDelete } from './FileDelete';
65
+ export { default as filesystemDirList } from './DirList';
66
+ export { default as filesystemDirMake } from './DirMake';
67
+ export { default as filesystemDirRemove } from './DirRemove';
68
+ export { default as filesystemPathInfoQuery } from './PathInfo';
69
+
42
70
  export { default as cipherKeyValue } from './CipherKeyValue';
43
71
 
44
72
  export { default as allNetworkGetAddress } from './allnetwork/AllNetworkGetAddress';
@@ -0,0 +1,33 @@
1
+ import { BaseMethod } from '../BaseMethod';
2
+ import {
3
+ PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS,
4
+ PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
5
+ normalizeFirmwareTargets,
6
+ } from './helpers';
7
+
8
+ import type { DeviceFirmwareUpdateParams } from './helpers';
9
+
10
+ export default class DeviceFirmwareUpdate extends BaseMethod<DeviceFirmwareUpdateParams> {
11
+ init() {
12
+ this.skipForceUpdateCheck = true;
13
+ this.useDevicePassphraseState = false;
14
+ this.params = {
15
+ targets: this.payload.targets,
16
+ targetId: this.payload.targetId,
17
+ target_id: this.payload.target_id,
18
+ path: this.payload.path,
19
+ };
20
+ }
21
+
22
+ async run() {
23
+ const res = await this.device.commands.typedCall(
24
+ 'DeviceFirmwareUpdate',
25
+ PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
26
+ {
27
+ targets: normalizeFirmwareTargets(this.params),
28
+ },
29
+ PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS
30
+ );
31
+ return Promise.resolve(res.message);
32
+ }
33
+ }
@@ -0,0 +1,35 @@
1
+ import { BaseMethod } from '../BaseMethod';
2
+ import { buildTargets, buildTypes } from './helpers';
3
+
4
+ import type { DeviceGetDeviceInfoParams } from './helpers';
5
+
6
+ export default class DeviceGetDeviceInfo extends BaseMethod<DeviceGetDeviceInfoParams> {
7
+ init() {
8
+ this.skipForceUpdateCheck = true;
9
+ this.useDevicePassphraseState = false;
10
+ this.params = {
11
+ targets: this.payload.targets,
12
+ types: this.payload.types,
13
+ targetHw: this.payload.targetHw,
14
+ targetFw: this.payload.targetFw,
15
+ targetBt: this.payload.targetBt,
16
+ targetSe1: this.payload.targetSe1,
17
+ targetSe2: this.payload.targetSe2,
18
+ targetSe3: this.payload.targetSe3,
19
+ targetSe4: this.payload.targetSe4,
20
+ targetStatus: this.payload.targetStatus,
21
+ includeVersion: this.payload.includeVersion,
22
+ includeBuildId: this.payload.includeBuildId,
23
+ includeHash: this.payload.includeHash,
24
+ includeSpecific: this.payload.includeSpecific,
25
+ };
26
+ }
27
+
28
+ async run() {
29
+ const res = await this.device.commands.typedCall('DeviceGetDeviceInfo', 'DeviceInfo', {
30
+ targets: buildTargets(this.params),
31
+ types: buildTypes(this.params),
32
+ });
33
+ return Promise.resolve(res.message);
34
+ }
35
+ }