@onekeyfe/hd-core 1.1.26-alpha.2 → 1.1.26-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 +912 -0
  2. package/dist/api/DirList.d.ts +10 -0
  3. package/dist/api/DirList.d.ts.map +1 -0
  4. package/dist/api/DirMake.d.ts +9 -0
  5. package/dist/api/DirMake.d.ts.map +1 -0
  6. package/dist/api/DirRemove.d.ts +9 -0
  7. package/dist/api/DirRemove.d.ts.map +1 -0
  8. package/dist/api/FileDelete.d.ts +9 -0
  9. package/dist/api/FileDelete.d.ts.map +1 -0
  10. package/dist/api/FileRead.d.ts +19 -0
  11. package/dist/api/FileRead.d.ts.map +1 -0
  12. package/dist/api/FileWrite.d.ts +23 -0
  13. package/dist/api/FileWrite.d.ts.map +1 -0
  14. package/dist/api/FirmwareUpdateV3.d.ts +1 -0
  15. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  16. package/dist/api/FirmwareUpdateV4.d.ts +32 -0
  17. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
  18. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  19. package/dist/api/PathInfo.d.ts +9 -0
  20. package/dist/api/PathInfo.d.ts.map +1 -0
  21. package/dist/api/SearchDevices.d.ts +2 -1
  22. package/dist/api/SearchDevices.d.ts.map +1 -1
  23. package/dist/api/alephium/AlephiumSignTransaction.d.ts +1 -1
  24. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  25. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
  26. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  27. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  28. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
  29. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  30. package/dist/api/index.d.ts +27 -0
  31. package/dist/api/index.d.ts.map +1 -1
  32. package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts +7 -0
  33. package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts.map +1 -0
  34. package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts +7 -0
  35. package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts.map +1 -0
  36. package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts +6 -0
  37. package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts.map +1 -0
  38. package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts +6 -0
  39. package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts.map +1 -0
  40. package/dist/api/protocol-v2/DevReboot.d.ts +7 -0
  41. package/dist/api/protocol-v2/DevReboot.d.ts.map +1 -0
  42. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
  43. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
  44. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
  45. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
  46. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
  47. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
  48. package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
  49. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
  50. package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
  51. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
  52. package/dist/api/protocol-v2/Ping.d.ts +8 -0
  53. package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
  54. package/dist/api/protocol-v2/helpers.d.ts +49 -0
  55. package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
  56. package/dist/api/ton/TonSignData.d.ts +7 -0
  57. package/dist/api/ton/TonSignData.d.ts.map +1 -0
  58. package/dist/constants/index.d.ts +1 -1
  59. package/dist/constants/index.d.ts.map +1 -1
  60. package/dist/core/index.d.ts.map +1 -1
  61. package/dist/data-manager/DataManager.d.ts +4 -2
  62. package/dist/data-manager/DataManager.d.ts.map +1 -1
  63. package/dist/data-manager/TransportManager.d.ts +2 -1
  64. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  65. package/dist/device/Device.d.ts +5 -3
  66. package/dist/device/Device.d.ts.map +1 -1
  67. package/dist/device/DeviceCommands.d.ts +12 -12
  68. package/dist/device/DeviceCommands.d.ts.map +1 -1
  69. package/dist/device/DeviceConnector.d.ts +2 -1
  70. package/dist/device/DeviceConnector.d.ts.map +1 -1
  71. package/dist/events/ui-request.d.ts +8 -0
  72. package/dist/events/ui-request.d.ts.map +1 -1
  73. package/dist/index.d.ts +207 -23
  74. package/dist/index.js +2815 -182
  75. package/dist/inject.d.ts.map +1 -1
  76. package/dist/protocols/protocol-v2/features.d.ts +56 -0
  77. package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
  78. package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
  79. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
  80. package/dist/protocols/protocol-v2/index.d.ts +3 -0
  81. package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
  82. package/dist/types/api/export.d.ts +2 -1
  83. package/dist/types/api/export.d.ts.map +1 -1
  84. package/dist/types/api/firmwareUpdate.d.ts +7 -0
  85. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  86. package/dist/types/api/index.d.ts +30 -1
  87. package/dist/types/api/index.d.ts.map +1 -1
  88. package/dist/types/api/protocolV2.d.ts +123 -0
  89. package/dist/types/api/protocolV2.d.ts.map +1 -0
  90. package/dist/types/api/searchDevices.d.ts +2 -2
  91. package/dist/types/api/searchDevices.d.ts.map +1 -1
  92. package/dist/types/api/tonSignData.d.ts +18 -0
  93. package/dist/types/api/tonSignData.d.ts.map +1 -0
  94. package/dist/types/device.d.ts +1 -1
  95. package/dist/types/device.d.ts.map +1 -1
  96. package/dist/types/params.d.ts +2 -0
  97. package/dist/types/params.d.ts.map +1 -1
  98. package/dist/types/settings.d.ts +1 -1
  99. package/dist/types/settings.d.ts.map +1 -1
  100. package/dist/utils/deviceInfoUtils.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/DirList.ts +25 -0
  106. package/src/api/DirMake.ts +20 -0
  107. package/src/api/DirRemove.ts +20 -0
  108. package/src/api/FileDelete.ts +20 -0
  109. package/src/api/FileRead.ts +161 -0
  110. package/src/api/FileWrite.ts +191 -0
  111. package/src/api/FirmwareUpdateV3.ts +21 -4
  112. package/src/api/FirmwareUpdateV4.ts +810 -0
  113. package/src/api/GetOnekeyFeatures.ts +75 -3
  114. package/src/api/PathInfo.ts +24 -0
  115. package/src/api/SearchDevices.ts +7 -2
  116. package/src/api/alephium/AlephiumSignTransaction.ts +6 -5
  117. package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
  118. package/src/api/device/DeviceRebootToBootloader.ts +10 -1
  119. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
  120. package/src/api/index.ts +29 -0
  121. package/src/api/protocol-v2/DevFirmwareUpdate.ts +33 -0
  122. package/src/api/protocol-v2/DevGetDeviceInfo.ts +35 -0
  123. package/src/api/protocol-v2/DevGetFirmwareUpdateStatus.ts +18 -0
  124. package/src/api/protocol-v2/DevGetOnboardingStatus.ts +18 -0
  125. package/src/api/protocol-v2/DevReboot.ts +22 -0
  126. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
  127. package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
  128. package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
  129. package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
  130. package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
  131. package/src/api/protocol-v2/Ping.ts +16 -0
  132. package/src/api/protocol-v2/helpers.ts +140 -0
  133. package/src/api/ton/TonSignData.ts +60 -0
  134. package/src/constants/index.ts +1 -1
  135. package/src/core/index.ts +19 -2
  136. package/src/data/messages/messages-pro2.json +733 -0
  137. package/src/data/messages/messages.json +98 -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 +66 -8
  141. package/src/device/DeviceCommands.ts +160 -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 +45 -1
  146. package/src/protocols/protocol-v2/features.ts +259 -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 +2 -0
  150. package/src/types/api/firmwareUpdate.ts +12 -0
  151. package/src/types/api/index.ts +65 -1
  152. package/src/types/api/protocolV2.ts +221 -0
  153. package/src/types/api/searchDevices.ts +2 -2
  154. package/src/types/api/tonSignData.ts +29 -0
  155. package/src/types/device.ts +3 -1
  156. package/src/types/params.ts +7 -0
  157. package/src/types/settings.ts +1 -1
  158. package/src/utils/deviceInfoUtils.ts +9 -5
