@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,6 +1,6 @@
|
|
|
1
1
|
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
|
-
import { DeviceType, Enum_SafetyCheckLevel } from '@onekeyfe/hd-transport';
|
|
3
2
|
|
|
3
|
+
import { DeviceType, Enum_SafetyCheckLevel } from '@onekeyfe/hd-transport';
|
|
4
4
|
import {
|
|
5
5
|
mapApplySettingsToState,
|
|
6
6
|
mapDeviceSettingsToState,
|
|
@@ -145,18 +145,6 @@ describe('DeviceStateMapper', () => {
|
|
|
145
145
|
expect(patch.status?.unlocked).toBeUndefined();
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
test('maps the Protocol V2 Neo device type without treating it as Pro2', () => {
|
|
149
|
-
const patch = mapProtocolV2DeviceInfoToState({
|
|
150
|
-
hw: { Device_type: DeviceType.NEO, serial_no: 'NEO-SERIAL-1' },
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
expect(patch.identity).toMatchObject({
|
|
154
|
-
deviceType: EDeviceType.Neo,
|
|
155
|
-
model: 'neo',
|
|
156
|
-
serialNo: 'NEO-SERIAL-1',
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
148
|
test('maps the hardware model independently from Protocol V2', () => {
|
|
161
149
|
const pro = mapProtocolV2DeviceInfoToState({
|
|
162
150
|
protocol_version: 2,
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
|
-
import { DeviceType } from '@onekeyfe/hd-transport';
|
|
3
2
|
|
|
4
3
|
import {
|
|
5
4
|
getDeviceSerialNo,
|
|
6
5
|
getDeviceType,
|
|
7
|
-
getDeviceTypeByBleName,
|
|
8
6
|
getDeviceUUID,
|
|
9
7
|
getFirmwareType,
|
|
10
|
-
getMethodVersionRange,
|
|
11
8
|
} from '../src/utils/deviceInfoUtils';
|
|
12
9
|
import {
|
|
13
10
|
getDeviceBLEFirmwareVersion,
|
|
@@ -88,7 +85,7 @@ describe('device feature selectors', () => {
|
|
|
88
85
|
test('reads normalized Protocol V2 features through the same public selectors', () => {
|
|
89
86
|
const features = buildProtocolV2FeaturesPayload({
|
|
90
87
|
deviceInfo: {
|
|
91
|
-
hw: {
|
|
88
|
+
hw: { serial_no: 'P2-001' },
|
|
92
89
|
fw: {
|
|
93
90
|
application: { version: '5.0.0' },
|
|
94
91
|
bootloader: { version: '2.0.0' },
|
|
@@ -107,48 +104,4 @@ describe('device feature selectors', () => {
|
|
|
107
104
|
expect(getDeviceBoardloaderVersion(features)).toEqual([1, 0, 0]);
|
|
108
105
|
expect(getDeviceBLEFirmwareVersion(features)).toEqual([3, 0, 0]);
|
|
109
106
|
});
|
|
110
|
-
|
|
111
|
-
test('preserves the real Neo type in Protocol V2 compatibility features', () => {
|
|
112
|
-
const features = buildProtocolV2FeaturesPayload({
|
|
113
|
-
deviceInfo: {
|
|
114
|
-
hw: { Device_type: DeviceType.NEO, serial_no: 'NEO-001' },
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
expect(features.deviceType).toBe(EDeviceType.Neo);
|
|
119
|
-
expect(features.onekey_device_type).toBe('NEO');
|
|
120
|
-
expect(getDeviceType(features)).toBe(EDeviceType.Neo);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('recognizes Neo discovery names before initialization', () => {
|
|
124
|
-
expect(getDeviceTypeByBleName('OneKey Neo 1234')).toBe(EDeviceType.Neo);
|
|
125
|
-
expect(getDeviceTypeByBleName('Neo 1234')).toBe(EDeviceType.Neo);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test.each([EDeviceType.Pro2, EDeviceType.Neo])(
|
|
129
|
-
'uses the Pro2 product model as the chain capability fallback for %s',
|
|
130
|
-
deviceType => {
|
|
131
|
-
const checkedTypes: string[] = [];
|
|
132
|
-
const versionRange = getMethodVersionRange({ deviceType } as PROTO.Features, type => {
|
|
133
|
-
checkedTypes.push(type);
|
|
134
|
-
return type === 'model_pro2' ? { min: '1.0.0' } : undefined;
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
expect(versionRange).toEqual({ min: '1.0.0' });
|
|
138
|
-
expect(checkedTypes).toEqual([deviceType, 'model_pro2']);
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
test('prefers a Neo-specific chain range over the shared Pro2 product model', () => {
|
|
143
|
-
const versionRange = getMethodVersionRange(
|
|
144
|
-
{ deviceType: EDeviceType.Neo } as PROTO.Features,
|
|
145
|
-
type => {
|
|
146
|
-
if (type === EDeviceType.Neo) return { min: '2.0.0' };
|
|
147
|
-
if (type === 'model_pro2') return { min: '1.0.0' };
|
|
148
|
-
return undefined;
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
expect(versionRange).toEqual({ min: '2.0.0' });
|
|
153
|
-
});
|
|
154
107
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
PROTOCOL_V2_NEVER_TIMEOUT_MS,
|
|
5
4
|
getAutoLockOptions,
|
|
6
5
|
getAutoShutDownOptions,
|
|
7
6
|
getDeviceSettingsCapabilities,
|
|
8
7
|
getLanguageConfig,
|
|
9
8
|
mapLanguageFromProtocolV2,
|
|
10
9
|
mapLanguageToProtocolV2,
|
|
10
|
+
PROTOCOL_V2_NEVER_TIMEOUT_MS,
|
|
11
11
|
} from '../src/utils/deviceSettings';
|
|
12
12
|
|
|
13
13
|
describe('Pro 2 device settings options', () => {
|
|
@@ -72,16 +72,6 @@ describe('Pro 2 device settings options', () => {
|
|
|
72
72
|
]);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
test('uses the shared Protocol V2 settings model for Neo', () => {
|
|
76
|
-
expect(getLanguageConfig(EDeviceType.Neo)).toEqual(getLanguageConfig(EDeviceType.Pro2));
|
|
77
|
-
expect(getAutoLockOptions(EDeviceType.Neo, 'V2')).toEqual(
|
|
78
|
-
getAutoLockOptions(EDeviceType.Pro2, 'V2')
|
|
79
|
-
);
|
|
80
|
-
expect(getAutoShutDownOptions(EDeviceType.Neo, 'V2')).toEqual(
|
|
81
|
-
getAutoShutDownOptions(EDeviceType.Pro2, 'V2')
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
75
|
test('keeps the legacy and Protocol V2 never values protocol-specific', () => {
|
|
86
76
|
expect(getAutoLockOptions(EDeviceType.Pro, 'V1').slice(-1)[0]).toEqual({
|
|
87
77
|
label: 'Never',
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { EDeviceType, EFirmwareType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import CheckAllFirmwareRelease from '../../src/api/CheckAllFirmwareRelease';
|
|
4
|
+
import { buildFirmwareUpdatePlan } from '../../src/api/firmware/FirmwareUpdatePlan';
|
|
5
|
+
import {
|
|
6
|
+
getBleFirmwareReleaseInfo,
|
|
7
|
+
getBootloaderReleaseInfo,
|
|
8
|
+
getFirmwareReleaseInfo,
|
|
9
|
+
} from '../../src/api/firmware/releaseHelper';
|
|
10
|
+
|
|
11
|
+
jest.mock('../../src/data/config', () => ({
|
|
12
|
+
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
13
|
+
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock('../../src/api/firmware/FirmwareUpdatePlan', () => ({
|
|
17
|
+
buildFirmwareUpdatePlan: jest.fn(),
|
|
18
|
+
validateFirmwareUpdatePlanForceTargets: jest.fn(value => value ?? []),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock('../../src/api/firmware/releaseHelper', () => ({
|
|
22
|
+
getBleFirmwareReleaseInfo: jest.fn(),
|
|
23
|
+
getBootloaderReleaseInfo: jest.fn(),
|
|
24
|
+
getFirmwareReleaseInfo: jest.fn(),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
const mockBuildFirmwareUpdatePlan = buildFirmwareUpdatePlan as jest.MockedFunction<
|
|
28
|
+
typeof buildFirmwareUpdatePlan
|
|
29
|
+
>;
|
|
30
|
+
const mockGetBleFirmwareReleaseInfo = getBleFirmwareReleaseInfo as jest.MockedFunction<
|
|
31
|
+
typeof getBleFirmwareReleaseInfo
|
|
32
|
+
>;
|
|
33
|
+
const mockGetBootloaderReleaseInfo = getBootloaderReleaseInfo as jest.MockedFunction<
|
|
34
|
+
typeof getBootloaderReleaseInfo
|
|
35
|
+
>;
|
|
36
|
+
const mockGetFirmwareReleaseInfo = getFirmwareReleaseInfo as jest.MockedFunction<
|
|
37
|
+
typeof getFirmwareReleaseInfo
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
const noUpdate = {
|
|
41
|
+
status: 'valid' as const,
|
|
42
|
+
release: undefined,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const createMethod = (serialNo = 'device-id') => {
|
|
46
|
+
const method = new CheckAllFirmwareRelease({
|
|
47
|
+
id: 1,
|
|
48
|
+
payload: {
|
|
49
|
+
method: 'checkAllFirmwareRelease',
|
|
50
|
+
platform: 'native',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
method.init();
|
|
54
|
+
method.device = {
|
|
55
|
+
isProtocolV2: jest.fn(() => false),
|
|
56
|
+
features: {
|
|
57
|
+
deviceType: EDeviceType.Classic1s,
|
|
58
|
+
serialNo,
|
|
59
|
+
firmwareType: EFirmwareType.Universal,
|
|
60
|
+
firmwareVersion: '1.0.0',
|
|
61
|
+
bootloaderVersion: '1.0.0',
|
|
62
|
+
},
|
|
63
|
+
} as typeof method.device;
|
|
64
|
+
return method;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const createMethodWithForceTargets = () => {
|
|
68
|
+
const method = createMethod();
|
|
69
|
+
method.payload = {
|
|
70
|
+
...method.payload,
|
|
71
|
+
forceUpdateTargets: ['firmware', 'resource'],
|
|
72
|
+
};
|
|
73
|
+
return method;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
describe('CheckAllFirmwareRelease', () => {
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
jest.clearAllMocks();
|
|
79
|
+
mockGetFirmwareReleaseInfo.mockReturnValue(noUpdate);
|
|
80
|
+
mockGetBootloaderReleaseInfo.mockReturnValue(noUpdate);
|
|
81
|
+
mockGetBleFirmwareReleaseInfo.mockReturnValue(noUpdate);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('keeps release information available when an optional Plan cannot be built', async () => {
|
|
85
|
+
const firmware = {
|
|
86
|
+
status: 'outdated' as const,
|
|
87
|
+
release: {
|
|
88
|
+
url: 'https://firmware.onekey.so/classic/firmware.bin',
|
|
89
|
+
version: [3, 0, 0],
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
mockGetFirmwareReleaseInfo.mockReturnValue(firmware);
|
|
93
|
+
mockBuildFirmwareUpdatePlan.mockImplementation(() => {
|
|
94
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Plan cannot be built', {
|
|
95
|
+
firmwareUpdateCode: 'FirmwarePlanInvalid',
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await expect(createMethod('').run()).resolves.toEqual(
|
|
100
|
+
expect.objectContaining({
|
|
101
|
+
firmware,
|
|
102
|
+
bootloader: noUpdate,
|
|
103
|
+
ble: noUpdate,
|
|
104
|
+
firmwareUpdatePlan: undefined,
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('returns an optional Plan when the builder succeeds', async () => {
|
|
110
|
+
const plan = {
|
|
111
|
+
schemaVersion: 2 as const,
|
|
112
|
+
planDigest: 'a'.repeat(64),
|
|
113
|
+
executor: 'v3' as const,
|
|
114
|
+
deviceIdentity: 'device-id',
|
|
115
|
+
deviceModel: EDeviceType.Classic1s,
|
|
116
|
+
firmwareType: EFirmwareType.Universal,
|
|
117
|
+
platform: 'native' as const,
|
|
118
|
+
artifacts: [],
|
|
119
|
+
targetsToUpdate: [],
|
|
120
|
+
};
|
|
121
|
+
mockBuildFirmwareUpdatePlan.mockReturnValue(plan);
|
|
122
|
+
|
|
123
|
+
await expect(createMethod().run()).resolves.toEqual(
|
|
124
|
+
expect.objectContaining({
|
|
125
|
+
firmwareUpdatePlan: plan,
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('passes host-selected update targets to the Plan builder', async () => {
|
|
131
|
+
mockBuildFirmwareUpdatePlan.mockReturnValue({
|
|
132
|
+
schemaVersion: 2,
|
|
133
|
+
planDigest: 'a'.repeat(64),
|
|
134
|
+
executor: 'v2',
|
|
135
|
+
deviceIdentity: 'device-id',
|
|
136
|
+
deviceModel: EDeviceType.Classic1s,
|
|
137
|
+
firmwareType: EFirmwareType.Universal,
|
|
138
|
+
platform: 'native',
|
|
139
|
+
artifacts: [],
|
|
140
|
+
targetsToUpdate: [],
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
await createMethodWithForceTargets().run();
|
|
144
|
+
|
|
145
|
+
expect(mockBuildFirmwareUpdatePlan).toHaveBeenCalledWith(
|
|
146
|
+
expect.objectContaining({
|
|
147
|
+
forceUpdateTargets: ['firmware', 'resource'],
|
|
148
|
+
})
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('does not hide a Plan failure for an explicitly forced target', async () => {
|
|
153
|
+
const planError = ERRORS.TypedError(
|
|
154
|
+
HardwareErrorCode.RuntimeError,
|
|
155
|
+
'Forced firmware target is unavailable',
|
|
156
|
+
{
|
|
157
|
+
firmwareUpdateCode: 'FirmwarePlanInvalid',
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
mockBuildFirmwareUpdatePlan.mockImplementation(() => {
|
|
161
|
+
throw planError;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
await expect(createMethodWithForceTargets().run()).rejects.toBe(planError);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('does not hide unexpected Plan builder failures', async () => {
|
|
168
|
+
const unexpectedError = new Error('unexpected builder failure');
|
|
169
|
+
mockBuildFirmwareUpdatePlan.mockImplementation(() => {
|
|
170
|
+
throw unexpectedError;
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
await expect(createMethod().run()).rejects.toBe(unexpectedError);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { EDeviceType, EFirmwareType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import DeviceUpdateBootloader from '../../src/api/device/DeviceUpdateBootloader';
|
|
4
|
+
import {
|
|
5
|
+
registerFirmwareUpdateHostBinding,
|
|
6
|
+
unregisterFirmwareUpdateHostBinding,
|
|
7
|
+
} from '../../src/api/firmware/FirmwareHostBinding';
|
|
8
|
+
|
|
9
|
+
jest.mock('../../src/api/firmware/FirmwareUpdatePreparedPlan', () => ({
|
|
10
|
+
assertFirmwareUpdatePreparedPlanBinding: jest.fn(),
|
|
11
|
+
assertFirmwareUpdatePreparedPlanDeviceIdentity: jest.fn(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock('../../src/data-manager', () => ({
|
|
15
|
+
DataManager: {
|
|
16
|
+
getSettings: jest.fn(),
|
|
17
|
+
isBleConnect: jest.fn(),
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock('../../src/device/DevicePool', () => ({
|
|
22
|
+
DevicePool: {},
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const artifact = {
|
|
26
|
+
artifactRef: `fw:${'a'.repeat(64)}`,
|
|
27
|
+
size: 4,
|
|
28
|
+
sha256: 'a'.repeat(64),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const createMethod = () => {
|
|
32
|
+
const closeError = new Error('artifact reader close failed');
|
|
33
|
+
const close = jest.fn().mockRejectedValue(closeError);
|
|
34
|
+
const artifactReader = {
|
|
35
|
+
open: jest.fn().mockResolvedValue({ readerId: 'reader-1', size: artifact.size }),
|
|
36
|
+
read: jest.fn(),
|
|
37
|
+
close,
|
|
38
|
+
};
|
|
39
|
+
const hostBindingGeneration = registerFirmwareUpdateHostBinding({ artifactReader });
|
|
40
|
+
const method = new DeviceUpdateBootloader({
|
|
41
|
+
id: 1,
|
|
42
|
+
payload: {
|
|
43
|
+
method: 'deviceUpdateBootloader',
|
|
44
|
+
artifact,
|
|
45
|
+
hostBindingGeneration,
|
|
46
|
+
preparedPlan: {},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
(method as any).device = {
|
|
50
|
+
features: {
|
|
51
|
+
deviceType: EDeviceType.Touch,
|
|
52
|
+
serialNo: 'touch-device-id',
|
|
53
|
+
},
|
|
54
|
+
getCurrentDeviceType: () => EDeviceType.Touch,
|
|
55
|
+
getCurrentFirmwareType: () => EFirmwareType.Universal,
|
|
56
|
+
};
|
|
57
|
+
return { close, closeError, method };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
describe('DeviceUpdateBootloader artifact source cleanup', () => {
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
unregisterFirmwareUpdateHostBinding();
|
|
63
|
+
jest.restoreAllMocks();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('does not replace a successful update result when source close fails', async () => {
|
|
67
|
+
const { close, method } = createMethod();
|
|
68
|
+
jest.spyOn(method, 'updateTouchBootloader').mockResolvedValue(true);
|
|
69
|
+
|
|
70
|
+
await expect(method.run()).resolves.toBe(true);
|
|
71
|
+
|
|
72
|
+
expect(close).toHaveBeenCalledWith({ readerId: 'reader-1' });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('does not replace the original hardware error when source close fails', async () => {
|
|
76
|
+
const { close, method } = createMethod();
|
|
77
|
+
const hardwareError = ERRORS.TypedError(
|
|
78
|
+
HardwareErrorCode.FirmwareError,
|
|
79
|
+
'original bootloader hardware error'
|
|
80
|
+
);
|
|
81
|
+
jest.spyOn(method, 'updateTouchBootloader').mockRejectedValue(hardwareError);
|
|
82
|
+
|
|
83
|
+
await expect(method.run()).rejects.toBe(hardwareError);
|
|
84
|
+
|
|
85
|
+
expect(close).toHaveBeenCalledWith({ readerId: 'reader-1' });
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_FIRMWARE_ARTIFACT_READ_BYTES,
|
|
3
|
+
openFirmwareByteSource,
|
|
4
|
+
writeFirmwareByteSource,
|
|
5
|
+
} from '../../src/api/firmware/FirmwareArtifactSource';
|
|
6
|
+
|
|
7
|
+
import type { FirmwareArtifactReader } from '../../src/types/api/firmwareUpdate';
|
|
8
|
+
|
|
9
|
+
const artifact = {
|
|
10
|
+
artifactRef: `fw:${'a'.repeat(64)}`,
|
|
11
|
+
size: 6,
|
|
12
|
+
sha256: 'b'.repeat(64),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const createReader = () => {
|
|
16
|
+
const open = jest.fn(() => Promise.resolve({ readerId: 'reader-1', size: artifact.size }));
|
|
17
|
+
const read = jest.fn(({ offset, length }: { readerId: string; offset: number; length: number }) =>
|
|
18
|
+
Promise.resolve({
|
|
19
|
+
data: Uint8Array.from([1, 2, 3, 4, 5, 6]).slice(offset, offset + length).buffer,
|
|
20
|
+
bytesRead: length,
|
|
21
|
+
eof: offset + length === artifact.size,
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
const close = jest.fn(() => Promise.resolve());
|
|
25
|
+
const reader: FirmwareArtifactReader = { open, read, close };
|
|
26
|
+
return { reader, open, read, close };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe('FirmwareArtifactSource', () => {
|
|
30
|
+
it('reads an opaque artifact through bounded sequential reads', async () => {
|
|
31
|
+
const { reader, close } = createReader();
|
|
32
|
+
const source = await openFirmwareByteSource({ artifact, reader });
|
|
33
|
+
if (!source) {
|
|
34
|
+
throw new Error('Expected a firmware byte source');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const writes: Array<{ offset: number; data: number[] }> = [];
|
|
38
|
+
await writeFirmwareByteSource({
|
|
39
|
+
source,
|
|
40
|
+
chunkSize: 4,
|
|
41
|
+
write: ({ data, sourceOffset, length }) => {
|
|
42
|
+
writes.push({
|
|
43
|
+
offset: sourceOffset,
|
|
44
|
+
data: Array.from(new Uint8Array(data)),
|
|
45
|
+
});
|
|
46
|
+
return Promise.resolve(length);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
await source.close();
|
|
50
|
+
|
|
51
|
+
expect(writes).toEqual([
|
|
52
|
+
{ offset: 0, data: [1, 2, 3, 4] },
|
|
53
|
+
{ offset: 4, data: [5, 6] },
|
|
54
|
+
]);
|
|
55
|
+
expect(close).toHaveBeenCalledWith({ readerId: 'reader-1' });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('rejects a reader whose opened size differs from the receipt', async () => {
|
|
59
|
+
const { reader, open, close } = createReader();
|
|
60
|
+
open.mockResolvedValue({
|
|
61
|
+
readerId: 'reader-1',
|
|
62
|
+
size: artifact.size + 1,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
await expect(openFirmwareByteSource({ artifact, reader })).rejects.toMatchObject({
|
|
66
|
+
params: {
|
|
67
|
+
firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch',
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
expect(close).toHaveBeenCalledWith({ readerId: 'reader-1' });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('rejects paths and over-limit reads before invoking the host', async () => {
|
|
74
|
+
const { reader, read } = createReader();
|
|
75
|
+
await expect(
|
|
76
|
+
openFirmwareByteSource({
|
|
77
|
+
artifact: { ...artifact, artifactRef: '/tmp/firmware.bin' },
|
|
78
|
+
reader,
|
|
79
|
+
})
|
|
80
|
+
).rejects.toMatchObject({
|
|
81
|
+
params: {
|
|
82
|
+
firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch',
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const source = await openFirmwareByteSource({ artifact, reader });
|
|
87
|
+
if (!source) {
|
|
88
|
+
throw new Error('Expected a firmware byte source');
|
|
89
|
+
}
|
|
90
|
+
await expect(
|
|
91
|
+
writeFirmwareByteSource({
|
|
92
|
+
source,
|
|
93
|
+
chunkSize: MAX_FIRMWARE_ARTIFACT_READ_BYTES + 1,
|
|
94
|
+
write: ({ length }) => Promise.resolve(length),
|
|
95
|
+
})
|
|
96
|
+
).rejects.toMatchObject({
|
|
97
|
+
params: {
|
|
98
|
+
firmwareUpdateCode: 'FirmwareArtifactReadTooLarge',
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
expect(read).not.toHaveBeenCalled();
|
|
102
|
+
await source.close();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('closes stale readers when open returns invalid metadata', async () => {
|
|
106
|
+
const { reader, open, close } = createReader();
|
|
107
|
+
open.mockResolvedValue({
|
|
108
|
+
readerId: '',
|
|
109
|
+
size: artifact.size,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
await expect(openFirmwareByteSource({ artifact, reader })).rejects.toMatchObject({
|
|
113
|
+
params: {
|
|
114
|
+
firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
expect(close).not.toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getFirmwareUpdateHostBindingGeneration,
|
|
3
|
+
registerFirmwareUpdateHostBinding,
|
|
4
|
+
resolveFirmwareUpdateHostBinding,
|
|
5
|
+
unregisterFirmwareUpdateHostBinding,
|
|
6
|
+
} from '../../src/api/firmware/FirmwareHostBinding';
|
|
7
|
+
|
|
8
|
+
const createBinding = () => ({
|
|
9
|
+
artifactReader: {
|
|
10
|
+
open: jest.fn(() => Promise.resolve({ readerId: 'reader-1', size: 4 })),
|
|
11
|
+
read: jest.fn(() =>
|
|
12
|
+
Promise.resolve({
|
|
13
|
+
data: new ArrayBuffer(4),
|
|
14
|
+
bytesRead: 4,
|
|
15
|
+
eof: true,
|
|
16
|
+
})
|
|
17
|
+
),
|
|
18
|
+
close: jest.fn(() => Promise.resolve()),
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('firmware host binding generation', () => {
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
unregisterFirmwareUpdateHostBinding();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('invalidates callbacks from a replaced generation', async () => {
|
|
28
|
+
const staleBinding = createBinding();
|
|
29
|
+
const staleGeneration = registerFirmwareUpdateHostBinding(staleBinding);
|
|
30
|
+
const stale = resolveFirmwareUpdateHostBinding(staleGeneration);
|
|
31
|
+
const activeGeneration = registerFirmwareUpdateHostBinding(createBinding());
|
|
32
|
+
|
|
33
|
+
expect(activeGeneration).toBeGreaterThan(staleGeneration);
|
|
34
|
+
expect(getFirmwareUpdateHostBindingGeneration()).toBe(activeGeneration);
|
|
35
|
+
await expect(
|
|
36
|
+
stale.artifactReader.read({
|
|
37
|
+
readerId: 'reader-1',
|
|
38
|
+
offset: 0,
|
|
39
|
+
length: 4,
|
|
40
|
+
})
|
|
41
|
+
).rejects.toMatchObject({
|
|
42
|
+
params: {
|
|
43
|
+
firmwareUpdateCode: 'FirmwareArtifactReaderInvalid',
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
expect(unregisterFirmwareUpdateHostBinding(staleGeneration)).toBe(false);
|
|
47
|
+
expect(getFirmwareUpdateHostBindingGeneration()).toBe(activeGeneration);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('closes an artifact opened during a generation race', async () => {
|
|
51
|
+
const binding = createBinding();
|
|
52
|
+
binding.artifactReader.open.mockImplementationOnce(() => {
|
|
53
|
+
registerFirmwareUpdateHostBinding(createBinding());
|
|
54
|
+
return Promise.resolve({ readerId: 'stale-reader', size: 4 });
|
|
55
|
+
});
|
|
56
|
+
const generation = registerFirmwareUpdateHostBinding(binding);
|
|
57
|
+
const guarded = resolveFirmwareUpdateHostBinding(generation);
|
|
58
|
+
|
|
59
|
+
await expect(
|
|
60
|
+
guarded.artifactReader.open({ artifactRef: `fw:${'a'.repeat(64)}` })
|
|
61
|
+
).rejects.toMatchObject({
|
|
62
|
+
params: {
|
|
63
|
+
firmwareUpdateCode: 'FirmwareArtifactReaderInvalid',
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
expect(binding.artifactReader.close).toHaveBeenCalledWith({
|
|
67
|
+
readerId: 'stale-reader',
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { normalizeFirmwarePreparationError } from '../../src/api/firmware/FirmwarePreparationError';
|
|
4
|
+
|
|
5
|
+
describe('normalizeFirmwarePreparationError', () => {
|
|
6
|
+
test('preserves structured firmware invariant errors', () => {
|
|
7
|
+
const error = ERRORS.TypedError(
|
|
8
|
+
HardwareErrorCode.RuntimeError,
|
|
9
|
+
'Firmware must be prepared by the external firmware host',
|
|
10
|
+
{
|
|
11
|
+
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
12
|
+
artifactName: 'firmware',
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(normalizeFirmwarePreparationError(error)).toBe(error);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('wraps ordinary preparation failures as firmware download errors', () => {
|
|
20
|
+
const error = normalizeFirmwarePreparationError(new Error('request failed'));
|
|
21
|
+
|
|
22
|
+
expect(error).toMatchObject({
|
|
23
|
+
errorCode: HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
24
|
+
message: 'request failed',
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|