@onekeyfe/hd-core 1.2.0-alpha.66 → 1.2.0-alpha.67
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__/AllNetworkGetAddressBase.tracing.test.ts +0 -313
- package/__tests__/DeviceCommands.test.ts +13 -59
- package/__tests__/DeviceEventRegistration.test.ts +0 -6
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +3 -198
- package/__tests__/connectSettings.test.ts +47 -5
- package/__tests__/device-initialize-timeout.test.ts +56 -0
- package/__tests__/device-lifecycle-events.test.ts +3 -105
- package/__tests__/device-pool-state.test.ts +0 -22
- package/__tests__/device-settings.test.ts +18 -39
- package/__tests__/device-state-contract.test.ts +0 -1
- package/__tests__/device-state-mapper.test.ts +1 -13
- package/__tests__/device-utils.test.ts +1 -48
- package/__tests__/deviceSettings.test.ts +1 -11
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +175 -0
- package/__tests__/firmware-update/device-update-bootloader.test.ts +87 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
- package/__tests__/firmware-update/firmware-preparation-error.test.ts +27 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +200 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +394 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +231 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +59 -31
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +12 -132
- package/__tests__/homescreen.test.ts +1 -41
- package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
- package/__tests__/kaspaSignTransaction.test.ts +26 -3
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +0 -19
- package/__tests__/open-wallet-session.test.ts +37 -568
- package/__tests__/protocol-v2-unlock-policy.test.ts +37 -300
- package/__tests__/protocol-v2.test.ts +1153 -1458
- package/__tests__/protocolV2FileWrite.test.ts +0 -152
- package/__tests__/protocolV2UiInteraction.test.ts +0 -63
- package/__tests__/public-pro2-api-boundary.test.ts +0 -1
- package/__tests__/search-devices.test.ts +3 -12
- package/__tests__/tron-sign-message-init.test.ts +2 -2
- package/dist/api/BaseMethod.d.ts +1 -3
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +1 -2
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +10 -0
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +7 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +27 -13
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +2 -2
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +25 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts +3 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +11 -4
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +25 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +32 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts +7 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- package/dist/api/firmware/updateBootloader.d.ts +2 -0
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +9 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +0 -9
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
- package/dist/api/polkadot/networks.d.ts +1 -1
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +2 -2
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +1 -1
- package/dist/api/ton/TonSignProof.d.ts +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +2 -2
- package/dist/api/tron/TronSignTransaction.d.ts +1 -1
- package/dist/core/deviceEventRegistration.d.ts +0 -2
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +4 -9
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +6 -29
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +1 -2
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -1
- package/dist/events/device.d.ts +0 -4
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-promise.d.ts +2 -4
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +2 -31
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +2 -10
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +247 -243
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3773 -3054
- package/dist/inject.d.ts +1 -6
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +4 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +4 -7
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +3 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +1 -6
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +5 -3
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +1 -5
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +4 -2
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +70 -4
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +28 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +10 -7
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +0 -3
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -2
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +0 -1
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +21 -38
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +1 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +0 -4
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +0 -4
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Wallpaper.d.ts +0 -10
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +10 -8
- package/src/api/CheckAllFirmwareRelease.ts +60 -59
- package/src/api/FirmwareUpdate.ts +15 -7
- package/src/api/FirmwareUpdateV2.ts +298 -126
- package/src/api/FirmwareUpdateV3.ts +265 -63
- package/src/api/FirmwareUpdateV4.ts +1017 -602
- package/src/api/GetPassphraseState.ts +1 -7
- package/src/api/OpenWalletSession.ts +17 -71
- package/src/api/SearchDevices.ts +1 -3
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -36
- package/src/api/device/DeviceSettings.ts +4 -5
- package/src/api/device/DeviceUnlock.ts +3 -8
- package/src/api/device/DeviceUpdateBootloader.ts +125 -6
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwarePreparationError.ts +12 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +83 -27
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +772 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +449 -0
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +144 -39
- package/src/api/helpers/protocolV2FileWrite.ts +63 -202
- package/src/api/index.ts +0 -2
- package/src/api/kaspa/KaspaGetAddress.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +13 -2
- package/src/api/polkadot/networks.ts +3 -3
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -3
- package/src/api/protocol-v2/helpers.ts +1 -1
- package/src/api/solana/SolSignMessage.ts +1 -1
- package/src/api/solana/SolSignOffchainMessage.ts +1 -1
- package/src/api/solana/SolSignTransaction.ts +2 -2
- package/src/api/sui/SuiGetAddress.ts +1 -1
- package/src/api/sui/SuiGetPublicKey.ts +1 -1
- package/src/api/sui/SuiSignMessage.ts +1 -1
- package/src/api/sui/SuiSignTransaction.ts +1 -1
- package/src/api/ton/TonGetAddress.ts +1 -1
- package/src/api/ton/TonSignMessage.ts +1 -1
- package/src/api/ton/TonSignProof.ts +1 -1
- package/src/api/tron/TronSignMessage.ts +2 -2
- package/src/api/tron/TronSignTransaction.ts +1 -1
- package/src/core/deviceEventRegistration.ts +0 -4
- package/src/core/index.ts +111 -213
- package/src/data/messages/messages-protocol-v2.json +0 -25
- package/src/data-manager/DataManager.ts +41 -113
- package/src/data-manager/TransportManager.ts +0 -6
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +49 -274
- package/src/device/DeviceCommands.ts +4 -31
- package/src/device/DeviceConnector.ts +13 -33
- package/src/device/DevicePool.ts +7 -21
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +0 -3
- package/src/events/device.ts +0 -4
- package/src/events/logBlockEvent.ts +0 -1
- package/src/events/ui-promise.ts +2 -4
- package/src/events/ui-request.ts +2 -36
- package/src/events/ui-response.ts +2 -12
- package/src/index.ts +5 -0
- package/src/inject.ts +24 -60
- package/src/lowLevelInject.ts +8 -7
- package/src/protocols/protocol-v2/features.ts +7 -10
- package/src/protocols/protocol-v2/firmware.ts +0 -2
- package/src/protocols/protocol-v2/lockedError.ts +10 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +6 -46
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -1
- package/src/protocols/protocol-v2/unlockRetry.ts +109 -0
- package/src/protocols/protocol-v2/walletSession.ts +36 -214
- package/src/topLevelInject.ts +8 -7
- package/src/types/api/checkAllFirmwareRelease.ts +5 -3
- package/src/types/api/deviceUnlock.ts +1 -12
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +18 -1
- package/src/types/api/firmwareUpdate.ts +78 -6
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +38 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
- package/src/types/api/index.ts +14 -13
- package/src/types/api/protocolV2.ts +0 -13
- package/src/types/device.ts +3 -15
- package/src/types/params.ts +1 -7
- package/src/types/settings.ts +22 -60
- package/src/utils/deviceFeaturesCompat.ts +6 -5
- package/src/utils/deviceFeaturesUtils.ts +3 -14
- package/src/utils/deviceInfoUtils.ts +0 -2
- package/src/utils/deviceSettings.ts +0 -3
- package/src/utils/homescreen.ts +6 -32
- package/src/utils/index.ts +1 -6
- package/src/utils/pro2Wallpaper.ts +8 -35
- package/__tests__/core-initialization.test.ts +0 -23
- package/__tests__/device-connector-protocol.test.ts +0 -81
- package/__tests__/deviceUploadNft.test.ts +0 -316
- package/__tests__/pro2Nft.test.ts +0 -108
- package/__tests__/protocol-binding.test.ts +0 -89
- package/__tests__/protocol-v2-resources.test.ts +0 -340
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +0 -91
- package/__tests__/uiProgressThrottle.test.ts +0 -74
- package/__tests__/uiPromiseRegistry.test.ts +0 -115
- package/dist/api/DetectDeviceConnectProtocol.d.ts +0 -7
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +0 -31
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +0 -1
- package/dist/core/uiPromiseRegistry.d.ts +0 -6
- package/dist/core/uiPromiseRegistry.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/resources.d.ts +0 -30
- package/dist/protocols/protocol-v2/resources.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -22
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +0 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +0 -4
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/utils/pro2Nft.d.ts +0 -31
- package/dist/utils/pro2Nft.d.ts.map +0 -1
- package/dist/utils/uiProgressThrottle.d.ts +0 -3
- package/dist/utils/uiProgressThrottle.d.ts.map +0 -1
- package/src/api/DetectDeviceConnectProtocol.ts +0 -18
- package/src/api/protocol-v2/DeviceUploadNft.ts +0 -197
- package/src/core/uiPromiseRegistry.ts +0 -63
- package/src/protocols/protocol-v2/resources.ts +0 -390
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -131
- package/src/types/api/detectDeviceConnectProtocol.ts +0 -6
- package/src/utils/pro2Nft.ts +0 -142
- package/src/utils/uiProgressThrottle.ts +0 -63
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
-
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
3
2
|
|
|
4
3
|
import { UI_REQUEST } from '../constants/ui-request';
|
|
5
4
|
import { refreshProtocolV2DeviceStatus } from '../protocols/protocol-v2/walletSession';
|
|
@@ -25,12 +24,7 @@ export default class GetPassphraseState extends BaseMethod {
|
|
|
25
24
|
if (isProtocolV2 && this.payload.useEmptyPassphrase !== true) {
|
|
26
25
|
const features = await refreshProtocolV2DeviceStatus(this.device);
|
|
27
26
|
if (features.unlocked === false) {
|
|
28
|
-
await this.device.unlockDevice(
|
|
29
|
-
source: 'unlock-coordinator',
|
|
30
|
-
reason: 'device-locked',
|
|
31
|
-
deviceOnly: true,
|
|
32
|
-
method: 'getPassphraseState',
|
|
33
|
-
});
|
|
27
|
+
await this.device.unlockDevice();
|
|
34
28
|
}
|
|
35
29
|
}
|
|
36
30
|
const { passphraseState } = await getPassphraseStateWithRefreshDeviceInfo(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
-
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
3
2
|
|
|
4
3
|
import { deviceWalletSessionStore } from '../device/DeviceWalletSessionStore';
|
|
5
4
|
import { getProtocolV2WalletSession } from '../protocols/protocol-v2/walletSession';
|
|
@@ -84,7 +83,6 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
84
83
|
|
|
85
84
|
init() {
|
|
86
85
|
this.useDevicePassphraseState = false;
|
|
87
|
-
this.unlockPolicy = 'unlock-before-run';
|
|
88
86
|
this.skipForceUpdateCheck = true;
|
|
89
87
|
this.params = normalizeParams(this.payload as unknown as Record<string, unknown>);
|
|
90
88
|
this.payload.useEmptyPassphrase = this.params.mode === OpenWalletSessionMode.Standard;
|
|
@@ -92,40 +90,23 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
92
90
|
|
|
93
91
|
async run(): Promise<OpenWalletSessionPayload> {
|
|
94
92
|
const isProtocolV2 = this.device.isProtocolV2();
|
|
95
|
-
|
|
93
|
+
const state = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
96
94
|
let currentDeviceId = state.identity.deviceId;
|
|
97
|
-
const hasAuthoritativeProtocolV2WalletStatus = (candidate: typeof state) =>
|
|
98
|
-
candidate.status.unlocked === true &&
|
|
99
|
-
typeof candidate.status.passphraseProtection === 'boolean' &&
|
|
100
|
-
typeof candidate.status.unlockedAttachPin === 'boolean';
|
|
101
|
-
const requireAuthoritativeProtocolV2WalletStatus = (candidate: typeof state) => {
|
|
102
|
-
if (!hasAuthoritativeProtocolV2WalletStatus(candidate)) {
|
|
103
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
104
|
-
}
|
|
105
|
-
return candidate;
|
|
106
|
-
};
|
|
107
95
|
const requireDeviceId = () => {
|
|
108
96
|
if (!currentDeviceId) {
|
|
109
97
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
110
98
|
}
|
|
111
99
|
return currentDeviceId;
|
|
112
100
|
};
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
currentDeviceId =
|
|
116
|
-
return
|
|
101
|
+
const refreshProtocolV2DeviceId = async () => {
|
|
102
|
+
const refreshedState = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
103
|
+
currentDeviceId = refreshedState.identity.deviceId;
|
|
104
|
+
return requireDeviceId();
|
|
117
105
|
};
|
|
118
|
-
const
|
|
119
|
-
if (isProtocolV2 &&
|
|
120
|
-
await this.device.unlockDevice(
|
|
121
|
-
source: 'unlock-coordinator',
|
|
122
|
-
reason: 'device-locked',
|
|
123
|
-
deviceOnly: true,
|
|
124
|
-
method: 'openWalletSession',
|
|
125
|
-
});
|
|
126
|
-
requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState());
|
|
106
|
+
const unlockProtocolV2IfLocked = async () => {
|
|
107
|
+
if (isProtocolV2 && state.status.unlocked === false) {
|
|
108
|
+
await this.device.unlockDevice();
|
|
127
109
|
}
|
|
128
|
-
return state;
|
|
129
110
|
};
|
|
130
111
|
|
|
131
112
|
const protocol = isProtocolV2 ? 'V2' : 'V1';
|
|
@@ -133,25 +114,13 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
133
114
|
if (this.params.mode === OpenWalletSessionMode.Standard) {
|
|
134
115
|
this.device.passphraseState = undefined;
|
|
135
116
|
const session = isProtocolV2
|
|
136
|
-
? await getProtocolV2WalletSession(this.device, {
|
|
137
|
-
onlyMainPin: true,
|
|
138
|
-
deriveCardano: this.payload.deriveCardano,
|
|
139
|
-
selectMainWalletBeforeRestore:
|
|
140
|
-
!hasAuthoritativeProtocolV2WalletStatus(state) ||
|
|
141
|
-
state.status.unlockedAttachPin === true,
|
|
142
|
-
})
|
|
117
|
+
? await getProtocolV2WalletSession(this.device, { onlyMainPin: true })
|
|
143
118
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
144
119
|
onlyMainPin: true,
|
|
145
120
|
initSession: this.payload.initSession,
|
|
146
121
|
});
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
: state;
|
|
150
|
-
const deviceId = requireDeviceId();
|
|
151
|
-
if (
|
|
152
|
-
session.unlockedAttachPin ||
|
|
153
|
-
(isProtocolV2 && refreshedState.status.unlockedAttachPin === true)
|
|
154
|
-
) {
|
|
122
|
+
const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
|
|
123
|
+
if (session.unlockedAttachPin) {
|
|
155
124
|
try {
|
|
156
125
|
await this.device.lockDevice();
|
|
157
126
|
} catch {
|
|
@@ -171,8 +140,8 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
171
140
|
|
|
172
141
|
if (this.params.mode === OpenWalletSessionMode.ResumeHidden) {
|
|
173
142
|
if (isProtocolV2) {
|
|
174
|
-
await
|
|
175
|
-
const refreshedDeviceId =
|
|
143
|
+
await unlockProtocolV2IfLocked();
|
|
144
|
+
const refreshedDeviceId = await refreshProtocolV2DeviceId();
|
|
176
145
|
if (refreshedDeviceId !== this.params.deviceId) {
|
|
177
146
|
deviceWalletSessionStore.delete(this.params.deviceId, this.params.passphraseState);
|
|
178
147
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
@@ -197,7 +166,6 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
197
166
|
const session = isProtocolV2
|
|
198
167
|
? await getProtocolV2WalletSession(this.device, {
|
|
199
168
|
expectedPassphraseState: this.params.passphraseState,
|
|
200
|
-
deriveCardano: this.payload.deriveCardano,
|
|
201
169
|
})
|
|
202
170
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
203
171
|
expectPassphraseState: this.params.passphraseState,
|
|
@@ -217,37 +185,15 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
217
185
|
}
|
|
218
186
|
|
|
219
187
|
this.device.passphraseState = undefined;
|
|
220
|
-
|
|
221
|
-
if (isProtocolV2 && walletStatus.status.passphraseProtection !== true) {
|
|
222
|
-
this.device.clearInternalState();
|
|
223
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
|
|
224
|
-
}
|
|
225
|
-
const readCurrentAttachPinSession =
|
|
226
|
-
isProtocolV2 && walletStatus.status.unlockedAttachPin === true;
|
|
188
|
+
await unlockProtocolV2IfLocked();
|
|
227
189
|
const session = isProtocolV2
|
|
228
|
-
? await getProtocolV2WalletSession(this.device, {
|
|
229
|
-
...(readCurrentAttachPinSession
|
|
230
|
-
? { readCurrentAttachPinSession: true }
|
|
231
|
-
: { forceWalletSelection: true }),
|
|
232
|
-
deriveCardano: this.payload.deriveCardano,
|
|
233
|
-
})
|
|
190
|
+
? await getProtocolV2WalletSession(this.device, { forceWalletSelection: true })
|
|
234
191
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
: state;
|
|
238
|
-
const deviceId = requireDeviceId();
|
|
239
|
-
if (isProtocolV2 && refreshedState.status.passphraseProtection !== true) {
|
|
192
|
+
const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
|
|
193
|
+
if (isProtocolV2 && this.device.getCurrentPassphraseProtection() !== true) {
|
|
240
194
|
this.device.clearInternalState();
|
|
241
195
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
|
|
242
196
|
}
|
|
243
|
-
if (
|
|
244
|
-
isProtocolV2 &&
|
|
245
|
-
readCurrentAttachPinSession &&
|
|
246
|
-
refreshedState.status.unlockedAttachPin !== true
|
|
247
|
-
) {
|
|
248
|
-
this.device.clearInternalState();
|
|
249
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError);
|
|
250
|
-
}
|
|
251
197
|
const responseBase = {
|
|
252
198
|
protocol,
|
|
253
199
|
deviceId,
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -59,9 +59,7 @@ export default class SearchDevices extends BaseMethod {
|
|
|
59
59
|
// Discovery is best effort. Browsers may retain WebUSB grants for devices that
|
|
60
60
|
// are offline, busy, or not ready, so one descriptor must not abort the scan.
|
|
61
61
|
const result = await DevicePool.getDevices([descriptor], descriptor.path, {
|
|
62
|
-
|
|
63
|
-
connectProtocol: undefined,
|
|
64
|
-
forceProtocolDetection: true,
|
|
62
|
+
connectProtocol: this.payload.connectProtocol,
|
|
65
63
|
refreshRuntimeState: true,
|
|
66
64
|
});
|
|
67
65
|
deviceList.push(...result.deviceList);
|
|
@@ -24,28 +24,24 @@ export default class AllNetworkGetAddress extends AllNetworkGetAddressBase {
|
|
|
24
24
|
const resultMap: Record<string, AllNetworkAddress> = {};
|
|
25
25
|
const { bundle } = this.payload as AllNetworkGetAddressParams;
|
|
26
26
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
(this.payload.useEmptyPassphrase === true || !!this.payload.passphraseState);
|
|
43
|
-
const methodGroups: [keyof CoreApi, MethodParams[]][] = requiresProtocolV2WalletHandoff
|
|
44
|
-
? methodParams.map(param => [param.methodName, [param]])
|
|
45
|
-
: Array.from(groupedMethodParams.entries());
|
|
27
|
+
const methodGroups = bundle
|
|
28
|
+
.map((param, index) =>
|
|
29
|
+
this.generateMethodName({
|
|
30
|
+
network: param.network,
|
|
31
|
+
payload: param,
|
|
32
|
+
originalIndex: index,
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
.reduce((acc, cur) => {
|
|
36
|
+
if (!acc[cur.methodName]) {
|
|
37
|
+
acc[cur.methodName] = [];
|
|
38
|
+
}
|
|
39
|
+
acc[cur.methodName].push(cur);
|
|
40
|
+
return acc;
|
|
41
|
+
}, {} as Record<keyof CoreApi, MethodParams[]>);
|
|
46
42
|
|
|
47
43
|
let i = 0;
|
|
48
|
-
for (const [methodName, params] of methodGroups) {
|
|
44
|
+
for (const [methodName, params] of Object.entries(methodGroups)) {
|
|
49
45
|
const methodParams = {
|
|
50
46
|
bundle: params.map(param => ({
|
|
51
47
|
...param.params,
|
|
@@ -56,7 +52,11 @@ export default class AllNetworkGetAddress extends AllNetworkGetAddressBase {
|
|
|
56
52
|
throw new Error(HardwareErrorCodeMessage[HardwareErrorCode.RepeatUnlocking]);
|
|
57
53
|
}
|
|
58
54
|
// call method
|
|
59
|
-
const response = await this.callMethod(
|
|
55
|
+
const response = await this.callMethod(
|
|
56
|
+
methodName as keyof CoreApi,
|
|
57
|
+
methodParams,
|
|
58
|
+
rootFingerprint
|
|
59
|
+
);
|
|
60
60
|
|
|
61
61
|
if (this.abortController?.signal.aborted) {
|
|
62
62
|
throw new Error(HardwareErrorCodeMessage[HardwareErrorCode.RepeatUnlocking]);
|
|
@@ -14,7 +14,6 @@ import { findMethod } from '../utils';
|
|
|
14
14
|
import { DEVICE, IFRAME, createUiMessage } from '../../events';
|
|
15
15
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
16
16
|
import { onDeviceButtonHandler } from '../../core';
|
|
17
|
-
import { runMethodWithUnlockPolicy } from '../../protocols/protocol-v2/unlockPolicyRunner';
|
|
18
17
|
import {
|
|
19
18
|
completeRequestContext,
|
|
20
19
|
createRequestContext,
|
|
@@ -376,38 +375,16 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
376
375
|
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
377
376
|
|
|
378
377
|
preCheckDeviceSupport(this.device, method);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// Protocol V2 hands a wallet session to exactly one blockchain request.
|
|
392
|
-
// The parent all-network call consumes its first handoff while fetching
|
|
393
|
-
// the root fingerprint, so each nested chain method must resume the
|
|
394
|
-
// requested standard or hidden wallet before sending its device command.
|
|
395
|
-
const useEmptyPassphrase = this.payload.useEmptyPassphrase === true;
|
|
396
|
-
const deriveCardano = method.name.startsWith('cardano');
|
|
397
|
-
const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
|
|
398
|
-
if (this.device.isProtocolV2() && shouldResumeWalletSession) {
|
|
399
|
-
const passphraseStateSafety = await this.device.checkPassphraseStateSafety(
|
|
400
|
-
this.payload.passphraseState,
|
|
401
|
-
useEmptyPassphrase,
|
|
402
|
-
this.payload.skipPassphraseCheck,
|
|
403
|
-
deriveCardano
|
|
404
|
-
);
|
|
405
|
-
if (!passphraseStateSafety) {
|
|
406
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
},
|
|
410
|
-
});
|
|
378
|
+
if (this.temporarySafetyCheckPrompted) {
|
|
379
|
+
method.temporarySafetyCheckPrompted = true;
|
|
380
|
+
} else {
|
|
381
|
+
const appliedTemporarySafetyCheck = await method.checkSafetyLevelOnTestNet();
|
|
382
|
+
if (appliedTemporarySafetyCheck) {
|
|
383
|
+
this.temporarySafetyCheckPrompted = true;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const response = await method.run();
|
|
411
388
|
|
|
412
389
|
if (!Array.isArray(response) || response.length === 0) {
|
|
413
390
|
throw new Error('No response');
|
|
@@ -462,9 +439,7 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
462
439
|
show_display: false,
|
|
463
440
|
});
|
|
464
441
|
|
|
465
|
-
|
|
466
|
-
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
467
|
-
}
|
|
442
|
+
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
468
443
|
|
|
469
444
|
if (res.message.root_fingerprint == null) {
|
|
470
445
|
throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter);
|
|
@@ -7,6 +7,7 @@ import { validateParams } from '../helpers/paramsValidator';
|
|
|
7
7
|
import {
|
|
8
8
|
mapApplySettingsToState,
|
|
9
9
|
mapCommonSettingsToProtocolV2,
|
|
10
|
+
mapDeviceSettingsToState,
|
|
10
11
|
} from '../../device/DeviceStateMapper';
|
|
11
12
|
import { getProtocolV2SettingsBehavior } from '../../protocols/protocol-v2/settingsUnlockPolicy';
|
|
12
13
|
import {
|
|
@@ -162,8 +163,6 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
162
163
|
async run() {
|
|
163
164
|
try {
|
|
164
165
|
if (this.device.isProtocolV2()) {
|
|
165
|
-
const refreshStatusAndSettings = () =>
|
|
166
|
-
this.device.getDeviceState({ refreshSections: ['status', 'settings'] });
|
|
167
166
|
assertSettingsSupported(this.payload, DEVICE_SETTINGS_V1_ONLY_FIELDS, 'Protocol V2');
|
|
168
167
|
const capabilities = getDeviceSettingsCapabilities(
|
|
169
168
|
this.device.getCurrentDeviceType(),
|
|
@@ -195,7 +194,7 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
195
194
|
const res = await this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
196
195
|
page: DeviceSettingsPage.DevicePassphrase,
|
|
197
196
|
});
|
|
198
|
-
const updated = await
|
|
197
|
+
const updated = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
199
198
|
const lockedAfterDisabling =
|
|
200
199
|
requestedPassphrase === false &&
|
|
201
200
|
current.status.unlocked === true &&
|
|
@@ -220,7 +219,7 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
220
219
|
const res = await this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
221
220
|
page: DeviceSettingsPage.DeviceAirgap,
|
|
222
221
|
});
|
|
223
|
-
const updated = await
|
|
222
|
+
const updated = await this.device.getDeviceState({ refreshSections: ['settings'] });
|
|
224
223
|
if (updated.settings.airgapMode !== requestedAirgap) {
|
|
225
224
|
throw TypedError(
|
|
226
225
|
HardwareErrorCode.RuntimeError,
|
|
@@ -236,7 +235,7 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
236
235
|
const res = await this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
237
236
|
settings,
|
|
238
237
|
});
|
|
239
|
-
|
|
238
|
+
this.device.updateState(mapDeviceSettingsToState(settings), 'settings-write');
|
|
240
239
|
return res.message;
|
|
241
240
|
}
|
|
242
241
|
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
|
-
|
|
3
1
|
import { BaseMethod } from '../BaseMethod';
|
|
4
2
|
|
|
5
|
-
import type {
|
|
3
|
+
import type { LockDevice } from '@onekeyfe/hd-transport';
|
|
6
4
|
|
|
7
|
-
export default class DeviceUnlock extends BaseMethod<
|
|
5
|
+
export default class DeviceUnlock extends BaseMethod<LockDevice> {
|
|
8
6
|
getSupportedProtocols() {
|
|
9
7
|
return ['V1', 'V2'] as const;
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
init() {
|
|
13
|
-
this.params = {
|
|
14
|
-
pinType: this.payload.pinType ?? DeviceSessionPinType.Main,
|
|
15
|
-
};
|
|
16
11
|
this.useDevicePassphraseState = false;
|
|
17
12
|
this.unlockPolicy = 'none';
|
|
18
13
|
this.protocolV2UiInteraction = {
|
|
@@ -26,6 +21,6 @@ export default class DeviceUnlock extends BaseMethod<DeviceUnlockParams> {
|
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
async run() {
|
|
29
|
-
return this.device.unlockDevice(
|
|
24
|
+
return this.device.unlockDevice();
|
|
30
25
|
}
|
|
31
26
|
}
|
|
@@ -5,15 +5,24 @@ import { UI_REQUEST } from '../../constants/ui-request';
|
|
|
5
5
|
import { FirmwareUpdateTipMessage } from '../../events/ui-request';
|
|
6
6
|
import { FirmwareUpdateBaseMethod } from '../firmware/FirmwareUpdateBaseMethod';
|
|
7
7
|
import { getSysResourceBinary } from '../firmware/getBinary';
|
|
8
|
-
import { updateBootloader } from '../firmware/uploadFirmware';
|
|
8
|
+
import { updateBootloader, updateBootloaderFromSource } from '../firmware/uploadFirmware';
|
|
9
9
|
import { DeviceModelToTypes } from '../../types';
|
|
10
10
|
import { DataManager } from '../../data-manager';
|
|
11
|
-
import { checkBootloaderLength } from '../firmware/updateBootloader';
|
|
11
|
+
import { checkBootloaderLength, checkBootloaderSourceLength } from '../firmware/updateBootloader';
|
|
12
|
+
import { openFirmwareByteSource } from '../firmware/FirmwareArtifactSource';
|
|
13
|
+
import { resolveFirmwareUpdateHostBinding } from '../firmware/FirmwareHostBinding';
|
|
14
|
+
import {
|
|
15
|
+
assertFirmwareUpdatePreparedPlanBinding,
|
|
16
|
+
assertFirmwareUpdatePreparedPlanDeviceIdentity,
|
|
17
|
+
} from '../firmware/FirmwareUpdatePreparedPlan';
|
|
18
|
+
import { getDeviceType, getDeviceUUID } from '../../utils';
|
|
19
|
+
import { resolveDeviceBootloaderMode } from '../../utils/deviceFeaturesCompat';
|
|
12
20
|
|
|
13
21
|
import type { DeviceUpdateBootloaderParams } from '../../types/api/deviceUpdateBootloader';
|
|
14
22
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
15
23
|
import type { Device } from '../../device/Device';
|
|
16
24
|
import type { Features } from '../../types';
|
|
25
|
+
import type { FirmwareByteSource } from '../firmware/FirmwareArtifactSource';
|
|
17
26
|
|
|
18
27
|
export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any> {
|
|
19
28
|
init() {
|
|
@@ -43,17 +52,68 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
43
52
|
return true;
|
|
44
53
|
}
|
|
45
54
|
|
|
55
|
+
async updateBootloaderWithEmmcFileWriteFromSource(_device: Device, source: FirmwareByteSource) {
|
|
56
|
+
const filePath = '0:boot/bootloader.bin';
|
|
57
|
+
|
|
58
|
+
this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
|
|
59
|
+
await this.emmcCommonUpdateProcessFromSource({
|
|
60
|
+
source,
|
|
61
|
+
filePath,
|
|
62
|
+
});
|
|
63
|
+
this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
|
|
64
|
+
await this.reboot(RebootType.Normal);
|
|
65
|
+
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloaderSuccess);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
46
69
|
async updateTouchBootloader({
|
|
47
70
|
device,
|
|
48
71
|
features,
|
|
49
72
|
firmwareType,
|
|
73
|
+
binary: preparedBinary,
|
|
74
|
+
source: preparedSource,
|
|
50
75
|
}: {
|
|
51
76
|
device: Device;
|
|
52
77
|
features?: Features;
|
|
53
78
|
firmwareType: EFirmwareType;
|
|
79
|
+
binary?: ArrayBuffer;
|
|
80
|
+
source?: FirmwareByteSource;
|
|
54
81
|
}) {
|
|
55
|
-
|
|
82
|
+
if (preparedSource) {
|
|
83
|
+
if (!(await checkBootloaderSourceLength(preparedSource))) {
|
|
84
|
+
throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
|
|
85
|
+
}
|
|
86
|
+
if (features && device.isBootloader()) {
|
|
87
|
+
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
|
|
88
|
+
const result = await this.updateBootloaderWithEmmcFileWriteFromSource(
|
|
89
|
+
device,
|
|
90
|
+
preparedSource
|
|
91
|
+
);
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
if (features && !device.isBootloader()) {
|
|
95
|
+
await updateBootloaderFromSource(
|
|
96
|
+
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
97
|
+
this.postMessage,
|
|
98
|
+
device,
|
|
99
|
+
preparedSource
|
|
100
|
+
);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let binary = preparedBinary;
|
|
56
106
|
if (!binary) {
|
|
107
|
+
if (DataManager.getSettings('firmwareManifestMode') === 'external-only') {
|
|
108
|
+
throw ERRORS.TypedError(
|
|
109
|
+
HardwareErrorCode.RuntimeError,
|
|
110
|
+
'Bootloader must be prepared by the external firmware host',
|
|
111
|
+
{
|
|
112
|
+
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
113
|
+
artifactName: 'bootloader',
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
}
|
|
57
117
|
this.postTipMessage(FirmwareUpdateTipMessage.CheckLatestUiResource);
|
|
58
118
|
const resourceUrl = features
|
|
59
119
|
? DataManager.getBootloaderResource(features, firmwareType)
|
|
@@ -68,7 +128,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
68
128
|
}
|
|
69
129
|
}
|
|
70
130
|
|
|
71
|
-
if (!checkBootloaderLength(binary)) {
|
|
131
|
+
if (!binary || !checkBootloaderLength(binary)) {
|
|
72
132
|
throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
|
|
73
133
|
}
|
|
74
134
|
|
|
@@ -76,7 +136,8 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
76
136
|
if (features && device.isBootloader()) {
|
|
77
137
|
// Use emmcFileWrite + reboot logic for bootloader mode
|
|
78
138
|
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
|
|
79
|
-
|
|
139
|
+
const result = await this.updateBootloaderWithEmmcFileWrite(device, binary);
|
|
140
|
+
return result;
|
|
80
141
|
}
|
|
81
142
|
|
|
82
143
|
if (features && !device.isBootloader()) {
|
|
@@ -96,13 +157,71 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
96
157
|
const { features } = device;
|
|
97
158
|
|
|
98
159
|
const payload = this.payload as DeviceUpdateBootloaderParams;
|
|
160
|
+
const hostBinding = payload.artifact
|
|
161
|
+
? resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration)
|
|
162
|
+
: undefined;
|
|
163
|
+
const executionParams = {
|
|
164
|
+
...payload,
|
|
165
|
+
artifactReader: hostBinding?.artifactReader ?? payload.artifactReader,
|
|
166
|
+
};
|
|
167
|
+
if (payload.artifact) {
|
|
168
|
+
assertFirmwareUpdatePreparedPlanDeviceIdentity({
|
|
169
|
+
preparedPlan: payload.preparedPlan,
|
|
170
|
+
deviceIdentity: getDeviceUUID(features) || undefined,
|
|
171
|
+
bootloaderMode: resolveDeviceBootloaderMode(features),
|
|
172
|
+
deviceModel: String(getDeviceType(features)),
|
|
173
|
+
});
|
|
174
|
+
assertFirmwareUpdatePreparedPlanBinding({
|
|
175
|
+
preparedPlan: payload.preparedPlan,
|
|
176
|
+
executor: 'v2',
|
|
177
|
+
scopeTargets: ['bootloader'],
|
|
178
|
+
bindings: [
|
|
179
|
+
{
|
|
180
|
+
target: 'bootloader',
|
|
181
|
+
artifact: payload.artifact,
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
const source = await openFirmwareByteSource({
|
|
186
|
+
artifact: payload.artifact,
|
|
187
|
+
reader: executionParams.artifactReader,
|
|
188
|
+
});
|
|
189
|
+
if (!source) {
|
|
190
|
+
throw ERRORS.TypedError(
|
|
191
|
+
HardwareErrorCode.RuntimeError,
|
|
192
|
+
'Bootloader artifact is not prepared'
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const deviceType = device.getCurrentDeviceType();
|
|
197
|
+
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
198
|
+
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
199
|
+
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
200
|
+
return await this.updateTouchBootloader({
|
|
201
|
+
device,
|
|
202
|
+
features,
|
|
203
|
+
firmwareType,
|
|
204
|
+
source,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return true;
|
|
208
|
+
} finally {
|
|
209
|
+
await source.close().catch(() => undefined);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
99
212
|
|
|
213
|
+
const { binary } = payload;
|
|
100
214
|
const deviceType = device.getCurrentDeviceType();
|
|
101
215
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
102
216
|
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
103
217
|
|
|
104
218
|
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
105
|
-
return this.updateTouchBootloader({
|
|
219
|
+
return this.updateTouchBootloader({
|
|
220
|
+
device,
|
|
221
|
+
features,
|
|
222
|
+
firmwareType,
|
|
223
|
+
binary,
|
|
224
|
+
});
|
|
106
225
|
}
|
|
107
226
|
|
|
108
227
|
return Promise.resolve(true);
|