@onekeyfe/hd-core 1.2.0-alpha.3 → 1.2.0-alpha.4

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 (112) hide show
  1. package/__tests__/preInitialize.test.ts +33 -0
  2. package/__tests__/protocol-v2.test.ts +1377 -480
  3. package/dist/api/FileRead.d.ts.map +1 -1
  4. package/dist/api/FileWrite.d.ts.map +1 -1
  5. package/dist/api/FirmwareUpdateV4.d.ts +20 -2
  6. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  7. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  8. package/dist/api/firmware/getBinary.d.ts +4 -0
  9. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  10. package/dist/api/index.d.ts +5 -10
  11. package/dist/api/index.d.ts.map +1 -1
  12. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
  13. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
  14. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
  15. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
  16. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -1
  17. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
  18. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +1 -1
  19. package/dist/api/protocol-v2/{DeviceGetDeviceInfo.d.ts → DeviceInfoGet.d.ts} +10 -10
  20. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
  21. package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
  22. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
  23. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
  24. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
  25. package/dist/api/protocol-v2/helpers.d.ts +24 -18
  26. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  27. package/dist/api/ton/TonSignData.d.ts +1 -5
  28. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  29. package/dist/core/index.d.ts.map +1 -1
  30. package/dist/data-manager/DataManager.d.ts +1 -1
  31. package/dist/data-manager/DataManager.d.ts.map +1 -1
  32. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  33. package/dist/device/Device.d.ts +4 -1
  34. package/dist/device/Device.d.ts.map +1 -1
  35. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  36. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  37. package/dist/index.d.ts +79 -54
  38. package/dist/index.js +1537 -1528
  39. package/dist/inject.d.ts.map +1 -1
  40. package/dist/protocols/protocol-v2/features.d.ts +12 -14
  41. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  42. package/dist/protocols/protocol-v2/firmware.d.ts +10 -9
  43. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  44. package/dist/types/api/firmwareUpdate.d.ts +1 -6
  45. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  46. package/dist/types/api/getDeviceInfo.d.ts +2 -0
  47. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  48. package/dist/types/api/index.d.ts +6 -11
  49. package/dist/types/api/index.d.ts.map +1 -1
  50. package/dist/types/api/protocolV2.d.ts +12 -17
  51. package/dist/types/api/protocolV2.d.ts.map +1 -1
  52. package/dist/types/device.d.ts +1 -0
  53. package/dist/types/device.d.ts.map +1 -1
  54. package/dist/types/params.d.ts +1 -0
  55. package/dist/types/params.d.ts.map +1 -1
  56. package/dist/types/settings.d.ts +29 -2
  57. package/dist/types/settings.d.ts.map +1 -1
  58. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  59. package/dist/utils/patch.d.ts +1 -1
  60. package/dist/utils/patch.d.ts.map +1 -1
  61. package/package.json +4 -4
  62. package/src/api/FileRead.ts +14 -1
  63. package/src/api/FileWrite.ts +14 -1
  64. package/src/api/FirmwareUpdateV4.ts +933 -197
  65. package/src/api/GetOnekeyFeatures.ts +1 -1
  66. package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
  67. package/src/api/device/DeviceRebootToBootloader.ts +4 -4
  68. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +11 -4
  69. package/src/api/index.ts +5 -10
  70. package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +3 -3
  71. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
  72. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +3 -5
  73. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +2 -2
  74. package/src/api/protocol-v2/{DeviceGetDeviceInfo.ts → DeviceInfoGet.ts} +52 -22
  75. package/src/api/protocol-v2/DeviceReboot.ts +1 -1
  76. package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +2 -2
  77. package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +2 -2
  78. package/src/api/protocol-v2/helpers.ts +59 -43
  79. package/src/api/ton/TonSignData.ts +1 -5
  80. package/src/core/index.ts +19 -5
  81. package/src/data/messages/messages-protocol-v2.json +486 -1072
  82. package/src/data-manager/DataManager.ts +7 -0
  83. package/src/data-manager/connectSettings.ts +0 -6
  84. package/src/device/Device.ts +25 -14
  85. package/src/deviceProfile/buildDeviceFeatures.ts +60 -63
  86. package/src/deviceProfile/buildDeviceProfile.ts +77 -58
  87. package/src/inject.ts +10 -16
  88. package/src/protocols/protocol-v2/features.ts +26 -63
  89. package/src/protocols/protocol-v2/firmware.ts +11 -36
  90. package/src/types/api/firmwareUpdate.ts +10 -20
  91. package/src/types/api/getDeviceInfo.ts +2 -0
  92. package/src/types/api/index.ts +10 -20
  93. package/src/types/api/protocolV2.ts +22 -42
  94. package/src/types/device.ts +1 -0
  95. package/src/types/params.ts +4 -0
  96. package/src/types/settings.ts +44 -35
  97. package/src/utils/deviceFeaturesUtils.ts +45 -10
  98. package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
  99. package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
  100. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
  101. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
  102. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
  103. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
  104. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
  105. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
  106. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
  107. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
  108. package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
  109. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
  110. package/src/api/protocol-v2/DevReboot.ts +0 -24
  111. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -16
  112. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
