@onekeyfe/hd-core 1.2.0-alpha.11 → 1.2.0-alpha.13

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 (59) hide show
  1. package/__tests__/protocol-v2-bootloader-mode.test.ts +37 -0
  2. package/__tests__/protocol-v2.test.ts +240 -82
  3. package/__tests__/protocolV2FileWrite.test.ts +67 -0
  4. package/dist/api/FileWrite.d.ts.map +1 -1
  5. package/dist/api/FirmwareUpdateV4.d.ts +2 -0
  6. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  7. package/dist/api/helpers/protocolV2FileWrite.d.ts +32 -0
  8. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -0
  9. package/dist/api/index.d.ts +1 -1
  10. package/dist/api/index.d.ts.map +1 -1
  11. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
  12. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
  13. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  14. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  15. package/dist/device/Device.d.ts.map +1 -1
  16. package/dist/deviceProfile/buildDeviceFeatures.d.ts +2 -2
  17. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  18. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  19. package/dist/index.d.ts +9 -11
  20. package/dist/index.js +736 -391
  21. package/dist/protocols/protocol-v2/features.d.ts +1 -0
  22. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  23. package/dist/protocols/protocol-v2/index.d.ts +1 -1
  24. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  25. package/dist/types/api/getDeviceInfo.d.ts +1 -1
  26. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  27. package/dist/types/api/index.d.ts +2 -2
  28. package/dist/types/api/index.d.ts.map +1 -1
  29. package/dist/types/api/protocolV2.d.ts +2 -5
  30. package/dist/types/api/protocolV2.d.ts.map +1 -1
  31. package/dist/types/device.d.ts +3 -2
  32. package/dist/types/device.d.ts.map +1 -1
  33. package/dist/utils/patch.d.ts +1 -1
  34. package/dist/utils/patch.d.ts.map +1 -1
  35. package/package.json +4 -4
  36. package/src/api/FileWrite.ts +18 -186
  37. package/src/api/FirmwareUpdateV4.ts +46 -6
  38. package/src/api/cardano/CardanoSignMessage.ts +1 -1
  39. package/src/api/cardano/CardanoSignTransaction.ts +1 -1
  40. package/src/api/helpers/protocolV2FileWrite.ts +168 -0
  41. package/src/api/index.ts +1 -1
  42. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
  43. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +22 -52
  44. package/src/api/protocol-v2/helpers.ts +0 -3
  45. package/src/data/messages/messages-protocol-v2.json +422 -16
  46. package/src/data/messages/messages.json +0 -8
  47. package/src/device/Device.ts +7 -17
  48. package/src/deviceProfile/buildDeviceFeatures.ts +28 -12
  49. package/src/deviceProfile/buildDeviceProfile.ts +8 -6
  50. package/src/inject.ts +2 -2
  51. package/src/protocols/protocol-v2/features.ts +19 -1
  52. package/src/protocols/protocol-v2/index.ts +2 -0
  53. package/src/types/api/getDeviceInfo.ts +1 -1
  54. package/src/types/api/index.ts +2 -2
  55. package/src/types/api/protocolV2.ts +6 -6
  56. package/src/types/device.ts +6 -1
  57. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +0 -13
  58. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +0 -1
  59. package/src/api/protocol-v2/FilesystemDiskControl.ts +0 -50
@@ -50,8 +50,26 @@ export const getProtocolV2SeState = (se?: DeviceSEInfo): ProtocolV2SeStateLabel
50
50
  export const getProtocolV2SeType = (se?: DeviceSEInfo): string | null =>
51
51
  normalizeEnumValue(DeviceSeType, se?.type);
52
52
 
53
+ /**
54
+ * 兼容尚未提供显式 runtime mode 的 Protocol V2 固件。
55
+ *
56
+ * 当前 romloader 只上报 hw、fw.romloader 和 fw.bootloader;bootloader
57
+ * 还会上报 application/application_data、coprocessor 或 SE 信息。
58
+ */
59
+ export const isProtocolV2RomloaderDeviceInfo = (deviceInfo?: ProtocolV2DeviceInfo | null) =>
60
+ !!deviceInfo &&
61
+ deviceInfo.status == null &&
62
+ deviceInfo.fw?.romloader != null &&
63
+ deviceInfo.fw?.application == null &&
64
+ deviceInfo.fw?.application_data == null &&
65
+ deviceInfo.coprocessor == null &&
66
+ deviceInfo.se1 == null &&
67
+ deviceInfo.se2 == null &&
68
+ deviceInfo.se3 == null &&
69
+ deviceInfo.se4 == null;
70
+
53
71
  export const isProtocolV2BootloaderDeviceInfo = (deviceInfo?: ProtocolV2DeviceInfo | null) =>
