@onekeyfe/hd-core 1.2.0-alpha.1 → 1.2.0-alpha.2

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 (46) hide show
  1. package/__tests__/protocol-v2.test.ts +106 -111
  2. package/dist/api/GetPassphraseState.d.ts +4 -4
  3. package/dist/api/protocol-v2/helpers.d.ts +3 -2
  4. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  5. package/dist/api/tron/TronSignMessage.d.ts +0 -1
  6. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  7. package/dist/api/tron/TronSignTransaction.d.ts +0 -1
  8. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  9. package/dist/constants/index.d.ts +1 -2
  10. package/dist/constants/index.d.ts.map +1 -1
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  13. package/dist/device/Device.d.ts +0 -1
  14. package/dist/device/Device.d.ts.map +1 -1
  15. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  16. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  17. package/dist/index.d.ts +10 -12
  18. package/dist/index.js +474 -493
  19. package/dist/protocols/protocol-v2/features.d.ts +2 -2
  20. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  21. package/dist/types/api/getPassphraseState.d.ts +4 -4
  22. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  23. package/dist/types/api/protocolV2.d.ts +3 -3
  24. package/dist/types/api/protocolV2.d.ts.map +1 -1
  25. package/dist/types/settings.d.ts +0 -1
  26. package/dist/types/settings.d.ts.map +1 -1
  27. package/dist/utils/patch.d.ts +1 -1
  28. package/dist/utils/patch.d.ts.map +1 -1
  29. package/package.json +4 -4
  30. package/src/api/GetPassphraseState.ts +4 -4
  31. package/src/api/protocol-v2/DeviceReboot.ts +3 -3
  32. package/src/api/protocol-v2/helpers.ts +26 -1
  33. package/src/api/tron/TronSignMessage.ts +0 -1
  34. package/src/api/tron/TronSignTransaction.ts +0 -1
  35. package/src/constants/index.ts +1 -10
  36. package/src/core/index.ts +0 -2
  37. package/src/data/messages/messages-protocol-v2.json +323 -329
  38. package/src/data-manager/connectSettings.ts +0 -6
  39. package/src/device/Device.ts +1 -12
  40. package/src/device/DevicePool.ts +6 -6
  41. package/src/deviceProfile/buildDeviceFeatures.ts +1 -2
  42. package/src/deviceProfile/buildDeviceProfile.ts +3 -2
  43. package/src/protocols/protocol-v2/features.ts +7 -8
  44. package/src/types/api/getPassphraseState.ts +4 -4
  45. package/src/types/api/protocolV2.ts +3 -2
  46. package/src/types/settings.ts +0 -5
@@ -27,8 +27,6 @@ const initialSettings: ConnectSettings = {
27
27
  env: 'web',
28
28
  lazyLoad: false,
29
29
  timestamp: new Date().getTime(),
30
- // 临时开关:仅用于本地/测试固件兼容;正式链路默认调用真实 DevGetDeviceInfo。
31
- protocolV2DeviceInfoMockEnabled: false,
32
30
  };
33
31
 
34
32
  export const getEnv = () => {
@@ -117,10 +115,6 @@ export const parseConnectSettings = (input: Partial<ConnectSettings> = {}) => {
117
115
  settings.fetchConfig = input.fetchConfig;
118
116
  }
119
117
 
120
- if (typeof input.protocolV2DeviceInfoMockEnabled === 'boolean') {
121
- settings.protocolV2DeviceInfoMockEnabled = input.protocolV2DeviceInfoMockEnabled;
122
- }
123
-
124
118
  return settings;
125
119
  };
126
120
 