@@ -1,7 +1,11 @@
1
1
  import semver from 'semver';
2
2
  import { isNaN } from 'lodash';
3
3
  import { EDeviceType, type EFirmwareType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
4
- import { Enum_Capability, type GetPassphraseState } from '@onekeyfe/hd-transport';
4
+ import {
5
+ Enum_Capability,
6
+ type DeviceSessionGet,
7
+ type GetPassphraseState,
8
+ } from '@onekeyfe/hd-transport';
5
9
 
6
10
  import { toHardened } from '../api/helpers/pathUtils';
7
11
  import { DeviceModelToTypes, DeviceTypeToModels } from '../types';
@@ -17,9 +21,7 @@ import { existCapability } from './capabilitieUtils';
17
21
  import type { Device } from '../device/Device';
18
22
  import type { Features, IDeviceType, SupportFeatureType } from '../types';
19
23
 
20
- // 生成的 GetPassphraseState 已包含 _only_main_pin / allow_create_attach_pin,
21
- // 不再需要手动扩展字段。
22
- type GetPassphraseStateMessage = GetPassphraseState;
24
+ type DeviceSessionGetMessage = DeviceSessionGet;
23
25
 
24
26
  export const getSupportProtocolV1MessageSchema = (
25
27
  features: Features | undefined
@@ -136,11 +138,14 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
136
138
  options?.initSession ? null : device.features?.sessionId
137
139
  );
138
140
 
139
- return { passphraseState, newSession, unlockedAttachPin };
141
+ return {
142
+ passphraseState,
143
+ newSession,
144
+ unlockedAttachPin: unlockedAttachPin ?? device.features?.unlockedAttachPin,
145
+ };
140
146
  };
141
147
 
142
148
  // 仅适用于 Protocol V1 的 Pro:Pro2 走独立版本线,不能套用 4.15.0 门槛
143
- // (Pro2 在 getPassphraseState 中通过 isProtocolV2 直接判定支持)。
144
149
  const supportProSeriesAttachPinPassphrase = (deviceType: IDeviceType, firmwareVersion: string) =>
145
150
  deviceType === EDeviceType.Pro && semver.gte(firmwareVersion, '4.15.0');
146
151
 
