@onekeyfe/hd-core 1.1.26-alpha.9 → 1.1.27-alpha.30

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 (158) hide show
  1. package/__tests__/protocol-v2.test.ts +940 -0
  2. package/dist/api/BaseMethod.d.ts.map +1 -1
  3. package/dist/api/DirList.d.ts +10 -0
  4. package/dist/api/DirList.d.ts.map +1 -0
  5. package/dist/api/DirMake.d.ts +9 -0
  6. package/dist/api/DirMake.d.ts.map +1 -0
  7. package/dist/api/DirRemove.d.ts +9 -0
  8. package/dist/api/DirRemove.d.ts.map +1 -0
  9. package/dist/api/FileDelete.d.ts +9 -0
  10. package/dist/api/FileDelete.d.ts.map +1 -0
  11. package/dist/api/FileRead.d.ts +19 -0
  12. package/dist/api/FileRead.d.ts.map +1 -0
  13. package/dist/api/FileWrite.d.ts +23 -0
  14. package/dist/api/FileWrite.d.ts.map +1 -0
  15. package/dist/api/FirmwareUpdateV3.d.ts +1 -0
  16. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  17. package/dist/api/FirmwareUpdateV4.d.ts +32 -0
  18. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
  19. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  20. package/dist/api/PathInfo.d.ts +9 -0
  21. package/dist/api/PathInfo.d.ts.map +1 -0
  22. package/dist/api/SearchDevices.d.ts +2 -1
  23. package/dist/api/SearchDevices.d.ts.map +1 -1
  24. package/dist/api/alephium/AlephiumSignTransaction.d.ts +1 -1
  25. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  26. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  27. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
  28. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  29. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  30. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
  31. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  32. package/dist/api/index.d.ts +26 -0
  33. package/dist/api/index.d.ts.map +1 -1
  34. package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts +7 -0
  35. package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts.map +1 -0
  36. package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts +7 -0
  37. package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts.map +1 -0
  38. package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts +6 -0
  39. package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts.map +1 -0
  40. package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts +6 -0
  41. package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts.map +1 -0
  42. package/dist/api/protocol-v2/DevReboot.d.ts +7 -0
  43. package/dist/api/protocol-v2/DevReboot.d.ts.map +1 -0
  44. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
  45. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
  46. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
  47. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
  48. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
  49. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
  50. package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
  51. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
  52. package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
  53. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
  54. package/dist/api/protocol-v2/Ping.d.ts +8 -0
  55. package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
  56. package/dist/api/protocol-v2/helpers.d.ts +49 -0
  57. package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
  58. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  59. package/dist/core/index.d.ts.map +1 -1
  60. package/dist/data-manager/DataManager.d.ts +4 -2
  61. package/dist/data-manager/DataManager.d.ts.map +1 -1
  62. package/dist/data-manager/TransportManager.d.ts +2 -1
  63. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  64. package/dist/device/Device.d.ts +5 -3
  65. package/dist/device/Device.d.ts.map +1 -1
  66. package/dist/device/DeviceCommands.d.ts +8 -8
  67. package/dist/device/DeviceCommands.d.ts.map +1 -1
  68. package/dist/device/DeviceConnector.d.ts +2 -1
  69. package/dist/device/DeviceConnector.d.ts.map +1 -1
  70. package/dist/events/ui-request.d.ts +8 -0
  71. package/dist/events/ui-request.d.ts.map +1 -1
  72. package/dist/index.d.ts +188 -20
  73. package/dist/index.js +15627 -699
  74. package/dist/inject.d.ts.map +1 -1
  75. package/dist/protocols/protocol-v2/features.d.ts +56 -0
  76. package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
  77. package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
  78. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
  79. package/dist/protocols/protocol-v2/index.d.ts +3 -0
  80. package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
  81. package/dist/types/api/export.d.ts +1 -1
  82. package/dist/types/api/export.d.ts.map +1 -1
  83. package/dist/types/api/firmwareUpdate.d.ts +7 -0
  84. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  85. package/dist/types/api/index.d.ts +28 -1
  86. package/dist/types/api/index.d.ts.map +1 -1
  87. package/dist/types/api/protocolV2.d.ts +123 -0
  88. package/dist/types/api/protocolV2.d.ts.map +1 -0
  89. package/dist/types/api/searchDevices.d.ts +2 -2
  90. package/dist/types/api/searchDevices.d.ts.map +1 -1
  91. package/dist/types/device.d.ts +1 -1
  92. package/dist/types/device.d.ts.map +1 -1
  93. package/dist/types/params.d.ts +2 -0
  94. package/dist/types/params.d.ts.map +1 -1
  95. package/dist/types/settings.d.ts +1 -1
  96. package/dist/types/settings.d.ts.map +1 -1
  97. package/dist/utils/deviceInfoUtils.d.ts +1 -0
  98. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  99. package/dist/utils/index.d.ts +1 -1
  100. package/dist/utils/index.d.ts.map +1 -1
  101. package/dist/utils/patch.d.ts +1 -1
  102. package/dist/utils/patch.d.ts.map +1 -1
  103. package/dist/utils/versionUtils.d.ts +1 -1
  104. package/package.json +5 -5
  105. package/src/api/BaseMethod.ts +10 -0
  106. package/src/api/DirList.ts +25 -0
  107. package/src/api/DirMake.ts +20 -0
  108. package/src/api/DirRemove.ts +20 -0
  109. package/src/api/FileDelete.ts +20 -0
  110. package/src/api/FileRead.ts +158 -0
  111. package/src/api/FileWrite.ts +191 -0
  112. package/src/api/FirmwareUpdateV3.ts +21 -4
  113. package/src/api/FirmwareUpdateV4.ts +810 -0
  114. package/src/api/GetOnekeyFeatures.ts +75 -3
  115. package/src/api/PathInfo.ts +24 -0
  116. package/src/api/SearchDevices.ts +7 -2
  117. package/src/api/alephium/AlephiumSignTransaction.ts +6 -5
  118. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +10 -1
  119. package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
  120. package/src/api/device/DeviceRebootToBootloader.ts +10 -1
  121. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
  122. package/src/api/index.ts +28 -0
  123. package/src/api/protocol-v2/DevFirmwareUpdate.ts +33 -0
  124. package/src/api/protocol-v2/DevGetDeviceInfo.ts +35 -0
  125. package/src/api/protocol-v2/DevGetFirmwareUpdateStatus.ts +18 -0
  126. package/src/api/protocol-v2/DevGetOnboardingStatus.ts +18 -0
  127. package/src/api/protocol-v2/DevReboot.ts +22 -0
  128. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
  129. package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
  130. package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
  131. package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
  132. package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
  133. package/src/api/protocol-v2/Ping.ts +16 -0
  134. package/src/api/protocol-v2/helpers.ts +138 -0
  135. package/src/api/ton/TonSignData.ts +4 -1
  136. package/src/core/index.ts +26 -4
  137. package/src/data/messages/messages-pro2.json +13102 -0
  138. package/src/data-manager/DataManager.ts +6 -2
  139. package/src/data-manager/TransportManager.ts +29 -3
  140. package/src/device/Device.ts +68 -8
  141. package/src/device/DeviceCommands.ts +162 -26
  142. package/src/device/DeviceConnector.ts +29 -4
  143. package/src/device/DevicePool.ts +1 -1
  144. package/src/events/ui-request.ts +8 -0
  145. package/src/inject.ts +42 -1
  146. package/src/protocols/protocol-v2/features.ts +266 -0
  147. package/src/protocols/protocol-v2/firmware.ts +26 -0
  148. package/src/protocols/protocol-v2/index.ts +2 -0
  149. package/src/types/api/export.ts +1 -0
  150. package/src/types/api/firmwareUpdate.ts +12 -0
  151. package/src/types/api/index.ts +63 -1
  152. package/src/types/api/protocolV2.ts +221 -0
  153. package/src/types/api/searchDevices.ts +2 -2
  154. package/src/types/device.ts +3 -1
  155. package/src/types/params.ts +7 -0
  156. package/src/types/settings.ts +1 -1
  157. package/src/utils/deviceInfoUtils.ts +14 -5
  158. package/src/utils/index.ts +1 -0
