@onekeyfe/hd-core 1.2.0-alpha.110 → 1.2.0-alpha.112

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 (35) hide show
  1. package/__tests__/DeviceCommands.test.ts +2 -2
  2. package/__tests__/device-lifecycle-events.test.ts +1 -1
  3. package/__tests__/device-state-mapper.test.ts +4 -4
  4. package/__tests__/device-utils.test.ts +1 -1
  5. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +0 -54
  6. package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +36 -89
  7. package/__tests__/get-device-state.test.ts +8 -8
  8. package/__tests__/protocol-v2-resources.test.ts +20 -0
  9. package/__tests__/protocol-v2.test.ts +219 -240
  10. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  11. package/dist/api/FirmwareUpdateV4.d.ts +0 -3
  12. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  13. package/dist/api/protocol-v2/DeviceInfoGet.d.ts +1 -1
  14. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
  15. package/dist/index.d.ts +5 -20
  16. package/dist/index.js +139 -226
  17. package/dist/protocols/protocol-v2/features.d.ts +4 -4
  18. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  19. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
  20. package/dist/types/settings.d.ts +4 -19
  21. package/dist/types/settings.d.ts.map +1 -1
  22. package/dist/utils/patch.d.ts +1 -1
  23. package/dist/utils/patch.d.ts.map +1 -1
  24. package/package.json +4 -4
  25. package/src/api/FirmwareUpdateV3.ts +16 -23
  26. package/src/api/FirmwareUpdateV4.ts +85 -178
  27. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
  28. package/src/api/protocol-v2/DeviceInfoGet.ts +3 -3
  29. package/src/data/messages/messages-protocol-v2.json +31 -14
  30. package/src/device/DeviceStateMapper.ts +15 -15
  31. package/src/deviceProfile/buildDeviceFeatures.ts +3 -3
  32. package/src/protocols/protocol-v2/features.ts +6 -6
  33. package/src/protocols/protocol-v2/resources.ts +10 -49
  34. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +1 -0
  35. package/src/types/settings.ts +4 -19
