@onekeyfe/hd-core 1.2.0-alpha.157 → 1.2.0-alpha.159
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__/device-utils.test.ts +2 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +1 -4
- package/__tests__/protocol-v2-resources.test.ts +1 -3
- package/__tests__/protocol-v2.test.ts +80 -37
- package/dist/api/FirmwareUpdateV4.d.ts +3 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -15
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/index.d.ts +2 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -234
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +76 -185
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -41
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +2 -0
- package/src/data-manager/TransportManager.ts +3 -1
- package/src/index.ts +0 -6
- package/src/types/api/firmwareUpdate.ts +1 -1
- package/src/utils/deviceInfoUtils.ts +3 -1
- package/__tests__/firmware-memory-host.test.ts +0 -126
- package/dist/api/firmware/FirmwareMemoryHost.d.ts +0 -22
- package/dist/api/firmware/FirmwareMemoryHost.d.ts.map +0 -1
- package/src/api/firmware/FirmwareMemoryHost.ts +0 -143
package/dist/index.js
CHANGED
|
@@ -468,7 +468,7 @@ const getDeviceTypeByBleName = (name) => {
|
|
|
468
468
|
if (/^Touch/i.test(name))
|
|
469
469
|
return hdShared.EDeviceType.Touch;
|
|
470
470
|
const compactName = name.replace(/[\s-]/g, '');
|
|
471
|
-
if (/\bPro\s*2\b/i.test(name) || /^
|
|
471
|
+
if (/\bPro\s*2\b/i.test(name) || /^(?:OneKey)?Pro2[a-f0-9]{4}$/i.test(compactName)) {
|
|
472
472
|
return hdShared.EDeviceType.Pro2;
|
|
473
473
|
}
|
|
474
474
|
if (/\bNeo\b/i.test(name) || /^Neo/i.test(name) || /^(?:OneKey)?Neo/i.test(compactName)) {
|
|
@@ -930,22 +930,6 @@ const finalizeFirmwareUpdatePlan = ({ features, firmwareType, platform, artifact
|
|
|
930
930
|
};
|
|
931
931
|
return assertFirmwareUpdatePlan(Object.assign(Object.assign({}, planWithoutDigest), { planDigest: digestFirmwareUpdatePlan(planWithoutDigest) }));
|
|
932
932
|
};
|
|
933
|
-
const buildProtocolV2LocalFirmwareUpdatePlan = ({ features, firmwareType, platform, artifacts, }) => {
|
|
934
|
-
if (artifacts.length === 0) {
|
|
935
|
-
return planError('Protocol V2 local firmware plan has no artifacts');
|
|
936
|
-
}
|
|
937
|
-
const plan = finalizeFirmwareUpdatePlan({
|
|
938
|
-
features,
|
|
939
|
-
firmwareType,
|
|
940
|
-
platform,
|
|
941
|
-
artifacts: artifacts.map(artifact => (Object.assign(Object.assign({}, artifact), { role: artifact.target === 'resource' ? 'resourceBundle' : 'component', url: `https://local-firmware.invalid/${encodeURIComponent(artifact.artifactId)}` }))),
|
|
942
|
-
targetsToUpdate: artifacts.map(artifact => artifact.target),
|
|
943
|
-
});
|
|
944
|
-
if (plan.executor !== 'v4') {
|
|
945
|
-
return planError('Protocol V2 local firmware plan requires executor v4');
|
|
946
|
-
}
|
|
947
|
-
return plan;
|
|
948
|
-
};
|
|
949
933
|
const buildProtocolV2FirmwareUpdatePlan = ({ features, firmwareType, platform, release, targetsToUpdate, forceUpdateTargets, resourceArchive, }) => {
|
|
950
934
|
const validatedForceTargets = validateFirmwareUpdatePlanForceTargets(forceUpdateTargets);
|
|
951
935
|
if (validatedForceTargets.some(target => target === 'ble' || target === 'bootloader')) {
|
|
@@ -43430,7 +43414,7 @@ class TransportManager {
|
|
|
43430
43414
|
yield this.transport.init(WebBleLogger, DevicePool.emitter);
|
|
43431
43415
|
}
|
|
43432
43416
|
else if (env === 'webusb' || env === 'desktop-webusb') {
|
|
43433
|
-
yield this.transport.init(WebUsbLogger);
|
|
43417
|
+
yield this.transport.init(WebUsbLogger, DevicePool.emitter);
|
|
43434
43418
|
}
|
|
43435
43419
|
else {
|
|
43436
43420
|
yield this.transport.init(HttpLogger);
|
|
@@ -51719,86 +51703,6 @@ const INSTALLABLE_FIRMWARE_TARGET_IDS = new Set([
|
|
|
51719
51703
|
]);
|
|
51720
51704
|
new Map(Object.entries(ProtocolV2FirmwareTargetType).flatMap(([key, value]) => INSTALLABLE_FIRMWARE_TARGET_IDS.has(value) ? [[key, value]] : []));
|
|
51721
51705
|
|
|
51722
|
-
let memoryHostSequence = 0;
|
|
51723
|
-
const createReference = (binary, prefix) => {
|
|
51724
|
-
const digest = utils.bytesToHex(sha256.sha256(new Uint8Array(binary)));
|
|
51725
|
-
return {
|
|
51726
|
-
artifactRef: `fwmem:${prefix}:${digest.slice(0, 32)}`,
|
|
51727
|
-
size: binary.byteLength,
|
|
51728
|
-
sha256: digest,
|
|
51729
|
-
};
|
|
51730
|
-
};
|
|
51731
|
-
function prepareFirmwareUpdateV4MemoryHost({ sdk, plan, artifacts, }) {
|
|
51732
|
-
if (plan.executor !== 'v4') {
|
|
51733
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Firmware memory host only supports V4 plans');
|
|
51734
|
-
}
|
|
51735
|
-
memoryHostSequence += 1;
|
|
51736
|
-
const hostId = `${Date.now()}:${memoryHostSequence}`;
|
|
51737
|
-
const binaries = new Map();
|
|
51738
|
-
const inputs = artifacts.map((input, artifactIndex) => {
|
|
51739
|
-
var _a;
|
|
51740
|
-
const artifactBinary = new Uint8Array(input.binary).slice();
|
|
51741
|
-
const artifact = createReference(artifactBinary.buffer, `${hostId}:artifact:${artifactIndex}`);
|
|
51742
|
-
binaries.set(artifact.artifactRef, artifactBinary);
|
|
51743
|
-
const materializedEntries = (_a = input.materializedEntries) === null || _a === void 0 ? void 0 : _a.map((entry, entryIndex) => {
|
|
51744
|
-
const entryArtifact = createReference(entry.binary, `${hostId}:entry:${artifactIndex}:${entryIndex}`);
|
|
51745
|
-
return {
|
|
51746
|
-
entryName: entry.entryName,
|
|
51747
|
-
artifact: entryArtifact,
|
|
51748
|
-
};
|
|
51749
|
-
});
|
|
51750
|
-
return Object.assign({ artifactId: input.artifactId, artifact }, ((materializedEntries === null || materializedEntries === void 0 ? void 0 : materializedEntries.length) ? { materializedEntries } : {}));
|
|
51751
|
-
});
|
|
51752
|
-
const preparedPlan = sdk.prepareFirmwareUpdatePlan({
|
|
51753
|
-
plan,
|
|
51754
|
-
leaseRef: `fwmemlease:${hostId}`,
|
|
51755
|
-
artifacts: inputs,
|
|
51756
|
-
});
|
|
51757
|
-
const readers = new Map();
|
|
51758
|
-
let readerSequence = 0;
|
|
51759
|
-
const artifactReader = {
|
|
51760
|
-
open({ artifactRef }) {
|
|
51761
|
-
const binary = binaries.get(artifactRef);
|
|
51762
|
-
if (!binary) {
|
|
51763
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Firmware memory artifact is unavailable');
|
|
51764
|
-
}
|
|
51765
|
-
readerSequence += 1;
|
|
51766
|
-
const readerId = `fwmemreader:${hostId}:${readerSequence}`;
|
|
51767
|
-
readers.set(readerId, binary);
|
|
51768
|
-
return Promise.resolve({ readerId, size: binary.byteLength });
|
|
51769
|
-
},
|
|
51770
|
-
read({ readerId, offset, length }) {
|
|
51771
|
-
const binary = readers.get(readerId);
|
|
51772
|
-
if (!binary || offset < 0 || length <= 0 || offset + length > binary.byteLength) {
|
|
51773
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Firmware memory artifact read is invalid');
|
|
51774
|
-
}
|
|
51775
|
-
const data = binary.slice(offset, offset + length).buffer;
|
|
51776
|
-
return Promise.resolve({
|
|
51777
|
-
data,
|
|
51778
|
-
bytesRead: data.byteLength,
|
|
51779
|
-
eof: offset + length === binary.byteLength,
|
|
51780
|
-
});
|
|
51781
|
-
},
|
|
51782
|
-
close({ readerId }) {
|
|
51783
|
-
readers.delete(readerId);
|
|
51784
|
-
return Promise.resolve();
|
|
51785
|
-
},
|
|
51786
|
-
};
|
|
51787
|
-
const hostBindingGeneration = sdk.registerFirmwareUpdateHostBinding({
|
|
51788
|
-
artifactReader,
|
|
51789
|
-
preparedPlanDigest: preparedPlan.preparedPlanDigest,
|
|
51790
|
-
});
|
|
51791
|
-
return {
|
|
51792
|
-
preparedPlan,
|
|
51793
|
-
hostBindingGeneration,
|
|
51794
|
-
release: () => {
|
|
51795
|
-
sdk.unregisterFirmwareUpdateHostBinding(hostBindingGeneration);
|
|
51796
|
-
readers.clear();
|
|
51797
|
-
binaries.clear();
|
|
51798
|
-
},
|
|
51799
|
-
};
|
|
51800
|
-
}
|
|
51801
|
-
|
|
51802
51706
|
const Log$7 = getLogger(exports.LoggerNames.Method);
|
|
51803
51707
|
const SESSION_ERROR$1 = 'session not found';
|
|
51804
51708
|
const PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT = 90 * 1000;
|
|
@@ -51918,12 +51822,8 @@ const PROTOCOL_V2_REMOTE_COMPONENT_TARGETS = {
|
|
|
51918
51822
|
},
|
|
51919
51823
|
};
|
|
51920
51824
|
const PROTOCOL_V2_FIRMWARE_STAGING_PATHS = new Set(Object.values(PROTOCOL_V2_REMOTE_COMPONENT_TARGETS).map(target => `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}${target.fileName}`));
|
|
51921
|
-
const isProtocolV2BootResourcePackagePath = (devicePath) =>
|
|
51922
|
-
|
|
51923
|
-
return false;
|
|
51924
|
-
const normalized = devicePath.toLowerCase();
|
|
51925
|
-
return (normalized.startsWith('vol0:/loaders/bootloader/') && normalized.endsWith('.okpkg.staging'));
|
|
51926
|
-
};
|
|
51825
|
+
const isProtocolV2BootResourcePackagePath = (devicePath) => typeof devicePath === 'string' &&
|
|
51826
|
+
devicePath.toLowerCase() === PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH;
|
|
51927
51827
|
const PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID = new Map([
|
|
51928
51828
|
[ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER, 'boot'],
|
|
51929
51829
|
[ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1, 'app_v1'],
|
|
@@ -52271,16 +52171,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52271
52171
|
if (!this.params.preparedPlan &&
|
|
52272
52172
|
this.params.resourceArchiveBinary &&
|
|
52273
52173
|
((_c = this.params.targetsToUpdate) === null || _c === void 0 ? void 0 : _c.includes('resource'))) {
|
|
52274
|
-
|
|
52275
|
-
features: deviceFeatures,
|
|
52276
|
-
firmwareType,
|
|
52277
|
-
});
|
|
52278
|
-
try {
|
|
52279
|
-
return yield this.runProtocolV2PreparedArtifacts(deviceFeatures, firmwareType);
|
|
52280
|
-
}
|
|
52281
|
-
finally {
|
|
52282
|
-
localMemoryHost.release();
|
|
52283
|
-
}
|
|
52174
|
+
return this.runProtocolV2DirectArtifacts({});
|
|
52284
52175
|
}
|
|
52285
52176
|
const hasPreparedComponentArtifacts = Object.values((_d = this.params.componentArtifacts) !== null && _d !== void 0 ? _d : {}).some(Boolean);
|
|
52286
52177
|
if (this.params.preparedPlan || hasPreparedComponentArtifacts) {
|
|
@@ -52289,12 +52180,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52289
52180
|
let fwBinaryMap = [];
|
|
52290
52181
|
let bootloaderBinary = null;
|
|
52291
52182
|
let installItems;
|
|
52292
|
-
let
|
|
52183
|
+
let explicitInstallItems;
|
|
52293
52184
|
try {
|
|
52294
52185
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
52295
52186
|
fwBinaryMap = this.collectExplicitTargetBinaries();
|
|
52296
52187
|
bootloaderBinary = this.prepareBootloaderBinary();
|
|
52297
|
-
|
|
52188
|
+
explicitInstallItems = this.buildProtocolV2InstallItems({
|
|
52298
52189
|
bootloaderBinary,
|
|
52299
52190
|
fwBinaryMap,
|
|
52300
52191
|
});
|
|
@@ -52336,16 +52227,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52336
52227
|
}
|
|
52337
52228
|
if (wantsResources) {
|
|
52338
52229
|
this.params.resourceArchiveBinary = yield this.downloadRemoteProtocolV2ResourceArchive(deviceFeatures, firmwareType);
|
|
52339
|
-
resourceMemoryHost = yield this.prepareProtocolV2LocalMemoryHost({
|
|
52340
|
-
features: deviceFeatures,
|
|
52341
|
-
firmwareType,
|
|
52342
|
-
availableInstallItems: installItems !== null && installItems !== void 0 ? installItems : explicitInstallItems,
|
|
52343
|
-
});
|
|
52344
52230
|
}
|
|
52345
52231
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
52346
52232
|
}
|
|
52347
52233
|
catch (err) {
|
|
52348
|
-
resourceMemoryHost === null || resourceMemoryHost === void 0 ? void 0 : resourceMemoryHost.release();
|
|
52349
52234
|
if (typeof err === 'object' &&
|
|
52350
52235
|
err !== null &&
|
|
52351
52236
|
'params' in err &&
|
|
@@ -52357,13 +52242,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52357
52242
|
}
|
|
52358
52243
|
throw normalizeFirmwarePreparationError(err);
|
|
52359
52244
|
}
|
|
52360
|
-
if (
|
|
52361
|
-
|
|
52362
|
-
|
|
52363
|
-
|
|
52364
|
-
|
|
52365
|
-
resourceMemoryHost.release();
|
|
52366
|
-
}
|
|
52245
|
+
if (wantsResources && this.params.resourceArchiveBinary) {
|
|
52246
|
+
return this.runProtocolV2DirectArtifacts({
|
|
52247
|
+
availableInstallItems: installItems !== null && installItems !== void 0 ? installItems : explicitInstallItems,
|
|
52248
|
+
announceDownload: false,
|
|
52249
|
+
});
|
|
52367
52250
|
}
|
|
52368
52251
|
if (!bootloaderBinary && fwBinaryMap.length === 0 && !(installItems === null || installItems === void 0 ? void 0 : installItems.length)) {
|
|
52369
52252
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, 'No firmware to update');
|
|
@@ -52464,95 +52347,59 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52464
52347
|
return installSources;
|
|
52465
52348
|
});
|
|
52466
52349
|
}
|
|
52467
|
-
|
|
52468
|
-
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
52469
|
-
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
52470
|
-
}), }) {
|
|
52471
|
-
var _a, _b;
|
|
52350
|
+
runProtocolV2DirectArtifacts({ availableInstallItems, announceDownload = true, }) {
|
|
52472
52351
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52473
|
-
|
|
52474
|
-
|
|
52475
|
-
|
|
52476
|
-
|
|
52477
|
-
|
|
52478
|
-
|
|
52479
|
-
|
|
52480
|
-
|
|
52481
|
-
|
|
52482
|
-
|
|
52352
|
+
try {
|
|
52353
|
+
if (announceDownload) {
|
|
52354
|
+
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
52355
|
+
}
|
|
52356
|
+
const installItems = this.filterProtocolV2LocalInstallItems(availableInstallItems !== null && availableInstallItems !== void 0 ? availableInstallItems : this.buildProtocolV2InstallItems({
|
|
52357
|
+
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
52358
|
+
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
52359
|
+
}));
|
|
52360
|
+
const installSources = yield Promise.all(installItems.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
52361
|
+
return ({
|
|
52362
|
+
fileName: item.fileName,
|
|
52363
|
+
source: yield this.openProtocolV2MemorySource(item.binary),
|
|
52364
|
+
targetId: item.targetId,
|
|
52365
|
+
kind: item.kind,
|
|
52366
|
+
});
|
|
52367
|
+
})));
|
|
52368
|
+
const resourceSources = this.params.resourceArchiveBinary
|
|
52369
|
+
? yield this.createProtocolV2ResourceSourcesFromArchive(this.params.resourceArchiveBinary)
|
|
52370
|
+
: [];
|
|
52371
|
+
if (installSources.length === 0 && resourceSources.length === 0) {
|
|
52372
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, 'No firmware to update');
|
|
52373
|
+
}
|
|
52374
|
+
if (announceDownload) {
|
|
52375
|
+
this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
52376
|
+
}
|
|
52377
|
+
return yield this.executeProtocolV2SourceUpdate({
|
|
52378
|
+
installSources,
|
|
52379
|
+
resourceSources,
|
|
52483
52380
|
});
|
|
52484
52381
|
}
|
|
52485
|
-
|
|
52486
|
-
|
|
52487
|
-
const memoryArtifacts = [];
|
|
52488
|
-
for (const item of installItems) {
|
|
52489
|
-
const target = PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID.get(item.targetId);
|
|
52490
|
-
if (!target || item.binary.byteLength <= 0) {
|
|
52491
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local firmware artifact is invalid: ${item.fileName}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52492
|
-
}
|
|
52493
|
-
const artifactId = `component:${target}`;
|
|
52494
|
-
planArtifacts.push(Object.assign({ artifactId,
|
|
52495
|
-
target, container: 'raw', logicalName: item.fileName, expectedSize: item.binary.byteLength, expectedSha256: bytesToHex(sha256.sha256(new Uint8Array(item.binary))) }, (((_b = this.params.expectedTargetVersions) === null || _b === void 0 ? void 0 : _b[target])
|
|
52496
|
-
? { targetVersion: this.params.expectedTargetVersions[target] }
|
|
52497
|
-
: {})));
|
|
52498
|
-
memoryArtifacts.push({ artifactId, binary: item.binary });
|
|
52382
|
+
finally {
|
|
52383
|
+
yield this.closeProtocolV2PreparedSources();
|
|
52499
52384
|
}
|
|
52500
|
-
|
|
52501
|
-
|
|
52502
|
-
|
|
52503
|
-
|
|
52504
|
-
|
|
52505
|
-
|
|
52506
|
-
|
|
52507
|
-
|
|
52508
|
-
|
|
52509
|
-
|
|
52510
|
-
|
|
52511
|
-
|
|
52512
|
-
|
|
52513
|
-
|
|
52514
|
-
|
|
52515
|
-
const plan = buildProtocolV2LocalFirmwareUpdatePlan({
|
|
52516
|
-
features,
|
|
52517
|
-
firmwareType,
|
|
52518
|
-
platform: this.params.platform,
|
|
52519
|
-
artifacts: planArtifacts,
|
|
52520
|
-
});
|
|
52521
|
-
let memoryHost;
|
|
52522
|
-
try {
|
|
52523
|
-
memoryHost = prepareFirmwareUpdateV4MemoryHost({
|
|
52524
|
-
sdk: {
|
|
52525
|
-
prepareFirmwareUpdatePlan,
|
|
52526
|
-
registerFirmwareUpdateHostBinding,
|
|
52527
|
-
unregisterFirmwareUpdateHostBinding,
|
|
52528
|
-
},
|
|
52529
|
-
plan,
|
|
52530
|
-
artifacts: memoryArtifacts,
|
|
52531
|
-
});
|
|
52532
|
-
const preparedPlan = validateFirmwareUpdatePreparedPlan(memoryHost.preparedPlan);
|
|
52533
|
-
assertFirmwareUpdatePreparedPlanBinding({
|
|
52534
|
-
preparedPlan,
|
|
52535
|
-
executor: 'v4',
|
|
52536
|
-
platform: this.params.platform,
|
|
52537
|
-
scopeTargets: [],
|
|
52538
|
-
bindings: [],
|
|
52539
|
-
});
|
|
52540
|
-
assertFirmwareUpdatePreparedPlanDeviceIdentity({
|
|
52541
|
-
preparedPlan,
|
|
52542
|
-
deviceIdentity: this.protocolV2ExpectedSerialNumber,
|
|
52543
|
-
deviceModel: this.getProtocolV2PreparedPlanDeviceModel(features),
|
|
52385
|
+
});
|
|
52386
|
+
}
|
|
52387
|
+
createProtocolV2ResourceSourcesFromArchive(binary) {
|
|
52388
|
+
var _a;
|
|
52389
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52390
|
+
const archive = yield this.prepareProtocolV2LocalResourceArchive(binary);
|
|
52391
|
+
const sources = [];
|
|
52392
|
+
for (const resource of archive.resources) {
|
|
52393
|
+
sources.push({
|
|
52394
|
+
name: (_a = resource.entryName.split('/').pop()) !== null && _a !== void 0 ? _a : resource.entryName,
|
|
52395
|
+
source: yield this.openProtocolV2MemorySource(resource.binary),
|
|
52396
|
+
devicePath: resource.header.devicePath,
|
|
52397
|
+
version: resource.header.version,
|
|
52398
|
+
payloadHash: resource.header.payloadHash,
|
|
52399
|
+
headerHash: resource.header.headerHash,
|
|
52544
52400
|
});
|
|
52545
|
-
const hostBinding = resolveFirmwareUpdateHostBinding(memoryHost.hostBindingGeneration, preparedPlan.preparedPlanDigest);
|
|
52546
|
-
this.params.preparedPlan = preparedPlan;
|
|
52547
|
-
this.params.targetsToUpdate = [...preparedPlan.targetsToUpdate];
|
|
52548
|
-
this.params.artifactReader = hostBinding.artifactReader;
|
|
52549
|
-
this.params.componentArtifacts = undefined;
|
|
52550
|
-
return memoryHost;
|
|
52551
|
-
}
|
|
52552
|
-
catch (error) {
|
|
52553
|
-
memoryHost === null || memoryHost === void 0 ? void 0 : memoryHost.release();
|
|
52554
|
-
throw error;
|
|
52555
52401
|
}
|
|
52402
|
+
return sources;
|
|
52556
52403
|
});
|
|
52557
52404
|
}
|
|
52558
52405
|
prepareProtocolV2LocalResourceArchive(binary) {
|
|
@@ -52574,7 +52421,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52574
52421
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 resource ZIP has no valid resource package set', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52575
52422
|
}
|
|
52576
52423
|
let totalSize = 0;
|
|
52577
|
-
const materializedEntries = [];
|
|
52578
52424
|
const resources = [];
|
|
52579
52425
|
const devicePaths = new Set();
|
|
52580
52426
|
for (const entry of resourceEntries) {
|
|
@@ -52601,10 +52447,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52601
52447
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 resource ZIP contains duplicate device path: ${header.devicePath}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52602
52448
|
}
|
|
52603
52449
|
devicePaths.add(canonicalDevicePath);
|
|
52604
|
-
materializedEntries.push({ entryName: entry.name, binary: fileBinary });
|
|
52605
52450
|
resources.push({ entryName: entry.name, binary: fileBinary, header });
|
|
52606
52451
|
}
|
|
52607
|
-
return { binary,
|
|
52452
|
+
return { binary, resources };
|
|
52608
52453
|
});
|
|
52609
52454
|
}
|
|
52610
52455
|
prepareProtocolV2ResourceSources() {
|
|
@@ -52622,7 +52467,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52622
52467
|
});
|
|
52623
52468
|
}
|
|
52624
52469
|
prepareProtocolV2ResourceArchiveSources() {
|
|
52625
|
-
var _a, _b
|
|
52470
|
+
var _a, _b;
|
|
52626
52471
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52627
52472
|
const archiveArtifacts = (_b = (_a = this.params.preparedPlan) === null || _a === void 0 ? void 0 : _a.artifacts.filter(artifact => artifact.role === 'resourceBundle' &&
|
|
52628
52473
|
artifact.target === 'resource' &&
|
|
@@ -52649,20 +52494,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52649
52494
|
if (archiveDigest !== archiveArtifact.artifact.sha256.toLowerCase()) {
|
|
52650
52495
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 prepared resource archive does not match its approved receipt', { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' });
|
|
52651
52496
|
}
|
|
52652
|
-
|
|
52653
|
-
const sources = [];
|
|
52654
|
-
for (const resource of verifiedArchive.resources) {
|
|
52655
|
-
const source = yield this.openProtocolV2MemorySource(resource.binary);
|
|
52656
|
-
sources.push({
|
|
52657
|
-
name: (_c = resource.entryName.split('/').pop()) !== null && _c !== void 0 ? _c : resource.entryName,
|
|
52658
|
-
source,
|
|
52659
|
-
devicePath: resource.header.devicePath,
|
|
52660
|
-
version: resource.header.version,
|
|
52661
|
-
payloadHash: resource.header.payloadHash,
|
|
52662
|
-
headerHash: resource.header.headerHash,
|
|
52663
|
-
});
|
|
52664
|
-
}
|
|
52665
|
-
return sources;
|
|
52497
|
+
return this.createProtocolV2ResourceSourcesFromArchive(archiveBinary);
|
|
52666
52498
|
});
|
|
52667
52499
|
}
|
|
52668
52500
|
runProtocolV2PreparedArtifacts(features, firmwareType, announceDownload = true) {
|
|
@@ -53030,6 +52862,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53030
52862
|
return `vol0:${path}`;
|
|
53031
52863
|
return `vol0:/${path}`;
|
|
53032
52864
|
}
|
|
52865
|
+
getProtocolV2ResourceComparePath(devicePath) {
|
|
52866
|
+
return isProtocolV2BootResourcePackagePath(devicePath)
|
|
52867
|
+
? PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH
|
|
52868
|
+
: devicePath;
|
|
52869
|
+
}
|
|
53033
52870
|
readProtocolV2DeviceFileHeader(path, expectedSize) {
|
|
53034
52871
|
var _a, _b, _c, _d;
|
|
53035
52872
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -53088,7 +52925,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53088
52925
|
if (!bundle.payloadHash || !bundle.headerHash)
|
|
53089
52926
|
return false;
|
|
53090
52927
|
try {
|
|
53091
|
-
const header = yield this.readProtocolV2DeviceFileHeader(bundle.devicePath, bundle.source.size);
|
|
52928
|
+
const header = yield this.readProtocolV2DeviceFileHeader(this.getProtocolV2ResourceComparePath(bundle.devicePath), bundle.source.size);
|
|
53092
52929
|
if (!header)
|
|
53093
52930
|
return false;
|
|
53094
52931
|
if (bundle.version) {
|
|
@@ -53289,8 +53126,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53289
53126
|
let totalSize = installSources.reduce((total, item) => total + item.source.size, 0);
|
|
53290
53127
|
const resourcesToSync = [];
|
|
53291
53128
|
for (const resource of resourceSources) {
|
|
53292
|
-
|
|
53293
|
-
if (!requiresFreshStaging && (yield this.isProtocolV2ResourceBundleUpToDate(resource))) {
|
|
53129
|
+
if (yield this.isProtocolV2ResourceBundleUpToDate(resource)) {
|
|
53294
53130
|
Log$7.log(`[FirmwareUpdateV4] skip RESC bundle ${resource.name}; already up to date`);
|
|
53295
53131
|
}
|
|
53296
53132
|
else {
|
|
@@ -66356,7 +66192,6 @@ exports.parseConnectSettings = parseConnectSettings;
|
|
|
66356
66192
|
exports.parseMessage = parseMessage;
|
|
66357
66193
|
exports.patchFeatures = patchFeatures;
|
|
66358
66194
|
exports.preloadSessionCache = preloadSessionCache;
|
|
66359
|
-
exports.prepareFirmwareUpdateV4MemoryHost = prepareFirmwareUpdateV4MemoryHost;
|
|
66360
66195
|
exports.projectDeviceStateFeatures = projectFeatures;
|
|
66361
66196
|
exports.registerFirmwareUpdateHostBinding = registerFirmwareUpdateHostBinding;
|
|
66362
66197
|
exports.safeThrowError = safeThrowError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,WAqBtD,CAAC;AAMF,eAAO,MAAM,gBAAgB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAC3C,CAAC;AAKjC,eAAO,MAAM,iBAAiB,cAAe,mBAAmB,KAAG,MAClC,CAAC;AAKlC,eAAO,MAAM,aAAa,cANmB,mBAAmB,KAAG,MAMrB,CAAC;AAK/C,eAAO,MAAM,cAAc,cAAe,mBAAmB,kBAkB5D,CAAC;AAMF,eAAO,MAAM,qBAAqB,aACtB,mBAAmB,GAAG,SAAS,iCACV,WAAW,GAAG,YAAY,KAAK,aAAa,GAAG,SAAS,KACtF,aAAa,GAAG,SAyBlB,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,mBAAmB,gDACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.159",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.159",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.159",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "302f9ff916b3769cdb0cf79d58d09a87eeac68c2"
|
|
50
50
|
}
|