@@ -166,19 +171,42 @@ export const getPassphraseState = async (
166
171
  const firmwareVersion = device.getCurrentFirmwareVersionString() ?? '0.0.0';
167
172
  const deviceType = device.getCurrentDeviceType();
168
173
 
174
+ if (device.isProtocolV2()) {
175
+ const payload: DeviceSessionGetMessage = {};
176
+ const cachedSessionId =
177
+ typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
178
+ if (cachedSessionId) {
179
+ payload.session_id = cachedSessionId;
180
+ }
181
+
182
+ const { message, type } = await commands.typedCall(
183
+ 'DeviceSessionGet',
184
+ 'DeviceSession',
185
+ payload
186
+ );
187
+
188
+ // @ts-expect-error
189
+ if (type === 'CallMethodError') {
190
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
191
+ }
192
+
193
+ return {
194
+ passphraseState: message.btc_test_address,
195
+ newSession: message.session_id,
196
+ unlockedAttachPin: features.unlockedAttachPin ?? undefined,
197
+ };
198
+ }
199
+
169
200
  const supportAttachPinCapability = existCapability(
170
201
  features,
171
202
  Enum_Capability.Capability_AttachToPin
172
203
  );
173
- // Pro2 (Protocol V2) 协议自带 GetPassphraseState(10028),固件从首个版本即支持,
174
- // 不依赖 Pro 系列的 4.15.0 版本线;V2 也没有 GetAddress Testnet 探测这条 legacy 回退路径。
175
204
  const supportGetPassphraseState =
176
- device.isProtocolV2() ||
177
205
  supportAttachPinCapability ||
178
206
  supportProSeriesAttachPinPassphrase(deviceType, firmwareVersion);
179
207
 
180
208
  if (supportGetPassphraseState) {
181
- const payload: GetPassphraseStateMessage = options?.onlyMainPin
209
+ const payload: GetPassphraseState = options?.onlyMainPin
182
210
  ? { _only_main_pin: true }
183
211
  : { passphrase_state: options?.expectPassphraseState };
184
212
  if (options?.allowCreateAttachPin) {
@@ -282,6 +310,9 @@ export const getFirmwareUpdateField = ({
282
310
  if (deviceType === EDeviceType.Pro) {
283
311
  return latestFirmwareField;
284
312
  }
313
+ if (deviceType === EDeviceType.Pro2) {
314
+ return 'firmware-v1';
315
+ }
285
316
  return 'firmware';
286
317
  };
287
318
  /**
@@ -325,6 +356,10 @@ export const getFirmwareUpdateFieldArray = (
325
356
  return ['firmware-v8'];
326
357
  }
327
358
 
359
+ if (deviceType === 'pro2') {
360
+ return ['firmware-v1'];
361
+ }
362
+
328
363
  return ['firmware'];
329
364
  };
330
365
 
@@ -1,7 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import type { DeviceRebootParams } from './helpers';
3
- export default class DevReboot extends BaseMethod<DeviceRebootParams> {
4
- init(): void;
5
- run(): Promise<import("packages/hd-transport/dist").Success>;
6
- }
7
- //# sourceMappingURL=DevReboot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DevReboot.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DevReboot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpD,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,UAAU,CAAC,kBAAkB,CAAC;IACnE,IAAI;IAWE,GAAG;CAMV"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeviceGetDeviceInfo.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceGetDeviceInfo.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,MAAM,0BAA0B,GAAG;IACvC,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,KAAK,CAAC,EAAE,wBAAwB,CAAC;CAClC,CAAC;AAmDF,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,UAAU,CAAC;IAC1D,OAAO,EAAE,0BAA0B,CAAC;IACpC,KAAK,EAAE,wBAAwB,CAAC;CACjC,CAAC;IACA,IAAI;IAmBE,GAAG;CAgBV"}
@@ -1,6 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- export default class DeviceGetOnboardingStatus extends BaseMethod {
3
- init(): void;
4
- run(): Promise<import("packages/hd-transport/dist").OnboardingStatus>;
5
- }
6
- //# sourceMappingURL=DeviceGetOnboardingStatus.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeviceGetOnboardingStatus.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceGetOnboardingStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,UAAU;IAC/D,IAAI;IAQE,GAAG;CAIV"}
@@ -1,7 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import type { FactoryDeviceInfoSettingsParams } from './helpers';
3
- export default class FactoryDeviceInfoSettings extends BaseMethod<FactoryDeviceInfoSettingsParams> {
4
- init(): void;
5
- run(): Promise<import("packages/hd-transport/dist").Success>;
6
- }
7
- //# sourceMappingURL=FactoryDeviceInfoSettings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FactoryDeviceInfoSettings.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/FactoryDeviceInfoSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,UAAU,CAAC,+BAA+B,CAAC;IAChG,IAAI;IAeE,GAAG;CAQV"}
@@ -1,6 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- export default class FactoryGetDeviceInfo extends BaseMethod {
3
- init(): void;
4
- run(): Promise<import("packages/hd-transport/dist").FactoryDeviceInfo>;
5
- }
6
- //# sourceMappingURL=FactoryGetDeviceInfo.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FactoryGetDeviceInfo.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/FactoryGetDeviceInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,UAAU;IAC1D,IAAI;IAQE,GAAG;CAQV"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"FilesystemFixPermission.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/FilesystemFixPermission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,UAAU;IAC7D,IAAI;IAQE,GAAG;CAIV"}
@@ -1,6 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- export default class GetProtoVersion extends BaseMethod {
3
- init(): void;
4
- run(): Promise<import("packages/hd-transport/dist").ProtoVersion>;
5
- }
6
- //# sourceMappingURL=GetProtoVersion.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GetProtoVersion.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/GetProtoVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU;IACrD,IAAI;IAQE,GAAG;CAIV"}
@@ -1,24 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import { normalizeRebootType } from './helpers';
3
-
4
- import type { DeviceRebootParams } from './helpers';
5
-
6
- export default class DevReboot extends BaseMethod<DeviceRebootParams> {
7
- init() {
8
- // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
9
- this.requireProtocolV2 = true;
10
- this.skipForceUpdateCheck = true;
11
- this.useDevicePassphraseState = false;
12
- this.params = {
13
- rebootType: this.payload.rebootType,
14
- reboot_type: this.payload.reboot_type,
15
- };
16
- }
17
-
18
- async run() {
19
- const res = await this.device.commands.typedCall('DevReboot', 'Success', {
20
- reboot_type: normalizeRebootType(this.params.reboot_type ?? this.params.rebootType),
21
- });
22
- return Promise.resolve(res.message);
23
- }
24
- }
@@ -1,16 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
-
3
- export default class DeviceGetOnboardingStatus extends BaseMethod {
4
- init() {
5
- // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
6
- this.requireProtocolV2 = true;
7
- this.skipForceUpdateCheck = true;
8
- this.useDevicePassphraseState = false;
9
- this.params = undefined;
10
- }
11
-
12
- async run() {
13
- const res = await this.device.commands.typedCall('GetOnboardingStatus', 'OnboardingStatus', {});
14
- return Promise.resolve(res.message);
15
- }
16
- }
@@ -1,29 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
-
3
- import type { FactoryDeviceInfoSettingsParams } from './helpers';
4
-
5
- export default class FactoryDeviceInfoSettings extends BaseMethod<FactoryDeviceInfoSettingsParams> {
6
- init() {
7
- // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
8
- this.requireProtocolV2 = true;
9
- this.skipForceUpdateCheck = true;
10
- this.useDevicePassphraseState = false;
11
- this.params = {
12
- serial_no: this.payload.serial_no,
13
- serialNo: this.payload.serialNo,
14
- cpu_info: this.payload.cpu_info,
15
- cpuInfo: this.payload.cpuInfo,
16
- pre_firmware: this.payload.pre_firmware,
17
- preFirmware: this.payload.preFirmware,
18
- };
19
- }
20
-
21
- async run() {
22
- const res = await this.device.commands.typedCall('FactoryDeviceInfoSettings', 'Success', {
23
- serial_no: this.params.serial_no ?? this.params.serialNo,
24
- cpu_info: this.params.cpu_info ?? this.params.cpuInfo,
25
- pre_firmware: this.params.pre_firmware ?? this.params.preFirmware,
26
- });
27
- return Promise.resolve(res.message);
28
- }
29
- }