@onekeyfe/hd-core 1.1.26 → 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 (156) hide show
  1. package/__tests__/protocol-v2.test.ts +940 -0
  2. package/dist/api/BaseMethod.d.ts +1 -3
  3. package/dist/api/BaseMethod.d.ts.map +1 -1
  4. package/dist/api/DirList.d.ts +10 -0
  5. package/dist/api/DirList.d.ts.map +1 -0
  6. package/dist/api/DirMake.d.ts +9 -0
  7. package/dist/api/DirMake.d.ts.map +1 -0
  8. package/dist/api/DirRemove.d.ts +9 -0
  9. package/dist/api/DirRemove.d.ts.map +1 -0
  10. package/dist/api/FileDelete.d.ts +9 -0
  11. package/dist/api/FileDelete.d.ts.map +1 -0
  12. package/dist/api/FileRead.d.ts +19 -0
  13. package/dist/api/FileRead.d.ts.map +1 -0
  14. package/dist/api/FileWrite.d.ts +23 -0
  15. package/dist/api/FileWrite.d.ts.map +1 -0
  16. package/dist/api/FirmwareUpdateV3.d.ts +1 -0
  17. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  18. package/dist/api/FirmwareUpdateV4.d.ts +32 -0
  19. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
  20. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  21. package/dist/api/PathInfo.d.ts +9 -0
  22. package/dist/api/PathInfo.d.ts.map +1 -0
  23. package/dist/api/SearchDevices.d.ts +2 -1
  24. package/dist/api/SearchDevices.d.ts.map +1 -1
  25. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  26. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
  27. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  28. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  29. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
  30. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  31. package/dist/api/index.d.ts +26 -0
  32. package/dist/api/index.d.ts.map +1 -1
  33. package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts +7 -0
  34. package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts.map +1 -0
  35. package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts +7 -0
  36. package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts.map +1 -0
  37. package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts +6 -0
  38. package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts.map +1 -0
  39. package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts +6 -0
  40. package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts.map +1 -0
  41. package/dist/api/protocol-v2/DevReboot.d.ts +7 -0
  42. package/dist/api/protocol-v2/DevReboot.d.ts.map +1 -0
  43. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
  44. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
  45. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
  46. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
  47. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
  48. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
  49. package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
  50. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
  51. package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
  52. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
  53. package/dist/api/protocol-v2/Ping.d.ts +8 -0
  54. package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
  55. package/dist/api/protocol-v2/helpers.d.ts +49 -0
  56. package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
  57. package/dist/core/index.d.ts.map +1 -1
  58. package/dist/data-manager/DataManager.d.ts +4 -2
  59. package/dist/data-manager/DataManager.d.ts.map +1 -1
  60. package/dist/data-manager/TransportManager.d.ts +2 -1
  61. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  62. package/dist/device/Device.d.ts +5 -3
  63. package/dist/device/Device.d.ts.map +1 -1
  64. package/dist/device/DeviceCommands.d.ts +8 -8
  65. package/dist/device/DeviceCommands.d.ts.map +1 -1
  66. package/dist/device/DeviceConnector.d.ts +2 -1
  67. package/dist/device/DeviceConnector.d.ts.map +1 -1
  68. package/dist/events/ui-request.d.ts +8 -0
  69. package/dist/events/ui-request.d.ts.map +1 -1
  70. package/dist/index.d.ts +188 -20
  71. package/dist/index.js +15626 -753
  72. package/dist/inject.d.ts.map +1 -1
  73. package/dist/protocols/protocol-v2/features.d.ts +56 -0
  74. package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
  75. package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
  76. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
  77. package/dist/protocols/protocol-v2/index.d.ts +3 -0
  78. package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
  79. package/dist/types/api/export.d.ts +1 -1
  80. package/dist/types/api/export.d.ts.map +1 -1
  81. package/dist/types/api/firmwareUpdate.d.ts +7 -0
  82. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  83. package/dist/types/api/index.d.ts +28 -1
  84. package/dist/types/api/index.d.ts.map +1 -1
  85. package/dist/types/api/protocolV2.d.ts +123 -0
  86. package/dist/types/api/protocolV2.d.ts.map +1 -0
  87. package/dist/types/api/searchDevices.d.ts +2 -2
  88. package/dist/types/api/searchDevices.d.ts.map +1 -1
  89. package/dist/types/device.d.ts +1 -1
  90. package/dist/types/device.d.ts.map +1 -1
  91. package/dist/types/params.d.ts +2 -0
  92. package/dist/types/params.d.ts.map +1 -1
  93. package/dist/types/settings.d.ts +1 -1
  94. package/dist/types/settings.d.ts.map +1 -1
  95. package/dist/utils/deviceInfoUtils.d.ts +1 -0
  96. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  97. package/dist/utils/index.d.ts +1 -1
  98. package/dist/utils/index.d.ts.map +1 -1
  99. package/dist/utils/patch.d.ts +1 -1
  100. package/dist/utils/patch.d.ts.map +1 -1
  101. package/dist/utils/versionUtils.d.ts +1 -1
  102. package/package.json +4 -4
  103. package/src/api/BaseMethod.ts +12 -60
  104. package/src/api/DirList.ts +25 -0
  105. package/src/api/DirMake.ts +20 -0
  106. package/src/api/DirRemove.ts +20 -0
  107. package/src/api/FileDelete.ts +20 -0
  108. package/src/api/FileRead.ts +158 -0
  109. package/src/api/FileWrite.ts +191 -0
  110. package/src/api/FirmwareUpdateV3.ts +21 -4
  111. package/src/api/FirmwareUpdateV4.ts +810 -0
  112. package/src/api/GetOnekeyFeatures.ts +75 -3
  113. package/src/api/PathInfo.ts +24 -0
  114. package/src/api/SearchDevices.ts +7 -2
  115. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +10 -9
  116. package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
  117. package/src/api/device/DeviceRebootToBootloader.ts +10 -1
  118. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
  119. package/src/api/index.ts +28 -0
  120. package/src/api/protocol-v2/DevFirmwareUpdate.ts +33 -0
  121. package/src/api/protocol-v2/DevGetDeviceInfo.ts +35 -0
  122. package/src/api/protocol-v2/DevGetFirmwareUpdateStatus.ts +18 -0
  123. package/src/api/protocol-v2/DevGetOnboardingStatus.ts +18 -0
  124. package/src/api/protocol-v2/DevReboot.ts +22 -0
  125. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
  126. package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
  127. package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
  128. package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
  129. package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
  130. package/src/api/protocol-v2/Ping.ts +16 -0
  131. package/src/api/protocol-v2/helpers.ts +138 -0
  132. package/src/core/index.ts +26 -4
  133. package/src/data/messages/messages-pro2.json +13102 -0
  134. package/src/data-manager/DataManager.ts +6 -2
  135. package/src/data-manager/TransportManager.ts +29 -3
  136. package/src/device/Device.ts +68 -8
  137. package/src/device/DeviceCommands.ts +162 -26
  138. package/src/device/DeviceConnector.ts +29 -4
  139. package/src/device/DevicePool.ts +1 -1
  140. package/src/events/ui-request.ts +8 -0
  141. package/src/inject.ts +42 -1
  142. package/src/protocols/protocol-v2/features.ts +266 -0
  143. package/src/protocols/protocol-v2/firmware.ts +26 -0
  144. package/src/protocols/protocol-v2/index.ts +2 -0
  145. package/src/types/api/export.ts +1 -0
  146. package/src/types/api/firmwareUpdate.ts +12 -0
  147. package/src/types/api/index.ts +63 -1
  148. package/src/types/api/protocolV2.ts +221 -0
  149. package/src/types/api/searchDevices.ts +2 -2
  150. package/src/types/device.ts +3 -1
  151. package/src/types/params.ts +7 -0
  152. package/src/types/settings.ts +1 -1
  153. package/src/utils/deviceInfoUtils.ts +14 -5
  154. package/src/utils/index.ts +1 -0
  155. package/__tests__/DeviceCommands.test.ts +0 -99
  156. package/__tests__/evmLedgerLegacySafety.test.ts +0 -261
