@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
@@ -1,3 +1,5 @@
1
+ import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
2
+
1
3
  export interface CommonParams {
2
4
  keepSession?: boolean;
3
5
  /**
@@ -47,6 +49,11 @@ export interface CommonParams {
47
49
  * Only connect device, not initialize device, only ble connect
48
50
  */
49
51
  onlyConnectBleDevice?: boolean;
52
+
53
+ /**
54
+ * Expected transport protocol. If omitted, SDK probes Protocol V1 then Protocol V2.
55
+ */
56
+ connectProtocol?: HardwareConnectProtocol;
50
57
  }
51
58
 
52
59
  export type Params<T> = CommonParams & T & { bundle?: undefined };
@@ -83,7 +83,7 @@ export type IBLEFirmwareReleaseInfo = {
83
83
  };
84
84
  };
85
85
 
86
- type IKnownDevice = Exclude<IDeviceType, 'unknown'>;
86
+ type IKnownDevice = Exclude<IDeviceType, 'unknown' | 'pro2'>;
87
87
 
88
88
  /**
89
89
  * Device firmware configuration map
@@ -5,7 +5,10 @@ import { Enum_Capability } from '@onekeyfe/hd-transport';
5
5
 
6
6
  import { toHardened } from '../api/helpers/pathUtils';
7
7
  import { DeviceModelToTypes, DeviceTypeToModels } from '../types';
8
- import DataManager, { type IFirmwareField, type MessageVersion } from '../data-manager/DataManager';
8
+ import DataManager, {
9
+ type IFirmwareField,
10
+ type ProtocolV1MessageSchema,
11
+ } from '../data-manager/DataManager';
9
12
  import { PROTOBUF_MESSAGE_CONFIG } from '../data-manager/MessagesConfig';
10
13
  import { getDeviceType } from './deviceInfoUtils';
11
14
  import { getDeviceFirmwareVersion } from './deviceVersionUtils';
@@ -15,13 +18,13 @@ import type { Device } from '../device/Device';
15
18
  import type { DeviceCommands } from '../device/DeviceCommands';
16
19
  import type { Features, SupportFeatureType } from '../types';
17
20
 
18
- export const getSupportMessageVersion = (
21
+ export const getSupportProtocolV1MessageSchema = (
19
22
  features: Features | undefined
20
- ): { messages: JSON; messageVersion: MessageVersion } => {
23
+ ): { messages: JSON; protocolV1MessageSchema: ProtocolV1MessageSchema } => {
21
24
  if (!features)
22
25
  return {
23
- messages: DataManager.messages.latest,
24
- messageVersion: 'latest',
26
+ messages: DataManager.messages.protocolV1Current,
27
+ protocolV1MessageSchema: 'protocolV1Current',
25
28
  };
26
29
 
27
30
  const currentDeviceVersion = getDeviceFirmwareVersion(features).join('.');
@@ -37,18 +40,18 @@ export const getSupportMessageVersion = (
37
40
  const sortedDeviceVersionConfigs =
38
41
  deviceVersionConfigs?.sort((a, b) => semver.compare(b.minVersion, a.minVersion)) ?? [];
39
42
 
40
- for (const { minVersion, messageVersion } of sortedDeviceVersionConfigs) {
43
+ for (const { minVersion, protocolV1MessageSchema } of sortedDeviceVersionConfigs) {
41
44
  if (semver.gte(currentDeviceVersion, minVersion)) {
42
45
  return {
43
- messages: DataManager.messages[messageVersion],
44
- messageVersion,
46
+ messages: DataManager.messages[protocolV1MessageSchema],
47
+ protocolV1MessageSchema,
45
48
  };
46
49
  }
47
50
  }
48
51
 
49
52
  return {
50
- messages: DataManager.messages.latest,
51
- messageVersion: 'latest',
53
+ messages: DataManager.messages.protocolV1Current,
54
+ protocolV1MessageSchema: 'protocolV1Current',
52
55
  };
53
56
  };
54
57
 
@@ -68,7 +71,11 @@ export const supportNewPassphrase = (features?: Features): SupportFeatureType =>
68
71
  if (!features) return { support: false };
69
72
 
70
73
  const deviceType = getDeviceType(features);
71
- if (deviceType === EDeviceType.Touch || deviceType === EDeviceType.Pro) {
74
+ if (
75
+ deviceType === EDeviceType.Touch ||
76
+ deviceType === EDeviceType.Pro ||
77
+ deviceType === EDeviceType.Pro2
78
+ ) {
72
79
  return { support: true };
73
80
  }
74
81
 
@@ -86,6 +93,8 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
86
93
  ) => {
87
94
  const { features, commands } = device;
88
95
  const locked = features?.unlocked === false;
96
+ const deviceType = getDeviceType(features);
97
+ const isPro2 = deviceType === EDeviceType.Pro2;
89
98
 
90
99
  const { passphraseState, newSession, unlockedAttachPin } = await getPassphraseState(
91
100
  features,
@@ -95,12 +104,12 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
95
104
  }
96
105
  );
97
106
 
98
- const isModeT =
99
- getDeviceType(features) === EDeviceType.Touch || getDeviceType(features) === EDeviceType.Pro;
107
+ const isModeT = deviceType === EDeviceType.Touch || deviceType === EDeviceType.Pro;
100
108
 
101
109
  // 如果可以获取到 passphraseState,但是设备 features 显示设备未开启 passphrase,需要刷新设备状态
102
110
  // if passphraseState can be obtained, but the device features show that the device has not enabled passphrase, the device status needs to be refreshed
103
- const needRefreshWithPassphrase = passphraseState && features?.passphrase_protection !== true;
111
+ const needRefreshWithPassphrase =
112
+ !isPro2 && passphraseState && features?.passphrase_protection !== true;
104
113
  // 如果 Touch/Pro 在之前是锁定状态,刷新设备状态
105
114
  // if Touch/Pro was locked before, refresh the device state
106
115
  const needRefreshWithLocked = isModeT && locked;
@@ -110,10 +119,17 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
110
119
  await device.getFeatures();
111
120
  }
112
121
 
122
+ if (isPro2 && device.features && (passphraseState || newSession)) {
123
+ device.features.passphrase_protection = true;
124
+ if (newSession) {
125
+ device.features.session_id = newSession;
126
+ }
127
+ }
128
+
113
129
  // Attach to pin try to fix internal state
114
130
  if (features?.device_id) {
115
131
  device.updateInternalState(
116
- device.features?.passphrase_protection ?? false,
132
+ (device.features?.passphrase_protection ?? false) || isPro2,
117
133
  passphraseState,
118
134
  device.features?.device_id ?? '',
119
135
  newSession,
@@ -148,6 +164,8 @@ export const getPassphraseState = async (
148
164
  );
149
165
  const supportGetPassphraseState =
150
166
  supportAttachPinCapability ||
167
+ // Pro2 V2 暂未从 features 暴露 capabilities,先直连该方法用于固件联调。
168
+ deviceType === EDeviceType.Pro2 ||
151
169
  (deviceType === EDeviceType.Pro && semver.gte(firmwareVersion.join('.'), '4.15.0'));
152
170
 
153
171
  if (supportGetPassphraseState) {
@@ -27,6 +27,9 @@ export const getDeviceType = (features?: Features): IDeviceType => {
27
27
  return EDeviceType.Touch;
28
28
  case 'PRO':
29
29
  return EDeviceType.Pro;
30
+ case 'PRO2':
31
+ case 'pro2':
32
+ return EDeviceType.Pro2;
30
33
  case 'PURE':
31
34
  return EDeviceType.ClassicPure;
32
35
  default:
@@ -68,13 +71,14 @@ export const getDeviceType = (features?: Features): IDeviceType => {
68
71
  export const getDeviceTypeByBleName = (name?: string): IDeviceType => {
69
72
  if (!name) return EDeviceType.Unknown;
70
73
 
71
- if (name.startsWith('BixinKey')) return EDeviceType.Classic;
72
- if (name.startsWith('K')) return EDeviceType.Classic;
74
+ if (/^BixinKey/i.test(name)) return EDeviceType.Classic;
75
+ if (/^K/i.test(name)) return EDeviceType.Classic;
73
76
 
74
- if (name.startsWith('T')) return EDeviceType.Touch;
75
- if (name.startsWith('Touch')) return EDeviceType.Touch;
77
+ if (/^T/i.test(name)) return EDeviceType.Touch;
78
+ if (/^Touch/i.test(name)) return EDeviceType.Touch;
76
79
 
77
- if (name.startsWith('Pro')) return EDeviceType.Pro;
80
+ if (/\bPro\s*2\b/i.test(name) || /^Pro2/i.test(name)) return EDeviceType.Pro2;
81
+ if (/\bPro\b/i.test(name) || /^Pro/i.test(name)) return EDeviceType.Pro;
78
82
 
79
83
  return EDeviceType.Unknown;
80
84
  };
@@ -152,6 +156,11 @@ export const getMethodVersionRange = (
152
156
  return versionRange;
153
157
  };
154
158
 
159
+ export const shouldSkipMethodSupportCheck = (
160
+ features: Features | undefined,
161
+ protocolType?: string
162
+ ): boolean => protocolType === 'V2' || getDeviceType(features) === EDeviceType.Pro2;
163
+
155
164
  export const getFirmwareType = (features: Features | undefined) => {
156
165
  if (!features) {
157
166
  return EFirmwareType.Universal;
@@ -11,6 +11,7 @@ export {
11
11
  getDeviceUUID,
12
12
  getDeviceLabel,
13
13
  getMethodVersionRange,
14
+ shouldSkipMethodSupportCheck,
14
15
  getFirmwareType,
15
16
  } from './deviceInfoUtils';
16
17
  export {
@@ -1,99 +0,0 @@
1
- import { HardwareErrorCode } from '@onekeyfe/hd-shared';
2
-
3
- import { DeviceCommands } from '../src/device/DeviceCommands';
4
-
5
- jest.mock('../src/data/config', () => ({
6
- getSDKVersion: jest.fn(() => '1.0.0'),
7
- DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
8
- }));
9
-
10
- const createCommands = () => {
11
- const commands = Object.create(DeviceCommands.prototype) as DeviceCommands;
12
- commands.device = {
13
- clearCancelableAction: jest.fn(),
14
- } as any;
15
- return commands;
16
- };
17
-
18
- describe('DeviceCommands failure mapping', () => {
19
- it.each([
20
- ['ButtonAck', 'Not in Ethereum signing mode'],
21
- ['PinMatrixAck', 'Not in Conflux signing mode'],
22
- ])('keeps %s unexpected message "%s" as firmware runtime error', async (callType, message) => {
23
- const commands = createCommands();
24
-
25
- await expect(
26
- commands._filterCommonTypes(
27
- {
28
- type: 'Failure',
29
- message: {
30
- code: 'Failure_UnexpectedMessage',
31
- message,
32
- },
33
- } as any,
34
- callType as any
35
- )
36
- ).rejects.toMatchObject({
37
- errorCode: HardwareErrorCode.RuntimeError,
38
- message: `Failure_UnexpectedMessage,${message}`,
39
- });
40
- });
41
-
42
- it('keeps the existing NotInSigningMode mapping', async () => {
43
- const commands = createCommands();
44
-
45
- await expect(
46
- commands._filterCommonTypes(
47
- {
48
- type: 'Failure',
49
- message: {
50
- code: 'Failure_UnexpectedMessage',
51
- message: 'Not in Signing mode',
52
- },
53
- } as any,
54
- 'ButtonAck'
55
- )
56
- ).rejects.toMatchObject({
57
- errorCode: HardwareErrorCode.NotInSigningMode,
58
- });
59
- });
60
-
61
- it('keeps the existing unexpected passphrase mapping', async () => {
62
- const commands = createCommands();
63
-
64
- await expect(
65
- commands._filterCommonTypes(
66
- {
67
- type: 'Failure',
68
- message: {
69
- code: 'Failure_UnexpectedMessage',
70
- message: 'Unexpected message',
71
- },
72
- } as any,
73
- 'PassphraseAck'
74
- )
75
- ).rejects.toMatchObject({
76
- errorCode: HardwareErrorCode.UnexpectPassphrase,
77
- });
78
- });
79
-
80
- it('keeps non signing unexpected messages as runtime errors', async () => {
81
- const commands = createCommands();
82
-
83
- await expect(
84
- commands._filterCommonTypes(
85
- {
86
- type: 'Failure',
87
- message: {
88
- code: 'Failure_UnexpectedMessage',
89
- message: 'Not in Reset mode',
90
- },
91
- } as any,
92
- 'ButtonAck'
93
- )
94
- ).rejects.toMatchObject({
95
- errorCode: HardwareErrorCode.RuntimeError,
96
- message: 'Failure_UnexpectedMessage,Not in Reset mode',
97
- });
98
- });
99
- });
@@ -1,261 +0,0 @@
1
- import AllNetworkGetAddressBase from '../src/api/allnetwork/AllNetworkGetAddressBase';
2
- import EvmGetAddress from '../src/api/evm/EVMGetAddress';
3
- import EVMGetPublicKey from '../src/api/evm/EVMGetPublicKey';
4
- import { findMethod } from '../src/api/utils';
5
-
6
- jest.mock('../src/data/config', () => ({
7
- getSDKVersion: jest.fn(() => '1.0.0'),
8
- DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
9
- }));
10
-
11
- jest.mock('../src/api/utils', () => ({
12
- findMethod: jest.fn(),
13
- }));
14
-
15
- const createDevice = (onekeyDeviceType: string) => {
16
- const typedCall = jest.fn();
17
- return {
18
- typedCall,
19
- device: {
20
- features: {
21
- onekey_device_type: onekeyDeviceType,
22
- safety_checks: 'Strict',
23
- },
24
- commands: {
25
- typedCall,
26
- },
27
- },
28
- };
29
- };
30
-
31
- class TestAllNetworkMethod extends AllNetworkGetAddressBase {
32
- async getAllNetworkAddress() {
33
- return Promise.resolve([]);
34
- }
35
- }
36
-
37
- describe('EVM Ledger legacy path safety checks', () => {
38
- it.each([
39
- ['evmGetAddress', EvmGetAddress],
40
- ['evmGetPublicKey', EVMGetPublicKey],
41
- ])(
42
- 'temporarily relaxes safety checks for Pro %s on ledger legacy path index greater than 1',
43
- async (methodName, Method) => {
44
- const { device, typedCall } = createDevice('PRO');
45
- const method = new Method({
46
- id: 1,
47
- payload: {
48
- method: methodName,
49
- path: "m/44'/60'/0'/2",
50
- },
51
- });
52
- method.device = device as any;
53
-
54
- await method.checkSafetyLevelOnTestNet();
55
-
56
- expect(typedCall).toHaveBeenCalledWith('ApplySettings', 'Success', {
57
- safety_checks: 'PromptTemporarily',
58
- });
59
- }
60
- );
61
-
62
- it('temporarily relaxes safety checks for Touch get public key on ledger legacy path index greater than 1', async () => {
63
- const { device, typedCall } = createDevice('TOUCH');
64
- const method = new EVMGetPublicKey({
65
- id: 1,
66
- payload: {
67
- method: 'evmGetPublicKey',
68
- path: "m/44'/60'/0'/2",
69
- },
70
- });
71
- method.device = device as any;
72
-
73
- await method.checkSafetyLevelOnTestNet();
74
-
75
- expect(typedCall).toHaveBeenCalledWith('ApplySettings', 'Success', {
76
- safety_checks: 'PromptTemporarily',
77
- });
78
- });
79
-
80
- it('runs EVM safety checks when allNetwork dispatches to the inner get address method', async () => {
81
- const { device, typedCall } = createDevice('PRO');
82
- (findMethod as jest.Mock).mockImplementation(message => new EvmGetAddress(message));
83
- const runSpy = jest.spyOn(EvmGetAddress.prototype, 'run').mockResolvedValue([
84
- {
85
- path: "m/44'/60'/0'/2",
86
- address: '0x0000000000000000000000000000000000000000',
87
- },
88
- ]);
89
- const method = new TestAllNetworkMethod({
90
- id: 1,
91
- payload: {
92
- method: 'allNetworkGetAddress',
93
- connectId: 'connect-id',
94
- deviceId: 'device-id',
95
- bundle: [],
96
- },
97
- });
98
- method.device = {
99
- ...device,
100
- on: jest.fn(),
101
- off: jest.fn(),
102
- } as any;
103
-
104
- await method.callMethod(
105
- 'evmGetAddress',
106
- {
107
- bundle: [
108
- {
109
- path: "m/44'/60'/0'/2",
110
- showOnOneKey: false,
111
- chainId: 1,
112
- _originRequestParams: {
113
- network: 'evm',
114
- path: "m/44'/60'/0'/2",
115
- showOnOneKey: false,
116
- chainName: '1',
117
- },
118
- },
119
- ],
120
- },
121
- 0
122
- );
123
-
124
- expect(typedCall).toHaveBeenCalledWith('ApplySettings', 'Success', {
125
- safety_checks: 'PromptTemporarily',
126
- });
127
-
128
- runSpy.mockRestore();
129
- });
130
-
131
- it('only applies temporary safety checks once during one allNetwork request even when features stay strict', async () => {
132
- const { device, typedCall } = createDevice('PRO');
133
- (findMethod as jest.Mock).mockImplementation(message => new EvmGetAddress(message));
134
- const runSpy = jest
135
- .spyOn(EvmGetAddress.prototype, 'run')
136
- .mockResolvedValueOnce([
137
- {
138
- path: "m/44'/60'/0'/2",
139
- address: '0x0000000000000000000000000000000000000002',
140
- },
141
- ])
142
- .mockResolvedValueOnce([
143
- {
144
- path: "m/44'/60'/0'/3",
145
- address: '0x0000000000000000000000000000000000000003',
146
- },
147
- ]);
148
- const method = new TestAllNetworkMethod({
149
- id: 1,
150
- payload: {
151
- method: 'allNetworkGetAddressByLoop',
152
- connectId: 'connect-id',
153
- deviceId: 'device-id',
154
- bundle: [],
155
- },
156
- });
157
- method.device = {
158
- ...device,
159
- on: jest.fn(),
160
- off: jest.fn(),
161
- } as any;
162
-
163
- await method.callMethod(
164
- 'evmGetAddress',
165
- {
166
- bundle: [
167
- {
168
- path: "m/44'/60'/0'/2",
169
- showOnOneKey: false,
170
- chainId: 1,
171
- _originRequestParams: {
172
- network: 'evm',
173
- path: "m/44'/60'/0'/2",
174
- showOnOneKey: false,
175
- chainName: '1',
176
- },
177
- },
178
- ],
179
- },
180
- 0
181
- );
182
-
183
- await method.callMethod(
184
- 'evmGetAddress',
185
- {
186
- bundle: [
187
- {
188
- path: "m/44'/60'/0'/3",
189
- showOnOneKey: false,
190
- chainId: 1,
191
- _originRequestParams: {
192
- network: 'evm',
193
- path: "m/44'/60'/0'/3",
194
- showOnOneKey: false,
195
- chainName: '1',
196
- },
197
- },
198
- ],
199
- },
200
- 0
201
- );
202
-
203
- expect(typedCall).toHaveBeenCalledTimes(1);
204
- expect(typedCall).toHaveBeenCalledWith('ApplySettings', 'Success', {
205
- safety_checks: 'PromptTemporarily',
206
- });
207
-
208
- runSpy.mockRestore();
209
- });
210
-
211
- it.each(["m/44'/60'/0'/0", "m/44'/60'/0'/1"])(
212
- 'keeps safety checks unchanged for legal ledger legacy path %s',
213
- async path => {
214
- const { device, typedCall } = createDevice('PRO');
215
- const method = new EvmGetAddress({
216
- id: 1,
217
- payload: {
218
- method: 'evmGetAddress',
219
- path,
220
- },
221
- });
222
- method.device = device as any;
223
-
224
- await method.checkSafetyLevelOnTestNet();
225
-
226
- expect(typedCall).not.toHaveBeenCalled();
227
- }
228
- );
229
-
230
- it('keeps safety checks unchanged for standard 5-segment BIP44 paths', async () => {
231
- const { device, typedCall } = createDevice('PRO');
232
- const method = new EvmGetAddress({
233
- id: 1,
234
- payload: {
235
- method: 'evmGetAddress',
236
- path: "m/44'/60'/0'/0/2",
237
- },
238
- });
239
- method.device = device as any;
240
-
241
- await method.checkSafetyLevelOnTestNet();
242
-
243
- expect(typedCall).not.toHaveBeenCalled();
244
- });
245
-
246
- it('keeps safety checks unchanged on non Pro/Touch devices', async () => {
247
- const { device, typedCall } = createDevice('MINI');
248
- const method = new EvmGetAddress({
249
- id: 1,
250
- payload: {
251
- method: 'evmGetAddress',
252
- path: "m/44'/60'/0'/2",
253
- },
254
- });
255
- method.device = device as any;
256
-
257
- await method.checkSafetyLevelOnTestNet();
258
-
259
- expect(typedCall).not.toHaveBeenCalled();
260
- });
261
- });