54
- !!deviceInfo && deviceInfo.status == null;
72
+ !!deviceInfo && deviceInfo.status == null && !isProtocolV2RomloaderDeviceInfo(deviceInfo);
55
73
 
56
74
  export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
57
75
  targets: {
@@ -4,6 +4,8 @@ export {
4
4
  PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST,
5
5
  PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
6
6
  PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
7
+ isProtocolV2BootloaderDeviceInfo,
8
+ isProtocolV2RomloaderDeviceInfo,
7
9
  getProtocolV2SeState,
8
10
  getProtocolV2SeType,
9
11
  } from './features';
@@ -16,7 +16,7 @@ export type GetDeviceInfoParams = {
16
16
  includeRaw?: boolean;
17
17
  };
18
18
 
19
- export type DeviceInfoMode = 'normal' | 'bootloader' | 'notInitialized' | 'unknown';
19
+ export type DeviceInfoMode = 'normal' | 'bootloader' | 'romloader' | 'notInitialized' | 'unknown';
20
20
 
21
21
  export type DeviceInfoStatus = {
22
22
  mode: DeviceInfoMode;
@@ -3,6 +3,7 @@ import type {
3
3
  deviceFactoryInfoSet,
4
4
  deviceFirmwareUpdate,
5
5
  deviceGetFirmwareUpdateStatus,
6
+ deviceGetOnboardingStatus,
6
7
  deviceInfoGet,
7
8
  deviceReboot,
8
9
  deviceSessionGet,
@@ -20,7 +21,6 @@ import type {
20
21
  filesystemDirList,
21
22
  filesystemDirMake,
22
23
  filesystemDirRemove,
23
- filesystemDiskControl,
24
24
  filesystemFileDelete,
25
25
  filesystemFileRead,
26
26
  filesystemFileWrite,
@@ -266,6 +266,7 @@ export type CoreApi = {
266
266
  deviceReboot: typeof deviceReboot;
267
267
  deviceInfoGet: typeof deviceInfoGet;
268
268
  deviceStatusGet: typeof deviceStatusGet;
269
+ deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
269
270
  deviceSessionGet: typeof deviceSessionGet;
270
271
  deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
271
272
  deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
@@ -292,7 +293,6 @@ export type CoreApi = {
292
293
  filesystemDirRemove: typeof filesystemDirRemove;
293
294
  filesystemPathInfoQuery: typeof filesystemPathInfoQuery;
294
295
  filesystemFormat: typeof filesystemFormat;
295
- filesystemDiskControl: typeof filesystemDiskControl;
296
296
 
297
297
  /**
298
298
  * All network function
@@ -2,6 +2,7 @@ import type { CommonParams, Response } from '../params';
2
2
  import type {
3
3
  DeviceFactoryInfo,
4
4
  DeviceFirmwareUpdateStatus,
5
+ DevOnboardingStatus,
5
6
  DeviceSession,
6
7
  DeviceSettings,
7
8
  DeviceStatus,
@@ -111,6 +112,11 @@ export declare function deviceStatusGet(
111
112
  params?: CommonParams
112
113
  ): Response<DeviceStatus>;
113
114
 
115
+ export declare function deviceGetOnboardingStatus(
116
+ connectId: string,
117
+ params?: CommonParams
118
+ ): Response<DevOnboardingStatus>;
119
+
114
120
  export declare function deviceSessionGet(
115
121
  connectId: string,
116
122
  params?: CommonParams
@@ -231,9 +237,3 @@ export declare const filesystemDirRemove: typeof dirRemove;
231
237
  export declare const filesystemPathInfoQuery: typeof pathInfo;
232
238
 
233
239
  export declare function filesystemFormat(connectId: string): Response<Success>;
234
-
235
- export declare function filesystemDiskControl(
236
- connectId: string,
237
- // enable 收紧为 boolean | 0 | 1(兼容历史的 '0' / '1' 字符串输入,内部归一化为 0/1)
238
- params: CommonParams & { enable: boolean | 0 | 1; timeoutMs?: number | string }
239
- ): Response<Success>;
@@ -91,6 +91,7 @@ export type DeviceFeaturesProtocol = 'V1' | 'V2' | 'unknown';
91
91
  export type DeviceFeaturesMode =
92
92
  | 'normal'
93
93
  | 'bootloader'
94
+ | 'romloader'
94
95
  | 'notInitialized'
95
96
  | 'backupMode'
96
97
  | 'unknown';
@@ -128,7 +129,7 @@ export type DeviceFeaturesRaw = {
128
129
  protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
129
130
  };
130
131
 
131
- export type Features = {
132
+ export type NormalizedFeatures = {
132
133
  protocol: DeviceFeaturesProtocol;
133
134
  protocolVersion?: number | null;
134
135
  deviceType: IDeviceType;
@@ -182,6 +183,10 @@ export type Features = {
182
183
  raw?: DeviceFeaturesRaw;
183
184
  };
184
185
 
186
+ export type Features = NormalizedFeatures &
187
+ Partial<Omit<PROTO.Features, keyof NormalizedFeatures>> &
188
+ Partial<Omit<PROTO.OnekeyFeatures, keyof NormalizedFeatures | keyof PROTO.Features>>;
189
+
185
190
  export type OnekeyFeatures = PROTO.OnekeyFeatures;
186
191
 
187
192
  export type IDeviceType =
@@ -1,13 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- export type FilesystemDiskControlParams = {
3
- enable?: boolean | 0 | 1;
4
- timeoutMs?: number | string;
5
- };
6
- export default class FilesystemDiskControl extends BaseMethod<{
7
- enable: 0 | 1;
8
- timeoutMs?: number;
9
- }> {
10
- init(): void;
11
- run(): Promise<any>;
12
- }
13
- //# sourceMappingURL=FilesystemDiskControl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FilesystemDiskControl.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/FilesystemDiskControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,MAAM,MAAM,2BAA2B,GAAG;IAExC,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B,CAAC;AAUF,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,UAAU,CAAC;IAC5D,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;IACA,IAAI;IAWE,GAAG;CAcV"}
@@ -1,50 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import {
3
- invalidParameter,
4
- validateOptionalNonNegativeInteger,
5
- } from '../helpers/filesystemValidation';
6
-
7
- export type FilesystemDiskControlParams = {
8
- // 收紧为 boolean | 0 | 1;'0' / '1' 字符串仅作为历史输入向后兼容,内部归一化为 0/1
9
- enable?: boolean | 0 | 1;
10
- timeoutMs?: number | string;
11
- };
12
-
13
- function normalizeDiskControlEnable(value: unknown): 0 | 1 {
14
- if (value === undefined || value === null) return 0;
15
- if (typeof value === 'boolean') return value ? 1 : 0;
16
- if (value === 0 || value === '0') return 0;
17
- if (value === 1 || value === '1') return 1;
18
- throw invalidParameter('Parameter [enable] must be a boolean or 0 | 1.');
19
- }
20
-
21
- export default class FilesystemDiskControl extends BaseMethod<{
22
- enable: 0 | 1;
23
- timeoutMs?: number;
24
- }> {
25
- init() {
26
- // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
27
- this.requireProtocolV2 = true;
28
- this.skipForceUpdateCheck = true;
29
- this.useDevicePassphraseState = false;
30
- this.params = {
31
- enable: normalizeDiskControlEnable(this.payload.enable),
32
- timeoutMs: validateOptionalNonNegativeInteger(this.payload.timeoutMs, 'timeoutMs'),
33
- };
34
- }
35
-
36
- async run() {
37
- const typedCall = this.device.commands.typedCall as any;
38
- const res = await typedCall(
39
- 'FilesystemDiskControl',
40
- 'Success',
41
- {
42
- enable: this.params.enable,
43
- },
44
- {
45
- timeoutMs: this.params.timeoutMs,
46
- }
47
- );
48
- return Promise.resolve(res.message);
49
- }
50
- }