@onekeyfe/hd-core 1.2.0-alpha.64 → 1.2.0-alpha.66
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 +313 -0
- package/__tests__/DeviceCommands.test.ts +59 -13
- package/__tests__/DeviceEventRegistration.test.ts +6 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +198 -3
- package/__tests__/connectSettings.test.ts +5 -47
- package/__tests__/core-initialization.test.ts +23 -0
- package/__tests__/device-connector-protocol.test.ts +81 -0
- package/__tests__/device-lifecycle-events.test.ts +105 -3
- package/__tests__/device-pool-state.test.ts +22 -0
- package/__tests__/device-settings.test.ts +39 -18
- package/__tests__/device-state-contract.test.ts +1 -0
- package/__tests__/device-state-mapper.test.ts +13 -1
- package/__tests__/device-utils.test.ts +48 -1
- package/__tests__/deviceSettings.test.ts +11 -1
- package/__tests__/deviceUploadNft.test.ts +316 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +31 -59
- package/__tests__/get-device-state.test.ts +132 -12
- package/__tests__/homescreen.test.ts +41 -1
- package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
- package/__tests__/kaspaSignTransaction.test.ts +3 -26
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +19 -0
- package/__tests__/open-wallet-session.test.ts +568 -37
- package/__tests__/pro2Nft.test.ts +108 -0
- package/__tests__/protocol-binding.test.ts +89 -0
- package/__tests__/protocol-v2-resources.test.ts +340 -0
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
- package/__tests__/protocol-v2-unlock-policy.test.ts +300 -37
- package/__tests__/protocol-v2.test.ts +1506 -1097
- package/__tests__/protocolV2FileWrite.test.ts +152 -0
- package/__tests__/protocolV2UiInteraction.test.ts +63 -0
- package/__tests__/public-pro2-api-boundary.test.ts +1 -0
- package/__tests__/search-devices.test.ts +12 -3
- package/__tests__/tron-sign-message-init.test.ts +2 -2
- package/__tests__/uiProgressThrottle.test.ts +74 -0
- package/__tests__/uiPromiseRegistry.test.ts +115 -0
- package/dist/api/BaseMethod.d.ts +3 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +2 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/DetectDeviceConnectProtocol.d.ts +7 -0
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +0 -11
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +3 -7
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +13 -27
- 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 +1 -5
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +4 -11
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +0 -7
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +0 -2
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +1 -9
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +9 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- 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/DeviceUploadNft.d.ts +31 -0
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
- 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 +2 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/uiPromiseRegistry.d.ts +6 -0
- package/dist/core/uiPromiseRegistry.d.ts.map +1 -0
- package/dist/data-manager/DataManager.d.ts +9 -4
- 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 +29 -6
- 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 +2 -1
- 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 +4 -0
- 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 +4 -2
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +31 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +10 -2
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +243 -248
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3051 -3774
- package/dist/inject.d.ts +6 -1
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +0 -4
- 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/resources.d.ts +30 -0
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +7 -4
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +1 -3
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +6 -1
- 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 +3 -5
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +4 -0
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/types/api/deviceUnlock.d.ts +5 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +2 -4
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +4 -71
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +7 -10
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -0
- 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 +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +38 -21
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +0 -1
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +4 -0
- 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 +4 -0
- 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/pro2Nft.d.ts +31 -0
- package/dist/utils/pro2Nft.d.ts.map +1 -0
- package/dist/utils/pro2Wallpaper.d.ts +10 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/dist/utils/uiProgressThrottle.d.ts +3 -0
- package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +8 -10
- package/src/api/CheckAllFirmwareRelease.ts +59 -60
- package/src/api/DetectDeviceConnectProtocol.ts +18 -0
- package/src/api/FirmwareUpdate.ts +7 -15
- package/src/api/FirmwareUpdateV2.ts +126 -316
- package/src/api/FirmwareUpdateV3.ts +63 -265
- package/src/api/FirmwareUpdateV4.ts +597 -1005
- package/src/api/GetPassphraseState.ts +7 -1
- package/src/api/OpenWalletSession.ts +71 -17
- package/src/api/SearchDevices.ts +3 -1
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +36 -11
- package/src/api/device/DeviceSettings.ts +5 -4
- package/src/api/device/DeviceUnlock.ts +8 -3
- package/src/api/device/DeviceUpdateBootloader.ts +6 -125
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -83
- package/src/api/firmware/updateBootloader.ts +4 -19
- package/src/api/firmware/uploadFirmware.ts +39 -144
- package/src/api/helpers/protocolV2FileWrite.ts +202 -63
- package/src/api/index.ts +2 -0
- package/src/api/kaspa/KaspaGetAddress.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +2 -13
- package/src/api/polkadot/networks.ts +3 -3
- package/src/api/protocol-v2/DeviceUploadNft.ts +197 -0
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +3 -1
- 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 +4 -0
- package/src/core/index.ts +213 -111
- package/src/core/uiPromiseRegistry.ts +63 -0
- package/src/data/messages/messages-protocol-v2.json +25 -0
- package/src/data-manager/DataManager.ts +113 -41
- package/src/data-manager/TransportManager.ts +6 -0
- package/src/data-manager/connectSettings.ts +0 -11
- package/src/device/Device.ts +274 -49
- package/src/device/DeviceCommands.ts +31 -4
- package/src/device/DeviceConnector.ts +33 -13
- package/src/device/DevicePool.ts +21 -7
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +3 -0
- package/src/events/device.ts +4 -0
- package/src/events/logBlockEvent.ts +1 -0
- package/src/events/ui-promise.ts +4 -2
- package/src/events/ui-request.ts +36 -2
- package/src/events/ui-response.ts +12 -2
- package/src/index.ts +0 -5
- package/src/inject.ts +60 -24
- package/src/lowLevelInject.ts +7 -8
- package/src/protocols/protocol-v2/features.ts +10 -7
- package/src/protocols/protocol-v2/firmware.ts +2 -0
- package/src/protocols/protocol-v2/resources.ts +390 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +46 -6
- package/src/protocols/protocol-v2/unlockPolicy.ts +1 -105
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +131 -0
- package/src/protocols/protocol-v2/walletSession.ts +214 -36
- package/src/topLevelInject.ts +7 -8
- package/src/types/api/checkAllFirmwareRelease.ts +3 -5
- package/src/types/api/detectDeviceConnectProtocol.ts +6 -0
- package/src/types/api/deviceUnlock.ts +12 -1
- package/src/types/api/deviceUpdateBootloader.ts +0 -6
- package/src/types/api/export.ts +1 -18
- package/src/types/api/firmwareUpdate.ts +6 -79
- package/src/types/api/index.ts +13 -14
- package/src/types/api/protocolV2.ts +13 -0
- package/src/types/device.ts +15 -3
- package/src/types/params.ts +7 -1
- package/src/types/settings.ts +60 -22
- package/src/utils/deviceFeaturesCompat.ts +5 -6
- package/src/utils/deviceFeaturesUtils.ts +14 -3
- package/src/utils/deviceInfoUtils.ts +2 -0
- package/src/utils/deviceSettings.ts +3 -0
- package/src/utils/homescreen.ts +32 -6
- package/src/utils/index.ts +6 -1
- package/src/utils/pro2Nft.ts +142 -0
- package/src/utils/pro2Wallpaper.ts +35 -8
- package/src/utils/uiProgressThrottle.ts +63 -0
- package/__tests__/device-initialize-timeout.test.ts +0 -56
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +0 -175
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
- package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
- package/__tests__/firmware-update/firmware-preparation-error.test.ts +0 -27
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +0 -200
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +0 -394
- package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -593
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -213
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +0 -58
- package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -25
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
- package/dist/api/firmware/FirmwarePreparationError.d.ts +0 -3
- package/dist/api/firmware/FirmwarePreparationError.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -25
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -32
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/dist/api/firmware/progressThrottle.d.ts +0 -3
- package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -10
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePlan.d.ts +0 -28
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
- package/src/api/firmware/FirmwareHostBinding.ts +0 -100
- package/src/api/firmware/FirmwarePreparationError.ts +0 -12
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -772
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -449
- package/src/api/firmware/progressThrottle.ts +0 -44
- package/src/protocols/protocol-v2/lockedError.ts +0 -10
- package/src/protocols/protocol-v2/unlockRetry.ts +0 -109
- package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
- package/src/types/api/firmwareUpdatePlan.ts +0 -38
- package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
3
4
|
import { UI_REQUEST } from '../constants/ui-request';
|
|
4
5
|
import { refreshProtocolV2DeviceStatus } from '../protocols/protocol-v2/walletSession';
|
|
@@ -24,7 +25,12 @@ export default class GetPassphraseState extends BaseMethod {
|
|
|
24
25
|
if (isProtocolV2 && this.payload.useEmptyPassphrase !== true) {
|
|
25
26
|
const features = await refreshProtocolV2DeviceStatus(this.device);
|
|
26
27
|
if (features.unlocked === false) {
|
|
27
|
-
await this.device.unlockDevice(
|
|
28
|
+
await this.device.unlockDevice(DeviceSessionPinType.Main, {
|
|
29
|
+
source: 'unlock-coordinator',
|
|
30
|
+
reason: 'device-locked',
|
|
31
|
+
deviceOnly: true,
|
|
32
|
+
method: 'getPassphraseState',
|
|
33
|
+
});
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
const { passphraseState } = await getPassphraseStateWithRefreshDeviceInfo(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
3
4
|
import { deviceWalletSessionStore } from '../device/DeviceWalletSessionStore';
|
|
4
5
|
import { getProtocolV2WalletSession } from '../protocols/protocol-v2/walletSession';
|
|
@@ -83,6 +84,7 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
83
84
|
|
|
84
85
|
init() {
|
|
85
86
|
this.useDevicePassphraseState = false;
|
|
87
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
86
88
|
this.skipForceUpdateCheck = true;
|
|
87
89
|
this.params = normalizeParams(this.payload as unknown as Record<string, unknown>);
|
|
88
90
|
this.payload.useEmptyPassphrase = this.params.mode === OpenWalletSessionMode.Standard;
|
|
@@ -90,23 +92,40 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
90
92
|
|
|
91
93
|
async run(): Promise<OpenWalletSessionPayload> {
|
|
92
94
|
const isProtocolV2 = this.device.isProtocolV2();
|
|
93
|
-
|
|
95
|
+
let state = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
94
96
|
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
|
+
};
|
|
95
107
|
const requireDeviceId = () => {
|
|
96
108
|
if (!currentDeviceId) {
|
|
97
109
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
98
110
|
}
|
|
99
111
|
return currentDeviceId;
|
|
100
112
|
};
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
currentDeviceId =
|
|
104
|
-
return
|
|
113
|
+
const refreshProtocolV2DeviceState = async () => {
|
|
114
|
+
state = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
115
|
+
currentDeviceId = state.identity.deviceId;
|
|
116
|
+
return state;
|
|
105
117
|
};
|
|
106
|
-
const
|
|
107
|
-
if (isProtocolV2 && state
|
|
108
|
-
await this.device.unlockDevice(
|
|
118
|
+
const ensureProtocolV2WalletStatus = async () => {
|
|
119
|
+
if (isProtocolV2 && !hasAuthoritativeProtocolV2WalletStatus(state)) {
|
|
120
|
+
await this.device.unlockDevice(DeviceSessionPinType.Main, {
|
|
121
|
+
source: 'unlock-coordinator',
|
|
122
|
+
reason: 'device-locked',
|
|
123
|
+
deviceOnly: true,
|
|
124
|
+
method: 'openWalletSession',
|
|
125
|
+
});
|
|
126
|
+
requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState());
|
|
109
127
|
}
|
|
128
|
+
return state;
|
|
110
129
|
};
|
|
111
130
|
|
|
112
131
|
const protocol = isProtocolV2 ? 'V2' : 'V1';
|
|
@@ -114,13 +133,25 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
114
133
|
if (this.params.mode === OpenWalletSessionMode.Standard) {
|
|
115
134
|
this.device.passphraseState = undefined;
|
|
116
135
|
const session = isProtocolV2
|
|
117
|
-
? await getProtocolV2WalletSession(this.device, {
|
|
136
|
+
? await getProtocolV2WalletSession(this.device, {
|
|
137
|
+
onlyMainPin: true,
|
|
138
|
+
deriveCardano: this.payload.deriveCardano,
|
|
139
|
+
selectMainWalletBeforeRestore:
|
|
140
|
+
!hasAuthoritativeProtocolV2WalletStatus(state) ||
|
|
141
|
+
state.status.unlockedAttachPin === true,
|
|
142
|
+
})
|
|
118
143
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
119
144
|
onlyMainPin: true,
|
|
120
145
|
initSession: this.payload.initSession,
|
|
121
146
|
});
|
|
122
|
-
const
|
|
123
|
-
|
|
147
|
+
const refreshedState = isProtocolV2
|
|
148
|
+
? requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState())
|
|
149
|
+
: state;
|
|
150
|
+
const deviceId = requireDeviceId();
|
|
151
|
+
if (
|
|
152
|
+
session.unlockedAttachPin ||
|
|
153
|
+
(isProtocolV2 && refreshedState.status.unlockedAttachPin === true)
|
|
154
|
+
) {
|
|
124
155
|
try {
|
|
125
156
|
await this.device.lockDevice();
|
|
126
157
|
} catch {
|
|
@@ -140,8 +171,8 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
140
171
|
|
|
141
172
|
if (this.params.mode === OpenWalletSessionMode.ResumeHidden) {
|
|
142
173
|
if (isProtocolV2) {
|
|
143
|
-
await
|
|
144
|
-
const refreshedDeviceId =
|
|
174
|
+
await ensureProtocolV2WalletStatus();
|
|
175
|
+
const refreshedDeviceId = requireDeviceId();
|
|
145
176
|
if (refreshedDeviceId !== this.params.deviceId) {
|
|
146
177
|
deviceWalletSessionStore.delete(this.params.deviceId, this.params.passphraseState);
|
|
147
178
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
@@ -166,6 +197,7 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
166
197
|
const session = isProtocolV2
|
|
167
198
|
? await getProtocolV2WalletSession(this.device, {
|
|
168
199
|
expectedPassphraseState: this.params.passphraseState,
|
|
200
|
+
deriveCardano: this.payload.deriveCardano,
|
|
169
201
|
})
|
|
170
202
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
171
203
|
expectPassphraseState: this.params.passphraseState,
|
|
@@ -185,15 +217,37 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
185
217
|
}
|
|
186
218
|
|
|
187
219
|
this.device.passphraseState = undefined;
|
|
188
|
-
await
|
|
220
|
+
const walletStatus = await ensureProtocolV2WalletStatus();
|
|
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;
|
|
189
227
|
const session = isProtocolV2
|
|
190
|
-
? await getProtocolV2WalletSession(this.device, {
|
|
228
|
+
? await getProtocolV2WalletSession(this.device, {
|
|
229
|
+
...(readCurrentAttachPinSession
|
|
230
|
+
? { readCurrentAttachPinSession: true }
|
|
231
|
+
: { forceWalletSelection: true }),
|
|
232
|
+
deriveCardano: this.payload.deriveCardano,
|
|
233
|
+
})
|
|
191
234
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
|
|
192
|
-
const
|
|
193
|
-
|
|
235
|
+
const refreshedState = isProtocolV2
|
|
236
|
+
? requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState())
|
|
237
|
+
: state;
|
|
238
|
+
const deviceId = requireDeviceId();
|
|
239
|
+
if (isProtocolV2 && refreshedState.status.passphraseProtection !== true) {
|
|
194
240
|
this.device.clearInternalState();
|
|
195
241
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
|
|
196
242
|
}
|
|
243
|
+
if (
|
|
244
|
+
isProtocolV2 &&
|
|
245
|
+
readCurrentAttachPinSession &&
|
|
246
|
+
refreshedState.status.unlockedAttachPin !== true
|
|
247
|
+
) {
|
|
248
|
+
this.device.clearInternalState();
|
|
249
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError);
|
|
250
|
+
}
|
|
197
251
|
const responseBase = {
|
|
198
252
|
protocol,
|
|
199
253
|
deviceId,
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -59,7 +59,9 @@ 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
|
-
|
|
62
|
+
// Discovery must actively identify the protocol instead of trusting a caller hint.
|
|
63
|
+
connectProtocol: undefined,
|
|
64
|
+
forceProtocolDetection: true,
|
|
63
65
|
refreshRuntimeState: true,
|
|
64
66
|
});
|
|
65
67
|
deviceList.push(...result.deviceList);
|
|
@@ -24,24 +24,28 @@ 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
|
-
|
|
27
|
+
const methodParams = bundle.map((param, index) =>
|
|
28
|
+
this.generateMethodName({
|
|
29
|
+
network: param.network,
|
|
30
|
+
payload: param,
|
|
31
|
+
originalIndex: index,
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
const groupedMethodParams = methodParams.reduce((groups, param) => {
|
|
35
|
+
const group = groups.get(param.methodName) ?? [];
|
|
36
|
+
group.push(param);
|
|
37
|
+
groups.set(param.methodName, group);
|
|
38
|
+
return groups;
|
|
39
|
+
}, new Map<keyof CoreApi, MethodParams[]>());
|
|
40
|
+
const requiresProtocolV2WalletHandoff =
|
|
41
|
+
this.device.isProtocolV2() &&
|
|
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());
|
|
42
46
|
|
|
43
47
|
let i = 0;
|
|
44
|
-
for (const [methodName, params] of
|
|
48
|
+
for (const [methodName, params] of methodGroups) {
|
|
45
49
|
const methodParams = {
|
|
46
50
|
bundle: params.map(param => ({
|
|
47
51
|
...param.params,
|
|
@@ -52,11 +56,7 @@ export default class AllNetworkGetAddress extends AllNetworkGetAddressBase {
|
|
|
52
56
|
throw new Error(HardwareErrorCodeMessage[HardwareErrorCode.RepeatUnlocking]);
|
|
53
57
|
}
|
|
54
58
|
// call method
|
|
55
|
-
const response = await this.callMethod(
|
|
56
|
-
methodName as keyof CoreApi,
|
|
57
|
-
methodParams,
|
|
58
|
-
rootFingerprint
|
|
59
|
-
);
|
|
59
|
+
const response = await this.callMethod(methodName, methodParams, rootFingerprint);
|
|
60
60
|
|
|
61
61
|
if (this.abortController?.signal.aborted) {
|
|
62
62
|
throw new Error(HardwareErrorCodeMessage[HardwareErrorCode.RepeatUnlocking]);
|
|
@@ -14,6 +14,7 @@ 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';
|
|
17
18
|
import {
|
|
18
19
|
completeRequestContext,
|
|
19
20
|
createRequestContext,
|
|
@@ -375,16 +376,38 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
375
376
|
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
376
377
|
|
|
377
378
|
preCheckDeviceSupport(this.device, method);
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
379
|
+
const response = await runMethodWithUnlockPolicy<any[]>(method, this.device, {
|
|
380
|
+
context: this.protocolV2UnlockContext,
|
|
381
|
+
prepare: async () => {
|
|
382
|
+
if (this.temporarySafetyCheckPrompted) {
|
|
383
|
+
method.temporarySafetyCheckPrompted = true;
|
|
384
|
+
} else {
|
|
385
|
+
const appliedTemporarySafetyCheck = await method.checkSafetyLevelOnTestNet();
|
|
386
|
+
if (appliedTemporarySafetyCheck) {
|
|
387
|
+
this.temporarySafetyCheckPrompted = true;
|
|
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
|
+
});
|
|
388
411
|
|
|
389
412
|
if (!Array.isArray(response) || response.length === 0) {
|
|
390
413
|
throw new Error('No response');
|
|
@@ -439,7 +462,9 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
439
462
|
show_display: false,
|
|
440
463
|
});
|
|
441
464
|
|
|
442
|
-
this.
|
|
465
|
+
if (!this.device.isProtocolV2()) {
|
|
466
|
+
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
467
|
+
}
|
|
443
468
|
|
|
444
469
|
if (res.message.root_fingerprint == null) {
|
|
445
470
|
throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter);
|
|
@@ -7,7 +7,6 @@ import { validateParams } from '../helpers/paramsValidator';
|
|
|
7
7
|
import {
|
|
8
8
|
mapApplySettingsToState,
|
|
9
9
|
mapCommonSettingsToProtocolV2,
|
|
10
|
-
mapDeviceSettingsToState,
|
|
11
10
|
} from '../../device/DeviceStateMapper';
|
|
12
11
|
import { getProtocolV2SettingsBehavior } from '../../protocols/protocol-v2/settingsUnlockPolicy';
|
|
13
12
|
import {
|
|
@@ -163,6 +162,8 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
163
162
|
async run() {
|
|
164
163
|
try {
|
|
165
164
|
if (this.device.isProtocolV2()) {
|
|
165
|
+
const refreshStatusAndSettings = () =>
|
|
166
|
+
this.device.getDeviceState({ refreshSections: ['status', 'settings'] });
|
|
166
167
|
assertSettingsSupported(this.payload, DEVICE_SETTINGS_V1_ONLY_FIELDS, 'Protocol V2');
|
|
167
168
|
const capabilities = getDeviceSettingsCapabilities(
|
|
168
169
|
this.device.getCurrentDeviceType(),
|
|
@@ -194,7 +195,7 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
194
195
|
const res = await this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
195
196
|
page: DeviceSettingsPage.DevicePassphrase,
|
|
196
197
|
});
|
|
197
|
-
const updated = await
|
|
198
|
+
const updated = await refreshStatusAndSettings();
|
|
198
199
|
const lockedAfterDisabling =
|
|
199
200
|
requestedPassphrase === false &&
|
|
200
201
|
current.status.unlocked === true &&
|
|
@@ -219,7 +220,7 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
219
220
|
const res = await this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
220
221
|
page: DeviceSettingsPage.DeviceAirgap,
|
|
221
222
|
});
|
|
222
|
-
const updated = await
|
|
223
|
+
const updated = await refreshStatusAndSettings();
|
|
223
224
|
if (updated.settings.airgapMode !== requestedAirgap) {
|
|
224
225
|
throw TypedError(
|
|
225
226
|
HardwareErrorCode.RuntimeError,
|
|
@@ -235,7 +236,7 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
235
236
|
const res = await this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
236
237
|
settings,
|
|
237
238
|
});
|
|
238
|
-
|
|
239
|
+
await refreshStatusAndSettings();
|
|
239
240
|
return res.message;
|
|
240
241
|
}
|
|
241
242
|
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
1
3
|
import { BaseMethod } from '../BaseMethod';
|
|
2
4
|
|
|
3
|
-
import type {
|
|
5
|
+
import type { DeviceUnlockParams } from '../../types/api/deviceUnlock';
|
|
4
6
|
|
|
5
|
-
export default class DeviceUnlock extends BaseMethod<
|
|
7
|
+
export default class DeviceUnlock extends BaseMethod<DeviceUnlockParams> {
|
|
6
8
|
getSupportedProtocols() {
|
|
7
9
|
return ['V1', 'V2'] as const;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
init() {
|
|
13
|
+
this.params = {
|
|
14
|
+
pinType: this.payload.pinType ?? DeviceSessionPinType.Main,
|
|
15
|
+
};
|
|
11
16
|
this.useDevicePassphraseState = false;
|
|
12
17
|
this.unlockPolicy = 'none';
|
|
13
18
|
this.protocolV2UiInteraction = {
|
|
@@ -21,6 +26,6 @@ export default class DeviceUnlock extends BaseMethod<LockDevice> {
|
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
async run() {
|
|
24
|
-
return this.device.unlockDevice();
|
|
29
|
+
return this.device.unlockDevice(this.params.pinType, { emitUiEvent: false });
|
|
25
30
|
}
|
|
26
31
|
}
|
|
@@ -5,24 +5,15 @@ 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
|
|
8
|
+
import { updateBootloader } from '../firmware/uploadFirmware';
|
|
9
9
|
import { DeviceModelToTypes } from '../../types';
|
|
10
10
|
import { DataManager } from '../../data-manager';
|
|
11
|
-
import { checkBootloaderLength
|
|
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';
|
|
11
|
+
import { checkBootloaderLength } from '../firmware/updateBootloader';
|
|
20
12
|
|
|
21
13
|
import type { DeviceUpdateBootloaderParams } from '../../types/api/deviceUpdateBootloader';
|
|
22
14
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
23
15
|
import type { Device } from '../../device/Device';
|
|
24
16
|
import type { Features } from '../../types';
|
|
25
|
-
import type { FirmwareByteSource } from '../firmware/FirmwareArtifactSource';
|
|
26
17
|
|
|
27
18
|
export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any> {
|
|
28
19
|
init() {
|
|
@@ -52,68 +43,17 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
52
43
|
return true;
|
|
53
44
|
}
|
|
54
45
|
|
|
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
|
-
|
|
69
46
|
async updateTouchBootloader({
|
|
70
47
|
device,
|
|
71
48
|
features,
|
|
72
49
|
firmwareType,
|
|
73
|
-
binary: preparedBinary,
|
|
74
|
-
source: preparedSource,
|
|
75
50
|
}: {
|
|
76
51
|
device: Device;
|
|
77
52
|
features?: Features;
|
|
78
53
|
firmwareType: EFirmwareType;
|
|
79
|
-
binary?: ArrayBuffer;
|
|
80
|
-
source?: FirmwareByteSource;
|
|
81
54
|
}) {
|
|
82
|
-
|
|
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;
|
|
55
|
+
let { binary } = this.payload;
|
|
106
56
|
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
|
-
}
|
|
117
57
|
this.postTipMessage(FirmwareUpdateTipMessage.CheckLatestUiResource);
|
|
118
58
|
const resourceUrl = features
|
|
119
59
|
? DataManager.getBootloaderResource(features, firmwareType)
|
|
@@ -128,7 +68,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
128
68
|
}
|
|
129
69
|
}
|
|
130
70
|
|
|
131
|
-
if (!
|
|
71
|
+
if (!checkBootloaderLength(binary)) {
|
|
132
72
|
throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
|
|
133
73
|
}
|
|
134
74
|
|
|
@@ -136,8 +76,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
136
76
|
if (features && device.isBootloader()) {
|
|
137
77
|
// Use emmcFileWrite + reboot logic for bootloader mode
|
|
138
78
|
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
|
|
139
|
-
|
|
140
|
-
return result;
|
|
79
|
+
return this.updateBootloaderWithEmmcFileWrite(device, binary);
|
|
141
80
|
}
|
|
142
81
|
|
|
143
82
|
if (features && !device.isBootloader()) {
|
|
@@ -157,71 +96,13 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
157
96
|
const { features } = device;
|
|
158
97
|
|
|
159
98
|
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();
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
99
|
|
|
213
|
-
const { binary } = payload;
|
|
214
100
|
const deviceType = device.getCurrentDeviceType();
|
|
215
101
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
216
102
|
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
217
103
|
|
|
218
104
|
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
219
|
-
return this.updateTouchBootloader({
|
|
220
|
-
device,
|
|
221
|
-
features,
|
|
222
|
-
firmwareType,
|
|
223
|
-
binary,
|
|
224
|
-
});
|
|
105
|
+
return this.updateTouchBootloader({ device, features, firmwareType });
|
|
225
106
|
}
|
|
226
107
|
|
|
227
108
|
return Promise.resolve(true);
|