@@ -0,0 +1,138 @@
1
+ import { DevRebootType } from '@onekeyfe/hd-transport';
2
+
3
+ import type {
4
+ DevFirmwareTarget,
5
+ DevFirmwareTargetType,
6
+ DevInfoTargets,
7
+ DevInfoTypes,
8
+ TransportCallOptions,
9
+ } from '@onekeyfe/hd-transport';
10
+
11
+ export type RebootTypeInput = DevRebootType | keyof typeof DevRebootType | string | number;
12
+
13
+ export type DevRebootParams = {
14
+ rebootType?: RebootTypeInput;
15
+ reboot_type?: RebootTypeInput;
16
+ };
17
+
18
+ export type DevGetDeviceInfoParams = {
19
+ targets?: DevInfoTargets;
20
+ types?: DevInfoTypes;
21
+ targetHw?: boolean;
22
+ targetFw?: boolean;
23
+ targetBt?: boolean;
24
+ targetSe1?: boolean;
25
+ targetSe2?: boolean;
26
+ targetSe3?: boolean;
27
+ targetSe4?: boolean;
28
+ targetStatus?: boolean;
29
+ includeVersion?: boolean;
30
+ includeBuildId?: boolean;
31
+ includeHash?: boolean;
32
+ includeSpecific?: boolean;
33
+ };
34
+
35
+ export type DevFirmwareTargetInput =
36
+ | DevFirmwareTarget
37
+ | {
38
+ targetId?: DevFirmwareTargetType | string | number;
39
+ target_id?: DevFirmwareTargetType | string | number;
40
+ path: string;
41
+ };
42
+
43
+ export type DevFirmwareUpdateParams = {
44
+ targets?: DevFirmwareTargetInput[];
45
+ targetId?: DevFirmwareTargetType | string | number;
46
+ target_id?: DevFirmwareTargetType | string | number;
47
+ path?: string;
48
+ };
49
+
50
+ export type FactoryDeviceInfoSettingsParams = {
51
+ serial_no?: string;
52
+ serialNo?: string;
53
+ cpu_info?: string;
54
+ cpuInfo?: string;
55
+ pre_firmware?: string;
56
+ preFirmware?: string;
57
+ };
58
+
59
+ const DEV_REBOOT_TYPES: Record<string, DevRebootType> = {
60
+ Normal: DevRebootType.Normal,
61
+ normal: DevRebootType.Normal,
62
+ Boardloader: DevRebootType.Boardloader,
63
+ boardloader: DevRebootType.Boardloader,
64
+ Bootloader: DevRebootType.Bootloader,
65
+ bootloader: DevRebootType.Bootloader,
66
+ };
67
+
68
+ export const PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS: TransportCallOptions = {
69
+ intermediateTypes: ['DevFirmwareInstallProgress'],
70
+ };
71
+
72
+ export const PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES: ('Success' | 'DevFirmwareUpdateStatus')[] =
73
+ ['Success', 'DevFirmwareUpdateStatus'];
74
+
75
+ export function normalizeRebootType(value: RebootTypeInput | undefined): DevRebootType {
76
+ if (typeof value === 'number') return value;
77
+ if (typeof value === 'string') {
78
+ const numeric = Number(value);
79
+ if (Number.isFinite(numeric)) return numeric;
80
+ if (value in DEV_REBOOT_TYPES) return DEV_REBOOT_TYPES[value];
81
+ }
82
+ return DevRebootType.Normal;
83
+ }
84
+
85
+ function normalizeTargetId(
86
+ value: DevFirmwareTargetType | string | number | undefined
87
+ ): DevFirmwareTargetType {
88
+ if (typeof value === 'number') return value;
89
+ const numeric = Number(value);
90
+ if (Number.isFinite(numeric)) return numeric;
91
+ return 0;
92
+ }
93
+
94
+ export function normalizeFirmwareTargets(params: DevFirmwareUpdateParams): DevFirmwareTarget[] {
95
+ const targets =
96
+ params.targets ??
97
+ (params.path
98
+ ? [
99
+ {
100
+ target_id: params.target_id ?? params.targetId ?? 0,
101
+ path: params.path,
102
+ },
103
+ ]
104
+ : []);
105
+
106
+ return targets.map(target => ({
107
+ target_id: normalizeTargetId('target_id' in target ? target.target_id : target.targetId),
108
+ path: target.path,
109
+ }));
110
+ }
111
+
112
+ export function buildTargets(params: DevGetDeviceInfoParams): DevInfoTargets | undefined {
113
+ if (params.targets) return params.targets;
114
+
115
+ const targets: DevInfoTargets = {
116
+ hw: params.targetHw,
117
+ fw: params.targetFw,
118
+ bt: params.targetBt,
119
+ se1: params.targetSe1,
120
+ se2: params.targetSe2,
121
+ se3: params.targetSe3,
122
+ se4: params.targetSe4,
123
+ status: params.targetStatus,
124
+ };
125
+ return Object.values(targets).some(value => value !== undefined) ? targets : undefined;
126
+ }
127
+
128
+ export function buildTypes(params: DevGetDeviceInfoParams): DevInfoTypes | undefined {
129
+ if (params.types) return params.types;
130
+
131
+ const types: DevInfoTypes = {
132
+ version: params.includeVersion,
133
+ build_id: params.includeBuildId,
134
+ hash: params.includeHash,
135
+ specific: params.includeSpecific,
136
+ };
137
+ return Object.values(types).some(value => value !== undefined) ? types : undefined;
138
+ }
@@ -9,7 +9,10 @@ import type { TonSignDataParams } from '../../types/api/tonSignData';
9
9
 