@@ -261,14 +261,13 @@ export class Device extends EventEmitter {
261
261
  const bleName = this.getCurrentBleName();
262
262
  const label = this.getCurrentLabel();
263
263
  const serialNo = this.getCurrentSerialNo();
264
- const connectId = this.getConnectId();
265
264
  const deviceId = this.getCurrentDeviceId() || null;
266
265
 
267
266
  const features = this.features;
268
267
 
269
268
  return {
270
269
  /** Android uses Mac address, iOS uses uuid, USB uses uuid */
271
- connectId: DataManager.isBleConnect(env) ? this.mainId || null : connectId,
270
+ connectId: DataManager.isBleConnect(env) ? this.mainId || null : serialNo,
272
271
  /** Hardware ID, will not change at any time */
273
272
  uuid: serialNo,
274
273
  commType: this.originalDescriptor.commType,
@@ -502,16 +501,6 @@ export class Device extends EventEmitter {
502
501
  return this.features ? getDeviceUUID(this.features) : '';
503
502
  }
504
503
 
505
- getConnectId() {
506
- const serialNo = this.getCurrentSerialNo();
507
- if (serialNo) return serialNo;
508
-
509
- // connectId 是 SDK 内部连接路由 key;Protocol V2 早期固件/mock
510
- // 可能还没有 serial_no,此时用 transport descriptor 兜底,不改变
511
- // features.serialNo / deviceId 的业务语义。
512
- return this.originalDescriptor.path || this.originalDescriptor.id || '';
513
- }
514
-
515
504
  getCurrentBleName() {
516
505
  return getDeviceBleName(this.features);
517
506
  }
@@ -118,14 +118,14 @@ export class DevicePool extends EventEmitter {
118
118
  for await (const descriptor of descriptorList) {
119
119
  const device = await this._createDevice(descriptor, initOptions);
120
120
 
121
- const connectId = device.getConnectId();
122
- if (connectId) {
123
- if (this.devicesCache[connectId]) {
124
- const cache = this.devicesCache[connectId];
121
+ const uuid = device.getCurrentSerialNo();
122
+ if (uuid) {
123
+ if (this.devicesCache[uuid]) {
124
+ const cache = this.devicesCache[uuid];
125
125
  cache.updateDescriptor(descriptor, true);
126
126
  }
127
- this.devicesCache[connectId] = device;
128
- devices[connectId] = device;
127
+ this.devicesCache[uuid] = device;
128
+ devices[uuid] = device;
129
129
  }
130
130
 
131
131
  deviceList.push(device);
@@ -250,7 +250,6 @@ export const buildProtocolV2FeaturesPayload = (
250
250
  );
251
251
  const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), previous?.boardVersion);
252
252
  const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication), previous?.bleVersion);
253
- const deviceId = firstValue(info?.hw?.device_id, previous?.deviceId) ?? null;
254
253
  const serialNo = firstValue(info?.hw?.serial_no, previous?.serialNo) ?? '';
255
254
  const label = firstValue(deviceInfo?.status?.label, previous?.label) ?? null;
256
255
  const bleName = firstValue(info?.coprocessor?.bt_adv_name, info?.bt?.adv_name, previous?.bleName);
@@ -269,7 +268,7 @@ export const buildProtocolV2FeaturesPayload = (
269
268
  firmwareType: previous?.firmwareType ?? EFirmwareType.Universal,
270
269
  model: 'pro2',
271
270
  vendor: 'onekey.so',
272
- deviceId,
271
+ deviceId: null,
273
272
  serialNo,
274
273
  label,
275
274
  bleName: bleName ?? null,
@@ -304,7 +304,6 @@ export function buildProfileFromProtocolV2({
304
304
  scope = 'basic',
305
305
  includeRaw = false,
306
306
  }: BuildProtocolV2ProfileParams): DeviceProfile {
307
- const deviceId = deviceInfo?.hw?.device_id || '';
308
307
  const serialNo = deviceInfo?.hw?.serial_no || '';
309
308
  const label = deviceInfo?.status?.label ?? null;
310
309
  const bleName = deviceInfo?.bt?.adv_name ?? null;
@@ -315,7 +314,9 @@ export function buildProfileFromProtocolV2({
315
314
  sources,
316
315
  deviceType: EDeviceType.Pro2,
317
316
  firmwareType: EFirmwareType.Universal,
318
- deviceId,
317
+ // Protocol V2 的 DevGetDeviceInfo 没有 device_id 字段;serialNo 与 deviceId
318
+ // 不是等价语义,这里保持空值,避免把稳定硬件序列号误当会随 wipe 轮换的身份。
319
+ deviceId: '',
319
320
  serialNo,
320
321
  label,
321
322
  bleName,
@@ -1,6 +1,6 @@
1
1
  import { DevSEState, DevSeType } from '@onekeyfe/hd-transport';
2
2
 
3
- import type { DevGetDeviceInfo, DevSEInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
3
+ import type { DeviceGetDeviceInfo, DevSEInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
4
4
  import type { DeviceCommands } from '../../device/DeviceCommands';
5
5
 
6
6
  // 单源类型:直接使用 hd-transport 生成的 ProtocolV2DeviceInfo / DevSEInfo /
@@ -121,16 +121,15 @@ export const PROTOCOL_V2_DEVICE_INFO_REQUEST = PROTOCOL_V2_FULL_DEVICE_INFO_REQU
121
121
  export const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
122
122
 
123
123
  /**
124
- * 临时开关(默认关闭):当前正式链路直接调用 DevGetDeviceInfo
125
- * 仅当 Pro2 测试固件 / 早期工程板尚未实现 DevGetDeviceInfo 时,才显式开启 mock。
126
- * 开启时跳过 wire 调用,直接返回 mock DeviceInfo;
124
+ * 临时开关(默认开启):当前 Pro2 测试固件 / 早期工程板尚未实现 DevGetDeviceInfo
125
+ * 真实调用只会超时失败。开启时跳过 wire 调用,直接返回 mock DeviceInfo;
127
126
  * DevGetDeviceInfo 尚未返回的字段保持为空,不再用 transport path 兜底成设备身份。
128
127
  *
129
- * 固件实现 DevGetDeviceInfo 稳定后:删除开关与 mock
128
+ * 固件实现 DevGetDeviceInfo 后:把默认值改回 false(或直接删除开关与 mock)。
130
129
  * 注意:开启期间 FirmwareUpdateV4 的“升级完成版本比对”拿到的也是 mock 版本,
131
130
  * 不能作为升级成功的依据。
132
131
  */
133
- let protocolV2DeviceInfoMockEnabled = false;
132
+ let protocolV2DeviceInfoMockEnabled = true;
134
133
 
135
134
  export const setProtocolV2DeviceInfoMock = (enabled: boolean) => {
136
135
  protocolV2DeviceInfoMockEnabled = enabled;
@@ -164,9 +163,9 @@ export async function requestProtocolV2DeviceInfo({
164
163
  }: {
165
164
  commands: DeviceCommands;
166
165
  timeoutMs?: number;
167
- request?: DevGetDeviceInfo;
166
+ request?: DeviceGetDeviceInfo;
168
167
  }): Promise<ProtocolV2DeviceInfo> {
169
- if (isProtocolV2DeviceInfoMockEnabled()) {
168
+ if (protocolV2DeviceInfoMockEnabled) {
170
169
  return buildMockProtocolV2DeviceInfo();
171
170
  }
172
171
  const { message } = await commands.typedCall('DevGetDeviceInfo', 'DeviceInfo', request, {
@@ -1,10 +1,10 @@
1
1
  import type { CommonParams, Response } from '../params';
2
2
 
3
3
  export type GetPassphraseStatePayload = {
4
- passphraseState?: string;
5
- sessionId?: string;
6
- unlockedAttachPin?: boolean;
7
- passphraseProtection?: boolean | null;
4
+ passphrase_state?: string;
5
+ session_id?: string;
6
+ unlocked_attach_pin?: boolean;
7
+ passphrase_protection?: boolean | null;
8
8
  };
9
9
 
10
10
  export type GetPassphraseStateParams = CommonParams & {
@@ -1,5 +1,6 @@
1
1
  import type { CommonParams, Response } from '../params';
2
2
  import type {
3
+ DeviceFirmwareUpdateStatus,
3
4
  DevFirmwareUpdateStatus,
4
5
  FactoryDeviceInfo,
5
6
  OnboardingStatus,
@@ -95,12 +96,12 @@ export declare function deviceGetOnboardingStatus(
95
96
  export declare function deviceFirmwareUpdate(
96
97
  connectId: string,
97
98
  params: CommonParams & DeviceFirmwareUpdateParams
98
- ): Response<Success | DevFirmwareUpdateStatus>;
99
+ ): Response<Success | DevFirmwareUpdateStatus | DeviceFirmwareUpdateStatus>;
99
100
 
100
101
  export declare function deviceGetFirmwareUpdateStatus(
101
102
  connectId: string,
102
103
  params?: CommonParams
103
- ): Response<DevFirmwareUpdateStatus>;
104
+ ): Response<DevFirmwareUpdateStatus | DeviceFirmwareUpdateStatus>;
104
105
 
105
106
  export declare function devReboot(
106
107
  connectId: string,
@@ -34,11 +34,6 @@ export type ConnectSettings = {
34
34
  fetchConfig?: boolean;
35
35
  extension?: string;
36
36
  configFetcher?: (url: string) => Promise<RemoteConfigResponse | null>;
37
- /**
38
- * 临时开关:Protocol V2 DevGetDeviceInfo 未稳定前用于 mock 设备信息。
39
- * 正式 app 可显式设置为 false 以调用真实 DevGetDeviceInfo;固件稳定后删除。
40
- */
41
- protocolV2DeviceInfoMockEnabled?: boolean;
42
37
  };
43
38
 
44
39
  export type IVersionArray = [number, number, number];