@@ -0,0 +1,221 @@
1
+ import type { CommonParams, Response } from '../params';
2
+ import type {
3
+ DevFirmwareTarget,
4
+ DevFirmwareUpdateStatus,
5
+ DevOnboardingStatus,
6
+ DevInfoTargets,
7
+ DevInfoTypes,
8
+ DevRebootType,
9
+ FactoryDeviceInfo,
10
+ ProtoVersion,
11
+ ProtocolV2DeviceInfo,
12
+ Success,
13
+ } from '@onekeyfe/hd-transport';
14
+
15
+ // ── Shared response shapes (Protocol V2 file system) ────────────────────
16
+
17
+ export type FileOpSuccess = { message?: string };
18
+
19
+ export type FileInfo = {
20
+ path: string;
21
+ offset: number;
22
+ total_size: number;
23
+ data?: Uint8Array;
24
+ data_hash?: number;
25
+ processed_byte?: number;
26
+ chunks?: number;
27
+ };
28
+
29
+ export type DirInfo = {
30
+ path: string;
31
+ child_dirs?: string;
32
+ child_files?: string;
33
+ };
34
+
35
+ export type PathInfoResult = {
36
+ exist: boolean;
37
+ size: number;
38
+ year: number;
39
+ month: number;
40
+ day: number;
41
+ hour: number;
42
+ minute: number;
43
+ second: number;
44
+ readonly?: boolean;
45
+ hidden?: boolean;
46
+ system?: boolean;
47
+ archive?: boolean;
48
+ directory?: boolean;
49
+ };
50
+
51
+ export type DevRebootParams = {
52
+ rebootType?: DevRebootType | string | number;
53
+ reboot_type?: DevRebootType | string | number;
54
+ };
55
+
56
+ export type DevGetDeviceInfoParams = {
57
+ targets?: DevInfoTargets;
58
+ types?: DevInfoTypes;
59
+ targetHw?: boolean;
60
+ targetFw?: boolean;
61
+ targetBt?: boolean;
62
+ targetSe1?: boolean;
63
+ targetSe2?: boolean;
64
+ targetSe3?: boolean;
65
+ targetSe4?: boolean;
66
+ targetStatus?: boolean;
67
+ includeVersion?: boolean;
68
+ includeBuildId?: boolean;
69
+ includeHash?: boolean;
70
+ includeSpecific?: boolean;
71
+ };
72
+
73
+ export type DevFirmwareUpdateParams = {
74
+ targets?: DevFirmwareTarget[];
75
+ targetId?: DevFirmwareTarget['target_id'] | string | number;
76
+ target_id?: DevFirmwareTarget['target_id'] | string | number;
77
+ path?: string;
78
+ };
79
+
80
+ export type FactoryDeviceInfoSettingsParams = {
81
+ serial_no?: string;
82
+ serialNo?: string;
83
+ cpu_info?: string;
84
+ cpuInfo?: string;
85
+ pre_firmware?: string;
86
+ preFirmware?: string;
87
+ };
88
+
89
+ // ── Method signatures ─────────────────────────────────────────────────────
90
+
91
+ export declare function fileRead(
92
+ connectId: string,
93
+ params: {
94
+ path: string;
95
+ offset?: number;
96
+ totalSize?: number;
97
+ chunkLen?: number;
98
+ uiPercentage?: number;
99
+ }
100
+ ): Response<FileInfo>;
101
+
102
+ export declare function fileWrite(
103
+ connectId: string,
104
+ params: {
105
+ path: string;
106
+ offset?: number;
107
+ totalSize?: number;
108
+ chunkSize?: number;
109
+ chunkLen?: number;
110
+ data: ArrayBuffer | Uint8Array | Blob | string;
111
+ overwrite?: boolean;
112
+ append?: boolean;
113
+ uiPercentage?: number;
114
+ }
115
+ ): Response<FileInfo>;
116
+
117
+ export declare function fileDelete(
118
+ connectId: string,
119
+ params: { path: string }
120
+ ): Response<FileOpSuccess>;
121
+
122
+ export declare function dirList(
123
+ connectId: string,
124
+ params: { path: string; depth?: number }
125
+ ): Response<DirInfo>;
126
+
127
+ export declare function dirMake(
128
+ connectId: string,
129
+ params: { path: string }
130
+ ): Response<FileOpSuccess>;
131
+
132
+ export declare function dirRemove(
133
+ connectId: string,
134
+ params: { path: string }
135
+ ): Response<FileOpSuccess>;
136
+
137
+ export declare function pathInfo(
138
+ connectId: string,
139
+ params: { path: string }
140
+ ): Response<PathInfoResult>;
141
+
142
+ export declare function getProtoVersion(
143
+ connectId: string,
144
+ params?: CommonParams
145
+ ): Response<ProtoVersion>;
146
+
147
+ export declare function ping(
148
+ connectId: string,
149
+ params?: CommonParams & { message?: string }
150
+ ): Response<Success>;
151
+
152
+ export declare function devReboot(
153
+ connectId: string,
154
+ params: CommonParams & DevRebootParams
155
+ ): Response<Success>;
156
+
157
+ export declare function devGetDeviceInfo(
158
+ connectId: string,
159
+ params?: CommonParams & DevGetDeviceInfoParams
160
+ ): Response<ProtocolV2DeviceInfo>;
161
+
162
+ export declare function devGetOnboardingStatus(
163
+ connectId: string,
164
+ params?: CommonParams
165
+ ): Response<DevOnboardingStatus>;
166
+
167
+ export declare function devFirmwareUpdate(
168
+ connectId: string,
169
+ params: CommonParams & DevFirmwareUpdateParams
170
+ ): Response<Success | DevFirmwareUpdateStatus>;
171
+
172
+ export declare function devGetFirmwareUpdateStatus(
173
+ connectId: string,
174
+ params?: CommonParams
175
+ ): Response<DevFirmwareUpdateStatus>;
176
+
177
+ export declare function factoryDeviceInfoSettings(
178
+ connectId: string,
179
+ params: FactoryDeviceInfoSettingsParams
180
+ ): Response<Success>;
181
+
182
+ export declare function factoryGetDeviceInfo(connectId: string): Response<FactoryDeviceInfo>;
183
+
184
+ export declare function filesystemFixPermission(connectId: string): Response<Success>;
185
+
186
+ export declare function filesystemFileRead(
187
+ connectId: string,
188
+ params: Parameters<typeof fileRead>[1]
189
+ ): ReturnType<typeof fileRead>;
190
+
191
+ export declare function filesystemFileWrite(
192
+ connectId: string,
193
+ params: Parameters<typeof fileWrite>[1]
194
+ ): ReturnType<typeof fileWrite>;
195
+
196
+ export declare function filesystemFileDelete(
197
+ connectId: string,
198
+ params: Parameters<typeof fileDelete>[1]
199
+ ): ReturnType<typeof fileDelete>;
200
+
201
+ export declare function filesystemDirList(
202
+ connectId: string,
203
+ params: Parameters<typeof dirList>[1]
204
+ ): ReturnType<typeof dirList>;
205
+
206
+ export declare function filesystemDirMake(
207
+ connectId: string,
208
+ params: Parameters<typeof dirMake>[1]
209
+ ): ReturnType<typeof dirMake>;
210
+
211
+ export declare function filesystemDirRemove(
212
+ connectId: string,
213
+ params: Parameters<typeof dirRemove>[1]
214
+ ): ReturnType<typeof dirRemove>;
215
+
216
+ export declare function filesystemPathInfoQuery(
217
+ connectId: string,
218
+ params: Parameters<typeof pathInfo>[1]
219
+ ): ReturnType<typeof pathInfo>;
220
+
221
+ export declare function filesystemFormat(connectId: string): Response<Success>;
@@ -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[]>;
@@ -0,0 +1,29 @@
1
+ import type {
2
+ TonSignDataType,
3
+ TonSignedData,
4
+ TonWalletVersion,
5
+ TonWorkChain,
6
+ UintType,
7
+ } from '@onekeyfe/hd-transport';
8
+ import type { CommonParams, Response } from '../params';
9
+
10
+ export type TonSignDataParams = {
11
+ path: string | number[];
12
+ type: TonSignDataType;
13
+ payload: string;
14
+ schema?: string;
15
+ appdomain: string;
16
+ timestamp: UintType;
17
+ fromAddress?: string;
18
+ walletVersion?: TonWalletVersion;
19
+ walletId?: number;
20
+ workchain?: TonWorkChain;
21
+ isBounceable?: boolean;
22
+ isTestnetOnly?: boolean;
23
+ };
24
+
25
+ export declare function tonSignData(
26
+ connectId: string,
27
+ deviceId: string,
28
+ params: CommonParams & TonSignDataParams
29
+ ): Response<TonSignedData>;
@@ -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
  };