10
10
  export default class TonSignData extends BaseMethod<HardwareTonSignData> {
11
11
  init() {
12
- this.strictCheckDeviceSupport = true;
12
+ // Keep strict-check off until the firmware release that ships TonSignData
13
+ // is decided — we don't yet know the min versions for touch/classic1s.
14
+ // Flip back to true and add getVersionRange() once those numbers land.
15
+ this.strictCheckDeviceSupport = false;
13
16
  this.checkDeviceId = true;
14
17
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
15
18
 
package/src/core/index.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  getLogger,
24
24
  getMethodVersionRange,
25
25
  setLoggerPostMessage,
26
+ shouldSkipMethodSupportCheck,
26
27
  wait,
27
28
  } from '../utils';
28
29
  import {
@@ -95,6 +96,7 @@ const parseInitOptions = (method?: BaseMethod): InitOptions => ({
95
96
  passphraseState: method?.payload.passphraseState,
96
97
  deviceId: method?.payload.deviceId,
97
98
  deriveCardano: method && hasDeriveCardano(method),
99
+ connectProtocol: method?.payload.connectProtocol,
98
100
  });
99
101
 
100
102
  let _core: Core;
@@ -342,6 +344,10 @@ const onCallDevice = async (
342
344
  device.features,
343
345
  type => method.getVersionRange()[type]
344
346
  );
347
+ const skipMethodSupportCheck = shouldSkipMethodSupportCheck(
348
+ device.features,
349
+ device.originalDescriptor?.protocolType
350
+ );
345
351
 
346
352
  if (device.features) {
347
353
  await DataManager.checkAndReloadData();
@@ -392,7 +398,7 @@ const onCallDevice = async (
392
398
  );
393
399
  }
394
400
 
395
- if (versionRange) {
401
+ if (!skipMethodSupportCheck && versionRange) {
396
402
  if (
397
403
  semver.valid(versionRange.min) &&
398
404
  semver.lt(currentFirmwareVersion, versionRange.min)
@@ -424,7 +430,7 @@ const onCallDevice = async (
424
430
  createDeprecatedHardwareError(currentFirmwareVersion, versionRange.max, method.name)
425
431
  );
426
432
  }
427
- } else if (method.strictCheckDeviceSupport) {
433
+ } else if (!skipMethodSupportCheck && method.strictCheckDeviceSupport) {
428
434
  throw createDeviceNotSupportMethodError(method.name, getFirmwareType(device.features));
429
435
  }
430
436
  }
@@ -648,6 +654,7 @@ function initDevice(method: BaseMethod) {
648
654
  } else if (allDevices.length > 1) {
649
655
  throw ERRORS.TypedError(
650
656
  [
657
+ 'firmwareUpdateV4',
651
658
  'firmwareUpdateV3',
652
659
  'firmwareUpdateV2',
653
660
  'checkFirmwareRelease',
@@ -702,15 +709,30 @@ function initDeviceForBle(method: BaseMethod) {
702
709
  */
703
710
  let bleTimeoutRetry = 0;
704
711
 
712
+ function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown) {
713
+ const message = error instanceof Error ? error.message : String(error ?? '');
714
+ return (
715
+ method.payload.connectProtocol === 'V2' &&
716
+ message.includes('Device protocol mismatch') &&
717
+ message.includes('expected V2') &&
718
+ message.includes('did not respond to expected protocol')
719
+ );
720
+ }
721
+
705
722
  async function connectDeviceForBle(method: BaseMethod, device: Device) {
706
723
  try {
707
- await device.acquire();
724
+ await device.acquire(method.payload.connectProtocol);
708
725
  if (method.payload?.onlyConnectBleDevice) {
709
726
  return;
710
727
  }
711
728
  await device.initialize(parseInitOptions(method));
712
729
  } catch (err) {
713
- if (err.errorCode === HardwareErrorCode.BleTimeoutError && bleTimeoutRetry <= 5) {
730
+ if (
731
+ (err.errorCode === HardwareErrorCode.BleTimeoutError ||
732
+ err.errorCode === HardwareErrorCode.BleConnectedError ||
733
+ isRetryableBleProtocolV2ProbeError(method, err)) &&
734
+ bleTimeoutRetry <= 5
735
+ ) {
714
736
  bleTimeoutRetry += 1;
715
737
  Log.debug(`Bletooth connect timeout and will retry, retry count: ${bleTimeoutRetry}`);
716
738
  await wait(3000);