@@ -104,9 +104,9 @@ export const getProtocolV2RuntimeMode = (
104
104
  if (binary === 'application') return 'normal';
105
105
  if (binary) return binary;
106
106
 
107
- if (isLegacyProtocolV2ProtocolInfo(protocolInfo) && !deviceInfo?.fw?.application) {
108
- if (deviceInfo?.fw?.romloader) return 'romloader';
109
- if (deviceInfo?.fw?.bootloader) return 'bootloader';
107
+ if (isLegacyProtocolV2ProtocolInfo(protocolInfo) && !deviceInfo?.main_mcu?.application) {
108
+ if (deviceInfo?.main_mcu?.romloader) return 'romloader';
109
+ if (deviceInfo?.main_mcu?.bootloader) return 'bootloader';
110
110
  }
111
111
  return undefined;
112
112
  };
@@ -122,7 +122,7 @@ export const supportsProtocolV2Message = (
122
122
  export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
123
123
  targets: {
124
124
  hw: true,
125
- fw: true,
125
+ main_mcu: true,
126
126
  coprocessor: true,
127
127
  },
128
128
  types: {
@@ -138,7 +138,7 @@ export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
138
138
  export const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
139
139
  targets: {
140
140
  hw: true,
141
- fw: true,
141
+ main_mcu: true,
142
142
  coprocessor: true,
143
143
  se1: true,
144
144
  se2: true,
@@ -154,7 +154,7 @@ export const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
154
154
  export const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
155
155
  targets: {
156
156
  hw: true,
157
- fw: true,
157
+ main_mcu: true,
158
158
  coprocessor: true,
159
159
  se1: true,
160
160
  se2: true,
@@ -107,10 +107,10 @@ function parseProtocolV2ResourceManifestFile(
107
107
  }
108
108
  const file = value as Partial<IProtocolV2ResourceManifestFile>;
109
109
  const archivePath = assertManifestRelativePath(file.archive_path, `files[${index}].archive_path`);
110
- const originalName = assertManifestRelativePath(
111
- file.original_name,
112
- `files[${index}].original_name`
113
- );
110
+ const originalName =
111
+ file.original_name === undefined
112
+ ? archivePath.split('/').pop() ?? archivePath
113
+ : assertManifestRelativePath(file.original_name, `files[${index}].original_name`);
114
114
  if (originalName.includes('/')) {
115
115
  throw new Error(`Invalid Pro2 resource manifest files[${index}].original_name`);
116
116
  }
@@ -122,15 +122,6 @@ function parseProtocolV2ResourceManifestFile(
122
122
  throw new Error(`Invalid Pro2 resource manifest files[${index}].size`);
123
123
  }
124
124
  const digest = normalizeHex(file.sha256, SHA256_HEX_LENGTH, `files[${index}].sha256`);
125
- if (file.signed !== true) {
126
- throw new Error(`Invalid Pro2 resource manifest files[${index}].signed`);
127
- }
128
- if (file.sig_algo !== 'ed25519' && file.sig_algo !== 'mldsa65') {
129
- throw new Error(`Invalid Pro2 resource manifest files[${index}].sig_algo`);
130
- }
131
- if (file.payload_version !== null && typeof file.payload_version !== 'string') {
132
- throw new Error(`Invalid Pro2 resource manifest files[${index}].payload_version`);
133
- }
134
125
  if (!archivePath.endsWith('.okpkg') || !originalName.endsWith('.okpkg')) {
135
126
  throw new Error(`Invalid Pro2 resource manifest files[${index}] package extension`);
136
127
  }
@@ -140,9 +131,9 @@ function parseProtocolV2ResourceManifestFile(
140
131
  device_path: devicePath,
141
132
  size: Number(file.size),
142
133
  sha256: digest,
143
- signed: true,
144
- sig_algo: file.sig_algo,
145
- payload_version: file.payload_version ?? null,
134
+ ...(file.signed === undefined ? {} : { signed: file.signed }),
135
+ ...(file.sig_algo === undefined ? {} : { sig_algo: file.sig_algo }),
136
+ ...(file.payload_version === undefined ? {} : { payload_version: file.payload_version }),
146
137
  };
147
138
  }
148
139
 
@@ -151,15 +142,8 @@ export function parseProtocolV2ResourceManifest(value: unknown): IProtocolV2Reso
151
142
  throw new Error('Invalid Pro2 resource manifest');
152
143
  }
153
144
  const manifest = value as Partial<IProtocolV2ResourceManifest>;
154
- if (
155
- manifest.schema !== 1 ||
156
- manifest.variant !== 'resource' ||
157
- manifest.device_root !== 'vol0:' ||
158
- manifest.restore_mode !== 'bootloader_update' ||
159
- !Array.isArray(manifest.trees) ||
160
- !Array.isArray(manifest.files)
161
- ) {
162
- throw new Error('Invalid Pro2 resource manifest contract');
145
+ if (!Array.isArray(manifest.files)) {
146
+ throw new Error('Invalid Pro2 resource manifest files');
163
147
  }
164
148
  const files = manifest.files.map(parseProtocolV2ResourceManifestFile);
165
149
  const devicePaths = new Set(files.map(file => file.device_path));
@@ -167,34 +151,11 @@ export function parseProtocolV2ResourceManifest(value: unknown): IProtocolV2Reso
167
151
  if (
168
152
  files.length === 0 ||
169
153
  devicePaths.size !== files.length ||
170
- archivePaths.size !== files.length ||
171
- !devicePaths.has(PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH) ||
172
- !files.some(file => file.device_path.startsWith('vol0:/bundles/'))
154
+ archivePaths.size !== files.length
173
155
  ) {
174
156
  throw new Error('Invalid Pro2 resource manifest file set');
175
157
  }
176
158
  return {
177
- schema: 1,
178
- artifact_name: assertManifestString(manifest.artifact_name, 'artifact_name'),
179
- release_name: assertManifestString(manifest.release_name, 'release_name'),
180
- variant: 'resource',
181
- commit: assertManifestString(manifest.commit, 'commit'),
182
- short_sha: assertManifestString(manifest.short_sha, 'short_sha'),
183
- timestamp_utc: assertManifestString(manifest.timestamp_utc, 'timestamp_utc'),
184
- core_version: assertManifestString(manifest.core_version, 'core_version'),
185
- key_set: assertManifestString(manifest.key_set, 'key_set'),
186
- device_root: 'vol0:',
187
- restore_mode: 'bootloader_update',
188
- trees: manifest.trees.map((tree, index) => {
189
- if (!tree || typeof tree !== 'object') {
190
- throw new Error(`Invalid Pro2 resource manifest trees[${index}]`);
191
- }
192
- const item = tree as { path?: unknown; device?: unknown };
193
- return {
194
- path: assertManifestRelativePath(item.path, `trees[${index}].path`),
195
- device: assertManifestString(item.device, `trees[${index}].device`),
196
- };
197
- }),
198
159
  files,
199
160
  };
200
161
  }
@@ -80,6 +80,7 @@ export async function runMethodWithUnlockPolicy<T = unknown>(
80
80
  const requiresPreUnlock =
81
81
  device.isProtocolV2() &&
82
82
  (method.useDevicePassphraseState || method.unlockPolicy === 'unlock-before-run') &&
83
+ device.state?.status.initialized !== false &&
83
84
  !device.isBootloader?.() &&
84
85
  !device.isRomloader?.();
85
86
 
@@ -76,31 +76,16 @@ export type IProtocolV2Resources = {
76
76
 
77
77
  export type IProtocolV2ResourceManifestFile = {
78
78
  archive_path: string;
79
- original_name: string;
79
+ original_name?: string;
80
80
  device_path: string;
81
81
  size: number;
82
82
  sha256: string;
83
- signed: true;
84
- sig_algo: 'ed25519' | 'mldsa65';
85
- payload_version: string | null;
83
+ signed?: boolean;
84
+ sig_algo?: string;
85
+ payload_version?: string | null;
86
86
  };
87
87
 
88
88
  export type IProtocolV2ResourceManifest = {
89
- schema: 1;
90
- artifact_name: string;
91
- release_name: string;
92
- variant: 'resource';
93
- commit: string;
94
- short_sha: string;
95
- timestamp_utc: string;
96
- core_version: string;
97
- key_set: string;
98
- device_root: 'vol0:';
99
- restore_mode: 'bootloader_update';
100
- trees: Array<{
101
- path: string;
102
- device: string;
103
- }>;
104
89
  files: IProtocolV2ResourceManifestFile[];
105
90
  };
106
91