@@ -1,4 +1,4 @@
1
1
  import type { SearchDevice } from '../device';
2
- import type { Response } from '../params';
2
+ import type { CommonParams, Response } from '../params';
3
3
 
4
- export declare function searchDevices(): Response<SearchDevice[]>;
4
+ export declare function searchDevices(params?: CommonParams): Response<SearchDevice[]>;
@@ -96,7 +96,8 @@ export type IDeviceType =
96
96
  | EDeviceType.ClassicPure
97
97
  | EDeviceType.Mini
98
98
  | EDeviceType.Touch
99
- | EDeviceType.Pro;
99
+ | EDeviceType.Pro
100
+ | EDeviceType.Pro2;
100
101
 
101
102
  /**
102
103
  * model_classic: 'classic' | 'classic1s' | 'classicpure'
@@ -124,6 +125,7 @@ export const DeviceTypeToModels: { [deviceType in IDeviceType]: IDeviceModel[] }
124
125
  [EDeviceType.Mini]: ['model_mini'],
125
126
  [EDeviceType.Touch]: ['model_touch'],
126
127
  [EDeviceType.Pro]: ['model_touch'],
128
+ [EDeviceType.Pro2]: [],
127
129
  [EDeviceType.Unknown]: [],
128
130
  };
129
131
 
@@ -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
@@ -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
- });