@onekeyfe/hd-core 1.2.0-alpha.136 → 1.2.0-alpha.140
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 +1 -1
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +48 -0
- package/__tests__/device-lifecycle-events.test.ts +21 -17
- package/__tests__/device-settings.test.ts +44 -8
- package/__tests__/device-state-mapper.test.ts +38 -0
- package/__tests__/device-wallet-session-store.test.ts +21 -79
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +37 -1
- package/__tests__/protocol-v2-unlock-policy.test.ts +97 -1
- package/__tests__/protocol-v2.test.ts +102 -21
- package/dist/api/FirmwareUpdateV4.d.ts +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceVerify.d.ts +1 -0
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/firmware/protocolV2Release.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts.map +1 -1
- package/dist/index.js +93 -82
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +52 -78
- package/src/api/device/DeviceChangePin.ts +4 -1
- package/src/api/device/DeviceSettings.ts +13 -0
- package/src/api/device/DeviceVerify.ts +25 -0
- package/src/api/device/DeviceWipe.ts +4 -1
- package/src/api/firmware/protocolV2Release.ts +7 -2
- package/src/device/Device.ts +17 -42
- package/src/device/DeviceCommands.ts +1 -1
- package/src/device/DeviceStateMapper.ts +11 -7
package/dist/index.js
CHANGED
|
@@ -43538,7 +43538,7 @@ const DEVICE_CONTROL_CALLS = new Set([
|
|
|
43538
43538
|
'DeviceCertificateSign',
|
|
43539
43539
|
'DeviceMiscUsbMscControl',
|
|
43540
43540
|
]);
|
|
43541
|
-
const isProtocolV2ActionCancelledMessage = (message) => /^(?:cancel(?:led|ed)(?: on device)?|confirm dismissed|user cancel(?:led|ed)(?:\s+.*)?)$/i.test(message);
|
|
43541
|
+
const isProtocolV2ActionCancelledMessage = (message) => /^(?:cancel(?:led|ed)(?: on device)?|confirm dismissed|update cancel(?:led|ed)|user cancel(?:led|ed)(?:\s+.*)?)$/i.test(message);
|
|
43542
43542
|
function shouldReduceDebugForCall(type) {
|
|
43543
43543
|
return HIGH_VOLUME_DEBUG_CALLS.has(type);
|
|
43544
43544
|
}
|
|
@@ -44627,7 +44627,7 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
|
|
|
44627
44627
|
};
|
|
44628
44628
|
};
|
|
44629
44629
|
const mapProtocolV2DeviceStatusToState = (status) => {
|
|
44630
|
-
var _a;
|
|
44630
|
+
var _a, _b, _c;
|
|
44631
44631
|
return ({
|
|
44632
44632
|
identity: definedEntries({ deviceId: status.device_id }),
|
|
44633
44633
|
status: definedEntries({
|
|
@@ -44636,8 +44636,8 @@ const mapProtocolV2DeviceStatusToState = (status) => {
|
|
|
44636
44636
|
unlocked: status.unlocked,
|
|
44637
44637
|
passphraseProtection: status.unlocked === true ? (_a = status.passphrase_enabled) !== null && _a !== void 0 ? _a : null : undefined,
|
|
44638
44638
|
backupRequired: status.backup_required,
|
|
44639
|
-
attachToPinEnabled: status.attach_to_pin_enabled,
|
|
44640
|
-
unlockedAttachPin: status.unlocked_by_attach_to_pin,
|
|
44639
|
+
attachToPinEnabled: status.unlocked === true ? (_b = status.attach_to_pin_enabled) !== null && _b !== void 0 ? _b : undefined : undefined,
|
|
44640
|
+
unlockedAttachPin: status.unlocked === true ? (_c = status.unlocked_by_attach_to_pin) !== null && _c !== void 0 ? _c : null : undefined,
|
|
44641
44641
|
}),
|
|
44642
44642
|
raw: { protocolV2DeviceStatus: status },
|
|
44643
44643
|
});
|
|
@@ -44659,21 +44659,24 @@ const mapApplySettingsToState = (settings) => {
|
|
|
44659
44659
|
return Object.assign(Object.assign(Object.assign({}, (Object.keys(identity).length ? { identity } : {})), (Object.keys(status).length ? { status } : {})), (Object.keys(stateSettings).length ? { settings: stateSettings } : {}));
|
|
44660
44660
|
};
|
|
44661
44661
|
const mapDeviceSettingsToState = (settings) => {
|
|
44662
|
-
|
|
44663
|
-
const
|
|
44662
|
+
var _a, _b, _c, _d, _e;
|
|
44663
|
+
const identity = definedEntries({ label: (_a = settings.label) !== null && _a !== void 0 ? _a : undefined });
|
|
44664
|
+
const status = definedEntries({
|
|
44665
|
+
passphraseProtection: (_b = settings.passphrase_enable) !== null && _b !== void 0 ? _b : undefined,
|
|
44666
|
+
});
|
|
44664
44667
|
const stateSettings = definedEntries({
|
|
44665
44668
|
bleEnabled: settings.bt_enable,
|
|
44666
44669
|
language: mapLanguageFromProtocolV2(settings.language),
|
|
44667
44670
|
wallpaperPath: settings.wallpaper_path,
|
|
44668
44671
|
brightness: settings.brightness,
|
|
44669
|
-
autoLockDelayMs: settings.autolock_delay_ms,
|
|
44670
|
-
autoShutdownDelayMs: settings.autoshutdown_delay_ms,
|
|
44672
|
+
autoLockDelayMs: (_c = settings.autolock_delay_ms) !== null && _c !== void 0 ? _c : undefined,
|
|
44673
|
+
autoShutdownDelayMs: (_d = settings.autoshutdown_delay_ms) !== null && _d !== void 0 ? _d : undefined,
|
|
44671
44674
|
animationEnabled: settings.animation_enable,
|
|
44672
44675
|
tapToWake: settings.tap_to_wake,
|
|
44673
44676
|
hapticFeedback: settings.haptic_feedback,
|
|
44674
44677
|
deviceNameDisplayEnabled: settings.device_name_display_enabled,
|
|
44675
44678
|
airgapMode: settings.airgap_mode,
|
|
44676
|
-
fidoEnabled: settings.fido_enabled,
|
|
44679
|
+
fidoEnabled: (_e = settings.fido_enabled) !== null && _e !== void 0 ? _e : undefined,
|
|
44677
44680
|
usbLockEnabled: settings.usb_lock_enable,
|
|
44678
44681
|
randomKeypad: settings.random_keypad,
|
|
44679
44682
|
});
|
|
@@ -45617,6 +45620,15 @@ class Device extends events.exports {
|
|
|
45617
45620
|
yield TransportManager.reconfigure(this.features);
|
|
45618
45621
|
});
|
|
45619
45622
|
const expectedDeviceId = options === null || options === void 0 ? void 0 : options.deviceId;
|
|
45623
|
+
if (expectedDeviceId) {
|
|
45624
|
+
this.passphraseState = undefined;
|
|
45625
|
+
const { message } = yield this.commands.typedCall('GetFeatures', 'Features', {});
|
|
45626
|
+
this._updateFeatures(message);
|
|
45627
|
+
yield TransportManager.reconfigure(this.features);
|
|
45628
|
+
if (!this.checkDeviceId(expectedDeviceId)) {
|
|
45629
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
45630
|
+
}
|
|
45631
|
+
}
|
|
45620
45632
|
this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
|
|
45621
45633
|
if (options === null || options === void 0 ? void 0 : options.initSession) {
|
|
45622
45634
|
this.clearInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
|
|
@@ -45632,23 +45644,7 @@ class Device extends events.exports {
|
|
|
45632
45644
|
if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
|
|
45633
45645
|
payload.derive_cardano = true;
|
|
45634
45646
|
}
|
|
45635
|
-
|
|
45636
|
-
yield TransportManager.reconfigure(this.features);
|
|
45637
|
-
}
|
|
45638
|
-
const assertExpectedDeviceIdentity = () => {
|
|
45639
|
-
if (expectedDeviceId && !this.checkDeviceId(expectedDeviceId)) {
|
|
45640
|
-
this.clearInternalState();
|
|
45641
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
45642
|
-
}
|
|
45643
|
-
};
|
|
45644
|
-
try {
|
|
45645
|
-
yield callInitialize(payload, options === null || options === void 0 ? void 0 : options.initSession);
|
|
45646
|
-
}
|
|
45647
|
-
catch (error) {
|
|
45648
|
-
assertExpectedDeviceIdentity();
|
|
45649
|
-
throw error;
|
|
45650
|
-
}
|
|
45651
|
-
assertExpectedDeviceIdentity();
|
|
45647
|
+
yield callInitialize(payload, options === null || options === void 0 ? void 0 : options.initSession);
|
|
45652
45648
|
}
|
|
45653
45649
|
catch (error) {
|
|
45654
45650
|
Log$h.error('Initialization failed:', error);
|
|
@@ -46122,14 +46118,17 @@ class Device extends events.exports {
|
|
|
46122
46118
|
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
|
|
46123
46119
|
const cleanupPromise = this.runCleanupPromise;
|
|
46124
46120
|
const { cancelableAction } = this;
|
|
46121
|
+
const env = DataManager.getSettings('env');
|
|
46125
46122
|
if (cancelableAction) {
|
|
46126
46123
|
yield cancelableAction(error);
|
|
46127
46124
|
}
|
|
46128
46125
|
else if (this.isProtocolV2() &&
|
|
46129
|
-
DataManager.isBleConnect(
|
|
46126
|
+
(DataManager.isBleConnect(env) ||
|
|
46127
|
+
DataManager.isBrowserWebUsb(env) ||
|
|
46128
|
+
DataManager.isDesktopWebUsb(env)) &&
|
|
46130
46129
|
this.hasDeviceAcquire()) {
|
|
46131
46130
|
yield ((_b = (_a = this.commands) === null || _a === void 0 ? void 0 : _a.cancelDevice) === null || _b === void 0 ? void 0 : _b.call(_a).catch(cancelError => {
|
|
46132
|
-
Log$h.debug('Protocol V2
|
|
46131
|
+
Log$h.debug('Protocol V2 fallback cancel error', cancelError);
|
|
46133
46132
|
}));
|
|
46134
46133
|
}
|
|
46135
46134
|
yield ((_c = this.commands) === null || _c === void 0 ? void 0 : _c.cancel());
|
|
@@ -47520,11 +47519,12 @@ function loadProtocolV2FirmwareReleaseContext({ device, firmwareType: firmwareTy
|
|
|
47520
47519
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `${methodName} requires initialized device features`);
|
|
47521
47520
|
}
|
|
47522
47521
|
const firmwareType = (_a = firmwareTypeParam !== null && firmwareTypeParam !== void 0 ? firmwareTypeParam : state.identity.firmwareType) !== null && _a !== void 0 ? _a : hdShared.EFirmwareType.Universal;
|
|
47522
|
+
const normalizedFeatures = Object.assign(Object.assign({}, features), { deviceType: state.identity.deviceType, firmwareType });
|
|
47523
47523
|
return {
|
|
47524
47524
|
state: state,
|
|
47525
|
-
features,
|
|
47525
|
+
features: normalizedFeatures,
|
|
47526
47526
|
firmwareType,
|
|
47527
|
-
release: DataManager.getFirmwareLatestRelease(
|
|
47527
|
+
release: DataManager.getFirmwareLatestRelease(normalizedFeatures, firmwareType),
|
|
47528
47528
|
};
|
|
47529
47529
|
});
|
|
47530
47530
|
}
|
|
@@ -48184,6 +48184,7 @@ class DeviceChangePin extends BaseMethod {
|
|
|
48184
48184
|
}
|
|
48185
48185
|
init() {
|
|
48186
48186
|
this.unlockPolicy = 'unlock-before-run';
|
|
48187
|
+
this.protocolV2PreUnlockPinType = hdTransport.DeviceSessionPinType.Any;
|
|
48187
48188
|
this.useDevicePassphraseState = false;
|
|
48188
48189
|
validateParams(this.payload, [{ name: 'remove', type: 'boolean' }]);
|
|
48189
48190
|
this.params = {
|
|
@@ -48533,6 +48534,9 @@ class DeviceSettings extends BaseMethod {
|
|
|
48533
48534
|
const res = yield this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
48534
48535
|
page: hdTransport.DeviceSettingsPage.DevicePassphrase,
|
|
48535
48536
|
});
|
|
48537
|
+
this.device.updateState({
|
|
48538
|
+
status: Object.assign({ passphraseProtection: requestedPassphrase }, (requestedPassphrase === false ? { unlockedAttachPin: false } : undefined)),
|
|
48539
|
+
}, 'settings-write');
|
|
48536
48540
|
yield refreshStatusAndSettings();
|
|
48537
48541
|
return res.message;
|
|
48538
48542
|
}
|
|
@@ -48793,7 +48797,12 @@ class DeviceSupportFeatures extends BaseMethod {
|
|
|
48793
48797
|
}
|
|
48794
48798
|
|
|
48795
48799
|
class DeviceVerify extends BaseMethod {
|
|
48800
|
+
getSupportedProtocols() {
|
|
48801
|
+
return ['V1', 'V2'];
|
|
48802
|
+
}
|
|
48796
48803
|
init() {
|
|
48804
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
48805
|
+
this.protocolV2PreUnlockPinType = hdTransport.DeviceSessionPinType.Any;
|
|
48797
48806
|
this.useDevicePassphraseState = false;
|
|
48798
48807
|
validateParams(this.payload, [{ name: 'dataHex', type: 'hexString' }]);
|
|
48799
48808
|
this.params = {
|
|
@@ -48808,6 +48817,16 @@ class DeviceVerify extends BaseMethod {
|
|
|
48808
48817
|
const res = yield this.device.commands.typedCall('BixinVerifyDeviceRequest', 'BixinVerifyDeviceAck', Object.assign(Object.assign({}, this.params), { data: utils.bytesToHex(sha256.sha256(this.params.data)) }));
|
|
48809
48818
|
response = res.message;
|
|
48810
48819
|
}
|
|
48820
|
+
else if (this.device.isProtocolV2()) {
|
|
48821
|
+
const signatureRes = yield this.device.commands.typedCall('DeviceCertificateSign', 'DeviceCertificateSignature', {
|
|
48822
|
+
data: this.params.data,
|
|
48823
|
+
});
|
|
48824
|
+
const certRes = yield this.device.commands.typedCall('DeviceCertificateRead', 'DeviceCertificate');
|
|
48825
|
+
response = {
|
|
48826
|
+
cert: certRes.message.cert_and_pubkey,
|
|
48827
|
+
signature: signatureRes.message.data,
|
|
48828
|
+
};
|
|
48829
|
+
}
|
|
48811
48830
|
else {
|
|
48812
48831
|
const signatureRes = yield this.device.commands.typedCall('SESignMessage', 'SEMessageSignature', {
|
|
48813
48832
|
message: this.params.data,
|
|
@@ -48832,6 +48851,7 @@ class DeviceWipe extends BaseMethod {
|
|
|
48832
48851
|
}
|
|
48833
48852
|
init() {
|
|
48834
48853
|
this.unlockPolicy = 'unlock-before-run';
|
|
48854
|
+
this.protocolV2PreUnlockPinType = hdTransport.DeviceSessionPinType.Any;
|
|
48835
48855
|
this.useDevicePassphraseState = false;
|
|
48836
48856
|
this.protocolV2UiInteraction = {
|
|
48837
48857
|
request: 'button',
|
|
@@ -51719,9 +51739,8 @@ const PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT = 90 * 1000;
|
|
|
51719
51739
|
const PROTOCOL_V2_FINAL_RECONNECT_TIMEOUT = 3 * 60 * 1000;
|
|
51720
51740
|
const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
|
|
51721
51741
|
const PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT = 15 * 1000;
|
|
51722
|
-
const PROTOCOL_V2_INSTALL_TIMEOUT =
|
|
51742
|
+
const PROTOCOL_V2_INSTALL_TIMEOUT = 5 * 60 * 1000;
|
|
51723
51743
|
const PROTOCOL_V2_INSTALL_STATUS_INITIAL_DELAY = 1000;
|
|
51724
|
-
const PROTOCOL_V2_MISSING_TARGET_STATUS_GRACE_TIMEOUT = 30 * 1000;
|
|
51725
51744
|
const PROTOCOL_V2_TARGET_STATUS_PENDING = 0;
|
|
51726
51745
|
const PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS = 1;
|
|
51727
51746
|
const PROTOCOL_V2_TARGET_STATUS_FINISHED = 2;
|
|
@@ -51735,6 +51754,8 @@ const PROTOCOL_V2_CONNECT_SINGLE_TIMEOUT = 75 * 1000;
|
|
|
51735
51754
|
const PROTOCOL_V2_DEVICE_INFO_READY_TIMEOUT = 30 * 1000;
|
|
51736
51755
|
const PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT = 3;
|
|
51737
51756
|
const PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE = 'FirmwareInstallStatusConflict';
|
|
51757
|
+
const PROTOCOL_V2_INSTALL_FAILED_CODE = 'FirmwareInstallFailed';
|
|
51758
|
+
const PROTOCOL_V2_INSTALL_TIMEOUT_CODE = 'FirmwareInstallTimeout';
|
|
51738
51759
|
const PROTOCOL_V2_OKPP_HEADER_SIZE = 0x52a0;
|
|
51739
51760
|
const PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET = 0x200;
|
|
51740
51761
|
const PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET = 0x240;
|
|
@@ -51890,7 +51911,8 @@ const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
|
|
|
51890
51911
|
const isProtocolV2TerminalInstallStatusError = (error) => {
|
|
51891
51912
|
var _a;
|
|
51892
51913
|
return error instanceof hdShared.HardwareError &&
|
|
51893
|
-
(error.errorCode === hdShared.HardwareErrorCode.
|
|
51914
|
+
(error.errorCode === hdShared.HardwareErrorCode.ActionCancelled ||
|
|
51915
|
+
error.errorCode === hdShared.HardwareErrorCode.FirmwareError ||
|
|
51894
51916
|
error.errorCode === hdShared.HardwareErrorCode.FirmwareVerificationFailed ||
|
|
51895
51917
|
((_a = error.params) === null || _a === void 0 ? void 0 : _a.firmwareUpdateCode) === PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE);
|
|
51896
51918
|
};
|
|
@@ -52021,7 +52043,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52021
52043
|
this.protocolV2ExecutionInLoader = false;
|
|
52022
52044
|
this.protocolV2BootResourceStagingSafe = false;
|
|
52023
52045
|
this.protocolV2CompletedTargetVersions = new Map();
|
|
52024
|
-
this.
|
|
52046
|
+
this.protocolV2CompletedTargetIds = new Set();
|
|
52025
52047
|
this.protocolV2InstallBaselineVersions = new Map();
|
|
52026
52048
|
}
|
|
52027
52049
|
getSupportedProtocols() {
|
|
@@ -52032,6 +52054,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52032
52054
|
this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.NOT_INITIALIZE];
|
|
52033
52055
|
this.requireDeviceMode = [];
|
|
52034
52056
|
this.unlockPolicy = 'unlock-before-run';
|
|
52057
|
+
this.protocolV2PreUnlockPinType = hdTransport.DeviceSessionPinType.Any;
|
|
52035
52058
|
this.useDevicePassphraseState = false;
|
|
52036
52059
|
this.skipForceUpdateCheck = true;
|
|
52037
52060
|
const { payload } = this;
|
|
@@ -52765,8 +52788,16 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52765
52788
|
? visibleVersions[target]
|
|
52766
52789
|
: `${Math.floor(statusVersion / 0x10000) % 0x100}.${Math.floor(statusVersion / 0x100) % 0x100}.${statusVersion % 0x100}`;
|
|
52767
52790
|
if (!observedVersion) {
|
|
52768
|
-
|
|
52769
|
-
|
|
52791
|
+
const requestedTargetIds = requestedTargets.flatMap(requestedTarget => {
|
|
52792
|
+
if (requestedTarget === 'resource' || requestedTarget === 'boot_resources')
|
|
52793
|
+
return [];
|
|
52794
|
+
const installTarget = PROTOCOL_V2_INSTALL_TARGET_BY_UPDATE_TARGET.get(requestedTarget);
|
|
52795
|
+
return installTarget ? [installTarget.targetId] : [];
|
|
52796
|
+
});
|
|
52797
|
+
const hasCompleteTargetEvidence = requestedTargetIds.length > 0 &&
|
|
52798
|
+
requestedTargetIds.every(targetId => this.protocolV2CompletedTargetIds.has(targetId));
|
|
52799
|
+
if (hasCompleteTargetEvidence) {
|
|
52800
|
+
Log$7.warn(`Protocol V2 target ${target} has no observable final version; install completion is authoritative`);
|
|
52770
52801
|
}
|
|
52771
52802
|
else {
|
|
52772
52803
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareVerificationFailed, `Protocol V2 target ${target} has no observable final version after status fallback`);
|
|
@@ -52807,15 +52838,18 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52807
52838
|
}
|
|
52808
52839
|
getProtocolV2DeviceFeatures() {
|
|
52809
52840
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52810
|
-
|
|
52811
|
-
return this.device.features;
|
|
52812
|
-
}
|
|
52841
|
+
let { features } = this.device;
|
|
52813
52842
|
if (typeof this.device.getFeatures === 'function') {
|
|
52814
|
-
|
|
52815
|
-
|
|
52816
|
-
|
|
52843
|
+
features !== null && features !== void 0 ? features : (features = yield this.device.getFeatures());
|
|
52844
|
+
}
|
|
52845
|
+
if (!features) {
|
|
52846
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device features not available');
|
|
52847
|
+
}
|
|
52848
|
+
const deviceType = this.device.getCurrentDeviceType();
|
|
52849
|
+
if (deviceType !== hdShared.EDeviceType.Pro2 && deviceType !== hdShared.EDeviceType.Neo) {
|
|
52850
|
+
return features;
|
|
52817
52851
|
}
|
|
52818
|
-
|
|
52852
|
+
return Object.assign(Object.assign({}, features), { deviceType, firmwareType: this.device.getCurrentFirmwareType() });
|
|
52819
52853
|
});
|
|
52820
52854
|
}
|
|
52821
52855
|
getProtocolV2SerialNumber(deviceInfo) {
|
|
@@ -53003,7 +53037,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53003
53037
|
});
|
|
53004
53038
|
}
|
|
53005
53039
|
prepareRemoteProtocolV2Binaries(firmwareType, features, explicitInstallItems = []) {
|
|
53006
|
-
var _a, _b;
|
|
53040
|
+
var _a, _b, _c;
|
|
53041
|
+
var _d;
|
|
53007
53042
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53008
53043
|
const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
|
|
53009
53044
|
let bootloaderBinary = null;
|
|
@@ -53031,6 +53066,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53031
53066
|
? PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID.get(target.targetId)
|
|
53032
53067
|
: undefined;
|
|
53033
53068
|
if (updateTarget && targetsToUpdate.has(updateTarget)) {
|
|
53069
|
+
if (component.version) {
|
|
53070
|
+
(_c = (_d = this.params).expectedTargetVersions) !== null && _c !== void 0 ? _c : (_d.expectedTargetVersions = {});
|
|
53071
|
+
this.params.expectedTargetVersions[updateTarget] = component.version.join('.');
|
|
53072
|
+
}
|
|
53034
53073
|
const explicitInstallItem = explicitInstallItemByTargetId.get(target.targetId);
|
|
53035
53074
|
const installItem = explicitInstallItem !== null && explicitInstallItem !== void 0 ? explicitInstallItem : (yield this.downloadRemoteProtocolV2Component(key, component));
|
|
53036
53075
|
if (installItem.kind === 'bootloader') {
|
|
@@ -53436,7 +53475,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53436
53475
|
});
|
|
53437
53476
|
}
|
|
53438
53477
|
assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths = new Map()) {
|
|
53439
|
-
var _a, _b, _c;
|
|
53440
53478
|
Log$7.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateStatus records=${JSON.stringify(statusTargets)}`);
|
|
53441
53479
|
const failedTarget = statusTargets.find(target => {
|
|
53442
53480
|
var _a;
|
|
@@ -53451,7 +53489,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53451
53489
|
path: failedTarget.path,
|
|
53452
53490
|
});
|
|
53453
53491
|
Log$7.error(`[FirmwareUpdateV4] firmware install failed target=${failedTargetDetails}`);
|
|
53454
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError,
|
|
53492
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, undefined, {
|
|
53493
|
+
firmwareUpdateCode: PROTOCOL_V2_INSTALL_FAILED_CODE,
|
|
53494
|
+
});
|
|
53455
53495
|
}
|
|
53456
53496
|
const matchingTargets = statusTargets.filter(target => { var _a; return expectedTargetIds.has((_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1); });
|
|
53457
53497
|
const seenTargetIds = new Set();
|
|
@@ -53460,7 +53500,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53460
53500
|
if (targetId === undefined ||
|
|
53461
53501
|
seenTargetIds.has(targetId) ||
|
|
53462
53502
|
(target.path && expectedPaths.get(targetId) && target.path !== expectedPaths.get(targetId))) {
|
|
53463
|
-
|
|
53503
|
+
Log$7.error(`[FirmwareUpdateV4] install status conflicts with target=${target.target_id}`);
|
|
53504
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, undefined, {
|
|
53464
53505
|
firmwareUpdateCode: PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE,
|
|
53465
53506
|
});
|
|
53466
53507
|
}
|
|
@@ -53472,6 +53513,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53472
53513
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53473
53514
|
if (targetId !== undefined) {
|
|
53474
53515
|
completedTargetIds.add(targetId);
|
|
53516
|
+
this.protocolV2CompletedTargetIds.add(targetId);
|
|
53475
53517
|
}
|
|
53476
53518
|
});
|
|
53477
53519
|
if (completedTargetIds.size === expectedTargetIds.size && expectedTargetIds.size > 0) {
|
|
@@ -53546,22 +53588,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53546
53588
|
waitForProtocolV2FirmwareUpdateComplete(targets, requireCurrentInstallStatus = false) {
|
|
53547
53589
|
var _a, _b;
|
|
53548
53590
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53549
|
-
this.protocolV2FinalStatusVerified = false;
|
|
53550
53591
|
const expectedTargetIds = new Set(targets.map(target => target.target_id));
|
|
53551
53592
|
const expectedPaths = new Map(targets.map(target => [target.target_id, target.path]));
|
|
53552
53593
|
const startTime = Date.now();
|
|
53553
53594
|
let lastError;
|
|
53554
53595
|
let shouldReconnect = false;
|
|
53555
53596
|
let deviceInfo;
|
|
53556
|
-
let missingTargetStatusSince;
|
|
53557
|
-
let missingTargetStatusKey;
|
|
53558
|
-
let normalModeWithoutInstallEvidenceSince;
|
|
53559
53597
|
let installEvidenceObserved = false;
|
|
53560
53598
|
let currentInstallStatusObserved = false;
|
|
53561
|
-
const resetMissingTargetStatusGrace = () => {
|
|
53562
|
-
missingTargetStatusSince = undefined;
|
|
53563
|
-
missingTargetStatusKey = undefined;
|
|
53564
|
-
};
|
|
53565
53599
|
while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
|
|
53566
53600
|
this.throwIfAborted();
|
|
53567
53601
|
try {
|
|
@@ -53581,7 +53615,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53581
53615
|
}, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
|
|
53582
53616
|
if (statusResponse.type === 'Success') {
|
|
53583
53617
|
installEvidenceObserved = true;
|
|
53584
|
-
resetMissingTargetStatusGrace();
|
|
53585
53618
|
lastError = new Error('Protocol V2 firmware install acknowledged; waiting for target status');
|
|
53586
53619
|
}
|
|
53587
53620
|
const statusTargets = statusResponse.type === 'DeviceFirmwareUpdateStatus'
|
|
@@ -53603,7 +53636,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53603
53636
|
if (hasMatchingTargetStatus &&
|
|
53604
53637
|
(!requireCurrentInstallStatus || currentInstallStatusObserved)) {
|
|
53605
53638
|
installEvidenceObserved = true;
|
|
53606
|
-
normalModeWithoutInstallEvidenceSince = undefined;
|
|
53607
53639
|
}
|
|
53608
53640
|
const matchingStatusTargets = statusTargets.filter(target => {
|
|
53609
53641
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
@@ -53612,7 +53644,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53612
53644
|
const shouldVerifyTargetCompletion = !requireCurrentInstallStatus || currentInstallStatusObserved;
|
|
53613
53645
|
if (shouldVerifyTargetCompletion &&
|
|
53614
53646
|
this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths)) {
|
|
53615
|
-
this.protocolV2FinalStatusVerified = true;
|
|
53616
53647
|
return;
|
|
53617
53648
|
}
|
|
53618
53649
|
if (requireCurrentInstallStatus &&
|
|
@@ -53631,7 +53662,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53631
53662
|
}
|
|
53632
53663
|
}
|
|
53633
53664
|
if (statusTargets.length === 0) {
|
|
53634
|
-
resetMissingTargetStatusGrace();
|
|
53635
53665
|
if (statusResponse.type !== 'Success') {
|
|
53636
53666
|
lastError = new Error('Protocol V2 firmware update is waiting for user confirmation or target status');
|
|
53637
53667
|
}
|
|
@@ -53639,23 +53669,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53639
53669
|
else {
|
|
53640
53670
|
const missingTargetIds = this.getProtocolV2MissingTargetIds(statusTargets, expectedTargetIds);
|
|
53641
53671
|
if (missingTargetIds.length > 0) {
|
|
53642
|
-
const now = Date.now();
|
|
53643
53672
|
const missingKey = missingTargetIds.join(',');
|
|
53644
|
-
if (missingTargetStatusSince === undefined || missingTargetStatusKey !== missingKey) {
|
|
53645
|
-
missingTargetStatusSince = now;
|
|
53646
|
-
missingTargetStatusKey = missingKey;
|
|
53647
|
-
}
|
|
53648
|
-
else if (now - missingTargetStatusSince >=
|
|
53649
|
-
PROTOCOL_V2_MISSING_TARGET_STATUS_GRACE_TIMEOUT) {
|
|
53650
|
-
const reportedTargetIds = statusTargets
|
|
53651
|
-
.map(target => normalizeProtocolV2TargetId(target.target_id))
|
|
53652
|
-
.filter((targetId) => targetId !== undefined);
|
|
53653
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, `Protocol V2 firmware status is missing requested records: targetIds=${missingKey} reportedTargetIds=${reportedTargetIds.join(',')}`);
|
|
53654
|
-
}
|
|
53655
53673
|
lastError = new Error(`Protocol V2 firmware status is temporarily missing targetIds=${missingKey}`);
|
|
53656
53674
|
}
|
|
53657
53675
|
else {
|
|
53658
|
-
resetMissingTargetStatusGrace();
|
|
53659
53676
|
lastError = new Error('Protocol V2 firmware targets are still installing');
|
|
53660
53677
|
}
|
|
53661
53678
|
}
|
|
@@ -53664,7 +53681,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53664
53681
|
if (isProtocolV2TerminalInstallStatusError(error)) {
|
|
53665
53682
|
throw error;
|
|
53666
53683
|
}
|
|
53667
|
-
resetMissingTargetStatusGrace();
|
|
53668
53684
|
if (isProtocolV2FirmwareStatusEndpointUnavailable(error)) {
|
|
53669
53685
|
if (!currentDeviceInfo) {
|
|
53670
53686
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device identity is unavailable during install polling');
|
|
@@ -53678,16 +53694,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53678
53694
|
return;
|
|
53679
53695
|
}
|
|
53680
53696
|
if (isNormalMode) {
|
|
53681
|
-
const now = Date.now();
|
|
53682
|
-
normalModeWithoutInstallEvidenceSince !== null && normalModeWithoutInstallEvidenceSince !== void 0 ? normalModeWithoutInstallEvidenceSince : (normalModeWithoutInstallEvidenceSince = now);
|
|
53683
|
-
if (now - normalModeWithoutInstallEvidenceSince >=
|
|
53684
|
-
PROTOCOL_V2_MISSING_TARGET_STATUS_GRACE_TIMEOUT) {
|
|
53685
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, 'Protocol V2 device returned to normal mode without install ACK, target status, or version change');
|
|
53686
|
-
}
|
|
53687
53697
|
lastError = new Error('Protocol V2 device is in normal mode but installation is not yet confirmed');
|
|
53688
53698
|
}
|
|
53689
53699
|
else {
|
|
53690
|
-
normalModeWithoutInstallEvidenceSince = undefined;
|
|
53691
53700
|
lastError = new Error('Protocol V2 firmware status endpoint is unavailable while the device remains in loader mode');
|
|
53692
53701
|
}
|
|
53693
53702
|
}
|
|
@@ -53713,12 +53722,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53713
53722
|
}
|
|
53714
53723
|
shouldReconnect = true;
|
|
53715
53724
|
deviceInfo = undefined;
|
|
53716
|
-
resetMissingTargetStatusGrace();
|
|
53717
53725
|
Log$7.log('Protocol V2 firmware install device readiness probe failed: ', error);
|
|
53718
53726
|
}
|
|
53719
53727
|
yield hdShared.wait(1000);
|
|
53720
53728
|
}
|
|
53721
|
-
|
|
53729
|
+
Log$7.error(`[FirmwareUpdateV4] install timed out after ${PROTOCOL_V2_INSTALL_TIMEOUT / 1000}s: ${this.normalizeErrorMessage(lastError)}`);
|
|
53730
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, undefined, {
|
|
53731
|
+
firmwareUpdateCode: PROTOCOL_V2_INSTALL_TIMEOUT_CODE,
|
|
53732
|
+
});
|
|
53722
53733
|
});
|
|
53723
53734
|
}
|
|
53724
53735
|
exitProtocolV2BootloaderToNormal() {
|
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.140",
|
|
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.140",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.140",
|
|
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": "15e3f0dc6c543c83a96e63b5d19aad70cdd6efb1"
|
|
50
50
|
}
|