@onekeyfe/hd-core 1.2.0-alpha.112 → 1.2.0-alpha.113
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.
- package/__tests__/DeviceCommands.test.ts +2 -2
- package/__tests__/device-lifecycle-events.test.ts +1 -1
- package/__tests__/device-state-mapper.test.ts +4 -4
- package/__tests__/device-utils.test.ts +1 -1
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +116 -0
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +89 -36
- package/__tests__/get-device-state.test.ts +8 -8
- package/__tests__/protocol-v2-resources.test.ts +0 -20
- package/__tests__/protocol-v2.test.ts +240 -219
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +3 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/index.d.ts +20 -5
- package/dist/index.js +230 -140
- package/dist/protocols/protocol-v2/features.d.ts +4 -4
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/types/settings.d.ts +19 -4
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV3.ts +29 -19
- package/src/api/FirmwareUpdateV4.ts +178 -85
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
- package/src/api/protocol-v2/DeviceInfoGet.ts +3 -3
- package/src/data/messages/messages-protocol-v2.json +14 -31
- package/src/device/DeviceStateMapper.ts +15 -15
- package/src/deviceProfile/buildDeviceFeatures.ts +3 -3
- package/src/protocols/protocol-v2/features.ts +6 -6
- package/src/protocols/protocol-v2/resources.ts +49 -10
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -1
- package/src/types/settings.ts +19 -4
|
@@ -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?.
|
|
108
|
-
if (deviceInfo?.
|
|
109
|
-
if (deviceInfo?.
|
|
107
|
+
if (isLegacyProtocolV2ProtocolInfo(protocolInfo) && !deviceInfo?.fw?.application) {
|
|
108
|
+
if (deviceInfo?.fw?.romloader) return 'romloader';
|
|
109
|
+
if (deviceInfo?.fw?.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
|
-
|
|
125
|
+
fw: 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
|
-
|
|
141
|
+
fw: 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
|
-
|
|
157
|
+
fw: 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 =
|
|
111
|
-
file.original_name
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
const originalName = assertManifestRelativePath(
|
|
111
|
+
file.original_name,
|
|
112
|
+
`files[${index}].original_name`
|
|
113
|
+
);
|
|
114
114
|
if (originalName.includes('/')) {
|
|
115
115
|
throw new Error(`Invalid Pro2 resource manifest files[${index}].original_name`);
|
|
116
116
|
}
|
|
@@ -122,6 +122,15 @@ 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
|
+
}
|
|
125
134
|
if (!archivePath.endsWith('.okpkg') || !originalName.endsWith('.okpkg')) {
|
|
126
135
|
throw new Error(`Invalid Pro2 resource manifest files[${index}] package extension`);
|
|
127
136
|
}
|
|
@@ -131,9 +140,9 @@ function parseProtocolV2ResourceManifestFile(
|
|
|
131
140
|
device_path: devicePath,
|
|
132
141
|
size: Number(file.size),
|
|
133
142
|
sha256: digest,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
signed: true,
|
|
144
|
+
sig_algo: file.sig_algo,
|
|
145
|
+
payload_version: file.payload_version ?? null,
|
|
137
146
|
};
|
|
138
147
|
}
|
|
139
148
|
|
|
@@ -142,8 +151,15 @@ export function parseProtocolV2ResourceManifest(value: unknown): IProtocolV2Reso
|
|
|
142
151
|
throw new Error('Invalid Pro2 resource manifest');
|
|
143
152
|
}
|
|
144
153
|
const manifest = value as Partial<IProtocolV2ResourceManifest>;
|
|
145
|
-
if (
|
|
146
|
-
|
|
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');
|
|
147
163
|
}
|
|
148
164
|
const files = manifest.files.map(parseProtocolV2ResourceManifestFile);
|
|
149
165
|
const devicePaths = new Set(files.map(file => file.device_path));
|
|
@@ -151,11 +167,34 @@ export function parseProtocolV2ResourceManifest(value: unknown): IProtocolV2Reso
|
|
|
151
167
|
if (
|
|
152
168
|
files.length === 0 ||
|
|
153
169
|
devicePaths.size !== files.length ||
|
|
154
|
-
archivePaths.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/'))
|
|
155
173
|
) {
|
|
156
174
|
throw new Error('Invalid Pro2 resource manifest file set');
|
|
157
175
|
}
|
|
158
176
|
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
|
+
}),
|
|
159
198
|
files,
|
|
160
199
|
};
|
|
161
200
|
}
|
|
@@ -80,7 +80,6 @@ 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 &&
|
|
84
83
|
!device.isBootloader?.() &&
|
|
85
84
|
!device.isRomloader?.();
|
|
86
85
|
|
package/src/types/settings.ts
CHANGED
|
@@ -76,16 +76,31 @@ export type IProtocolV2Resources = {
|
|
|
76
76
|
|
|
77
77
|
export type IProtocolV2ResourceManifestFile = {
|
|
78
78
|
archive_path: string;
|
|
79
|
-
original_name
|
|
79
|
+
original_name: string;
|
|
80
80
|
device_path: string;
|
|
81
81
|
size: number;
|
|
82
82
|
sha256: string;
|
|
83
|
-
signed
|
|
84
|
-
sig_algo
|
|
85
|
-
payload_version
|
|
83
|
+
signed: true;
|
|
84
|
+
sig_algo: 'ed25519' | 'mldsa65';
|
|
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
|
+
}>;
|
|
89
104
|
files: IProtocolV2ResourceManifestFile[];
|
|
90
105
|
};
|
|
91
106
|
|