@onekeyfe/hd-core 1.2.0-alpha.67 → 1.2.0-alpha.69
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 +226 -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-firmware-targets.test.ts +33 -1
- package/__tests__/protocol-v2-resources.test.ts +343 -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 +1586 -1213
- package/__tests__/protocolV2FileWrite.test.ts +193 -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 +3 -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 -10
- 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 +15 -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 -247
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3135 -3785
- 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 -70
- 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 +78 -64
- package/src/api/DetectDeviceConnectProtocol.ts +18 -0
- package/src/api/FirmwareUpdate.ts +7 -15
- package/src/api/FirmwareUpdateV2.ts +126 -298
- package/src/api/FirmwareUpdateV3.ts +63 -265
- package/src/api/FirmwareUpdateV4.ts +645 -1018
- 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 +252 -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 +394 -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 -78
- 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 +61 -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/device-update-bootloader.test.ts +0 -87
- 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 -231
- 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,6 +1,8 @@
|
|
|
1
1
|
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { writeProtocolV2File } from '../src/api/helpers/protocolV2FileWrite';
|
|
4
|
+
import { DataManager } from '../src/data-manager';
|
|
5
|
+
import { LoggerNames, getLogger } from '../src/utils/logger';
|
|
4
6
|
|
|
5
7
|
jest.mock('../src/data/config', () => ({
|
|
6
8
|
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
@@ -65,6 +67,24 @@ describe('writeProtocolV2File', () => {
|
|
|
65
67
|
).rejects.toMatchObject({ errorCode: HardwareErrorCode.RuntimeError });
|
|
66
68
|
});
|
|
67
69
|
|
|
70
|
+
test('拒绝非 FilesystemFile 响应', async () => {
|
|
71
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
72
|
+
type: 'CallMethodError',
|
|
73
|
+
message: { error: 'unexpected response' },
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
await expect(
|
|
77
|
+
writeProtocolV2File({
|
|
78
|
+
commands: { typedCall } as any,
|
|
79
|
+
path: 'vol1:/wallpapers/test.bin',
|
|
80
|
+
data: new Uint8Array([1]),
|
|
81
|
+
})
|
|
82
|
+
).rejects.toMatchObject({
|
|
83
|
+
errorCode: HardwareErrorCode.RuntimeError,
|
|
84
|
+
message: 'FilesystemFileWrite received unexpected response CallMethodError',
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
68
88
|
test('BLE 响应超时时原偏移重试且不重复上报进度', async () => {
|
|
69
89
|
const timeoutError = Object.assign(new Error('Lowlevel response timeout'), {
|
|
70
90
|
errorCode: HardwareErrorCode.BleTimeoutError,
|
|
@@ -89,4 +109,177 @@ describe('writeProtocolV2File', () => {
|
|
|
89
109
|
expect(typedCall.mock.calls[1][2]).toEqual(typedCall.mock.calls[0][2]);
|
|
90
110
|
expect(onProgress).toHaveBeenCalledTimes(1);
|
|
91
111
|
});
|
|
112
|
+
|
|
113
|
+
test('支持固件上传的响应写入选项和全局设备进度', async () => {
|
|
114
|
+
const typedCall = jest.fn().mockResolvedValue({ message: { processed_byte: 3 } });
|
|
115
|
+
const getUiPercentage = jest.fn().mockReturnValue(42);
|
|
116
|
+
|
|
117
|
+
await writeProtocolV2File({
|
|
118
|
+
commands: { typedCall } as any,
|
|
119
|
+
path: 'vol0:/firmware.bin',
|
|
120
|
+
data: new Uint8Array([1, 2, 3]),
|
|
121
|
+
writeWithResponse: true,
|
|
122
|
+
getUiPercentage,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(getUiPercentage).toHaveBeenCalledWith({
|
|
126
|
+
offset: 0,
|
|
127
|
+
chunkLength: 3,
|
|
128
|
+
totalSize: 3,
|
|
129
|
+
});
|
|
130
|
+
expect(typedCall).toHaveBeenCalledWith(
|
|
131
|
+
'FilesystemFileWrite',
|
|
132
|
+
'FilesystemFile',
|
|
133
|
+
expect.objectContaining({ ui_percentage: 42 }),
|
|
134
|
+
expect.objectContaining({
|
|
135
|
+
writeWithResponse: true,
|
|
136
|
+
onWriteCompleted: expect.any(Function),
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('记录主机整帧写入与设备响应等待的分段耗时', async () => {
|
|
142
|
+
const log = getLogger(LoggerNames.Core);
|
|
143
|
+
const logSpy = jest.spyOn(log, 'log').mockImplementation(() => undefined);
|
|
144
|
+
const typedCall = jest.fn().mockImplementation((_type, _resType, _request, options) => {
|
|
145
|
+
options.onWriteCompleted({ elapsedMs: 25, frameBytes: 128 });
|
|
146
|
+
return Promise.resolve({ message: { processed_byte: 3 } });
|
|
147
|
+
});
|
|
148
|
+
const dateNowSpy = jest
|
|
149
|
+
.spyOn(Date, 'now')
|
|
150
|
+
.mockReturnValueOnce(1_000)
|
|
151
|
+
.mockReturnValueOnce(1_010)
|
|
152
|
+
.mockReturnValueOnce(1_040)
|
|
153
|
+
.mockReturnValueOnce(1_050);
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
await writeProtocolV2File({
|
|
157
|
+
commands: { typedCall } as any,
|
|
158
|
+
path: 'vol0:/firmware.bin',
|
|
159
|
+
data: new Uint8Array([1, 2, 3]),
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
expect(logSpy).toHaveBeenLastCalledWith(
|
|
163
|
+
'[FileWrite] metrics transport=unknown status=completed path=vol0:/firmware.bin bytes=3/3 elapsed=0.05s speed=0.06 KiB/s hostWriteTotal=0.03s responseWaitTotal=0.03s measuredAttempts=1'
|
|
164
|
+
);
|
|
165
|
+
} finally {
|
|
166
|
+
dateNowSpy.mockRestore();
|
|
167
|
+
logSpy.mockRestore();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('按确认分片的时间窗口记录实时传输速率', async () => {
|
|
172
|
+
const data = new Uint8Array(4097);
|
|
173
|
+
const typedCall = jest.fn().mockResolvedValue({ message: {} });
|
|
174
|
+
const onProgress = jest.fn();
|
|
175
|
+
const dateNowSpy = jest
|
|
176
|
+
.spyOn(Date, 'now')
|
|
177
|
+
.mockReturnValueOnce(1_000)
|
|
178
|
+
.mockReturnValueOnce(2_000)
|
|
179
|
+
.mockReturnValueOnce(3_000);
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
await writeProtocolV2File({
|
|
183
|
+
commands: { typedCall } as any,
|
|
184
|
+
path: 'vol1:/wallpapers/test.bin',
|
|
185
|
+
data,
|
|
186
|
+
onProgress,
|
|
187
|
+
});
|
|
188
|
+
} finally {
|
|
189
|
+
dateNowSpy.mockRestore();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
expect(onProgress).toHaveBeenNthCalledWith(
|
|
193
|
+
1,
|
|
194
|
+
expect.objectContaining({
|
|
195
|
+
transferredBytes: 4000,
|
|
196
|
+
rateBytesPerSecond: 4000,
|
|
197
|
+
elapsedMs: 1000,
|
|
198
|
+
})
|
|
199
|
+
);
|
|
200
|
+
expect(onProgress).toHaveBeenNthCalledWith(
|
|
201
|
+
2,
|
|
202
|
+
expect.objectContaining({
|
|
203
|
+
transferredBytes: 4097,
|
|
204
|
+
rateBytesPerSecond: 97,
|
|
205
|
+
elapsedMs: 2000,
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('通过 Core Log 每十秒输出一次 BLE 传输关键指标', async () => {
|
|
211
|
+
const log = getLogger(LoggerNames.Core);
|
|
212
|
+
const logSpy = jest.spyOn(log, 'log').mockImplementation(() => undefined);
|
|
213
|
+
const getSettingsSpy = jest
|
|
214
|
+
.spyOn(DataManager, 'getSettings')
|
|
215
|
+
.mockReturnValue('react-native' as any);
|
|
216
|
+
const isBleConnectSpy = jest.spyOn(DataManager, 'isBleConnect').mockReturnValue(true);
|
|
217
|
+
const data = new Uint8Array(5400);
|
|
218
|
+
const typedCall = jest.fn().mockResolvedValue({ message: {} });
|
|
219
|
+
const dateNowSpy = jest
|
|
220
|
+
.spyOn(Date, 'now')
|
|
221
|
+
.mockReturnValueOnce(1_000)
|
|
222
|
+
.mockReturnValueOnce(5_000)
|
|
223
|
+
.mockReturnValueOnce(11_000)
|
|
224
|
+
.mockReturnValueOnce(15_000);
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
await writeProtocolV2File({
|
|
228
|
+
commands: { typedCall } as any,
|
|
229
|
+
path: 'vol1:/wallpapers/test.bin',
|
|
230
|
+
data,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
expect(logSpy).toHaveBeenCalledTimes(3);
|
|
234
|
+
expect(logSpy).toHaveBeenNthCalledWith(
|
|
235
|
+
1,
|
|
236
|
+
'[FileWrite] started transport=BLE path=vol1:/wallpapers/test.bin bytes=5400 offset=0 chunk=1800'
|
|
237
|
+
);
|
|
238
|
+
expect(logSpy).toHaveBeenNthCalledWith(
|
|
239
|
+
2,
|
|
240
|
+
'[FileWrite] metrics transport=BLE status=progress path=vol1:/wallpapers/test.bin bytes=3600/5400 elapsed=10.00s speed=0.35 KiB/s'
|
|
241
|
+
);
|
|
242
|
+
expect(logSpy).toHaveBeenNthCalledWith(
|
|
243
|
+
3,
|
|
244
|
+
'[FileWrite] metrics transport=BLE status=completed path=vol1:/wallpapers/test.bin bytes=5400/5400 elapsed=14.00s speed=0.44 KiB/s'
|
|
245
|
+
);
|
|
246
|
+
} finally {
|
|
247
|
+
dateNowSpy.mockRestore();
|
|
248
|
+
getSettingsSpy.mockRestore();
|
|
249
|
+
isBleConnectSpy.mockRestore();
|
|
250
|
+
logSpy.mockRestore();
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('写入失败时通过 Core Log 输出已传输字节和平均速率', async () => {
|
|
255
|
+
const log = getLogger(LoggerNames.Core);
|
|
256
|
+
const logSpy = jest.spyOn(log, 'log').mockImplementation(() => undefined);
|
|
257
|
+
const typedCall = jest.fn().mockRejectedValue(new Error('write failed'));
|
|
258
|
+
const dateNowSpy = jest
|
|
259
|
+
.spyOn(Date, 'now')
|
|
260
|
+
.mockReturnValueOnce(1_000)
|
|
261
|
+
.mockReturnValueOnce(2_000);
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
await expect(
|
|
265
|
+
writeProtocolV2File({
|
|
266
|
+
commands: { typedCall } as any,
|
|
267
|
+
path: 'vol1:/wallpapers/test.bin',
|
|
268
|
+
data: new Uint8Array(4000),
|
|
269
|
+
})
|
|
270
|
+
).rejects.toThrow('write failed');
|
|
271
|
+
|
|
272
|
+
expect(logSpy).toHaveBeenNthCalledWith(
|
|
273
|
+
1,
|
|
274
|
+
'[FileWrite] started transport=unknown path=vol1:/wallpapers/test.bin bytes=4000 offset=0 chunk=4000'
|
|
275
|
+
);
|
|
276
|
+
expect(logSpy).toHaveBeenNthCalledWith(
|
|
277
|
+
2,
|
|
278
|
+
'[FileWrite] metrics transport=unknown status=failed path=vol1:/wallpapers/test.bin bytes=0/4000 elapsed=1.00s speed=0.00 KiB/s'
|
|
279
|
+
);
|
|
280
|
+
} finally {
|
|
281
|
+
dateNowSpy.mockRestore();
|
|
282
|
+
logSpy.mockRestore();
|
|
283
|
+
}
|
|
284
|
+
});
|
|
92
285
|
});
|
|
@@ -120,6 +120,69 @@ describe('ProtocolV2UiInteractionCoordinator', () => {
|
|
|
120
120
|
]);
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
test('emits a routable close for a progress-only Protocol V2 operation', () => {
|
|
124
|
+
const postMessage = jest.fn();
|
|
125
|
+
const interaction = {
|
|
126
|
+
interactionId: 'interaction-progress',
|
|
127
|
+
phaseId: 'interaction-progress:phase-1',
|
|
128
|
+
sequence: 1,
|
|
129
|
+
phase: 'processing',
|
|
130
|
+
transition: 'finish',
|
|
131
|
+
outcome: 'succeeded',
|
|
132
|
+
protocol: 'V2',
|
|
133
|
+
} as const;
|
|
134
|
+
const device = {
|
|
135
|
+
...createDevice(),
|
|
136
|
+
finishProtocolV2UiInteraction: jest.fn(() => interaction),
|
|
137
|
+
};
|
|
138
|
+
const coordinator = new ProtocolV2UiInteractionCoordinator(device as any, postMessage);
|
|
139
|
+
|
|
140
|
+
const emitted = coordinator.close({ ensureOperationClose: true });
|
|
141
|
+
|
|
142
|
+
expect(emitted).toBe(true);
|
|
143
|
+
expect(postMessage).toHaveBeenCalledWith({
|
|
144
|
+
event: 'UI_EVENT',
|
|
145
|
+
type: UI_REQUEST.CLOSE_UI_WINDOW,
|
|
146
|
+
payload: {
|
|
147
|
+
...interaction,
|
|
148
|
+
device: { connectId: 'pro2-test', deviceType: 'pro2' },
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('closes a known Protocol V2 operation after transport state is released', () => {
|
|
154
|
+
const postMessage = jest.fn();
|
|
155
|
+
const interaction = {
|
|
156
|
+
interactionId: 'interaction-released',
|
|
157
|
+
phaseId: 'interaction-released:phase-1',
|
|
158
|
+
sequence: 2,
|
|
159
|
+
phase: 'processing',
|
|
160
|
+
transition: 'finish',
|
|
161
|
+
outcome: 'succeeded',
|
|
162
|
+
protocol: 'V2',
|
|
163
|
+
} as const;
|
|
164
|
+
const device = {
|
|
165
|
+
...createDevice(false),
|
|
166
|
+
finishProtocolV2UiInteraction: jest.fn(() => interaction),
|
|
167
|
+
};
|
|
168
|
+
const coordinator = new ProtocolV2UiInteractionCoordinator(device as any, postMessage);
|
|
169
|
+
|
|
170
|
+
const emitted = coordinator.close({
|
|
171
|
+
ensureOperationClose: true,
|
|
172
|
+
protocolV2Operation: true,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(emitted).toBe(true);
|
|
176
|
+
expect(postMessage).toHaveBeenCalledWith({
|
|
177
|
+
event: 'UI_EVENT',
|
|
178
|
+
type: UI_REQUEST.CLOSE_UI_WINDOW,
|
|
179
|
+
payload: {
|
|
180
|
+
...interaction,
|
|
181
|
+
device: { connectId: 'pro2-test', deviceType: 'pro2' },
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
123
186
|
test('does not emit interaction events for methods without metadata such as Portfolio', () => {
|
|
124
187
|
const postMessage = jest.fn();
|
|
125
188
|
const coordinator = new ProtocolV2UiInteractionCoordinator(createDevice() as any, postMessage);
|
|
@@ -48,6 +48,7 @@ describe('public Pro2 API boundary', () => {
|
|
|
48
48
|
const api = createCoreApi(jest.fn() as CoreApi['call']) as Record<string, unknown>;
|
|
49
49
|
|
|
50
50
|
expect(api.deviceGetOnboardingStatus).toBeInstanceOf(Function);
|
|
51
|
+
expect(api.deviceUploadNft).toBeInstanceOf(Function);
|
|
51
52
|
expect(api.uploadPortfolio).toBeInstanceOf(Function);
|
|
52
53
|
expect(api.testProtocolV2Ping).toBeInstanceOf(Function);
|
|
53
54
|
expect(publicMethods.testProtocolV2Ping).toBeInstanceOf(Function);
|
|
@@ -42,7 +42,7 @@ describe('SearchDevices', () => {
|
|
|
42
42
|
mockIsBleConnect.mockReturnValue(false);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
test('
|
|
45
|
+
test('搜索忽略调用方协议并主动探测,单个无响应设备不阻断后续结果', async () => {
|
|
46
46
|
const unresponsiveDescriptor = {
|
|
47
47
|
path: 'stale-usb-device',
|
|
48
48
|
id: 'stale-usb-device',
|
|
@@ -74,6 +74,7 @@ describe('SearchDevices', () => {
|
|
|
74
74
|
id: 1,
|
|
75
75
|
payload: {
|
|
76
76
|
method: 'searchDevices',
|
|
77
|
+
connectProtocol: 'V2',
|
|
77
78
|
},
|
|
78
79
|
} as any);
|
|
79
80
|
method.init();
|
|
@@ -89,13 +90,21 @@ describe('SearchDevices', () => {
|
|
|
89
90
|
1,
|
|
90
91
|
[unresponsiveDescriptor],
|
|
91
92
|
unresponsiveDescriptor.path,
|
|
92
|
-
{
|
|
93
|
+
{
|
|
94
|
+
connectProtocol: undefined,
|
|
95
|
+
forceProtocolDetection: true,
|
|
96
|
+
refreshRuntimeState: true,
|
|
97
|
+
}
|
|
93
98
|
);
|
|
94
99
|
expect(mockGetDevices).toHaveBeenNthCalledWith(
|
|
95
100
|
2,
|
|
96
101
|
[availableDescriptor],
|
|
97
102
|
availableDescriptor.path,
|
|
98
|
-
{
|
|
103
|
+
{
|
|
104
|
+
connectProtocol: undefined,
|
|
105
|
+
forceProtocolDetection: true,
|
|
106
|
+
refreshRuntimeState: true,
|
|
107
|
+
}
|
|
99
108
|
);
|
|
100
109
|
});
|
|
101
110
|
|
|
@@ -44,7 +44,7 @@ describe('TronSignMessage legacy message validation', () => {
|
|
|
44
44
|
}
|
|
45
45
|
);
|
|
46
46
|
|
|
47
|
-
test('allows Protocol V2 message signing on Pro2', async () => {
|
|
47
|
+
test('allows Protocol V2 message signing on the Pro2 product family', async () => {
|
|
48
48
|
const method = new TronSignMessage({
|
|
49
49
|
id: 1,
|
|
50
50
|
payload: {
|
|
@@ -60,7 +60,7 @@ describe('TronSignMessage legacy message validation', () => {
|
|
|
60
60
|
method.device = {
|
|
61
61
|
commands: { typedCall },
|
|
62
62
|
getCurrentFirmwareVersionString: jest.fn(() => '0.0.0'),
|
|
63
|
-
getCurrentMethodVersionRange: jest.fn(selector => selector('
|
|
63
|
+
getCurrentMethodVersionRange: jest.fn(selector => selector('model_pro2')),
|
|
64
64
|
getCurrentFirmwareType: jest.fn(() => EFirmwareType.Universal),
|
|
65
65
|
} as unknown as Device;
|
|
66
66
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createUiMessage } from '../src/events';
|
|
2
|
+
import { UI_REQUEST } from '../src/events/ui-request';
|
|
3
|
+
import { createUiProgressMessageFilter } from '../src/utils/uiProgressThrottle';
|
|
4
|
+
|
|
5
|
+
import type { KnownDevice } from '../src/types';
|
|
6
|
+
|
|
7
|
+
describe('createUiProgressMessageFilter', () => {
|
|
8
|
+
let currentTime: number;
|
|
9
|
+
let shouldPostMessage: ReturnType<typeof createUiProgressMessageFilter>;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
currentTime = 1_000;
|
|
13
|
+
shouldPostMessage = createUiProgressMessageFilter(250, () => currentTime);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const firmwareProgress = (
|
|
17
|
+
progress: number,
|
|
18
|
+
progressType: 'transferData' | 'installingFirmware' = 'transferData'
|
|
19
|
+
) =>
|
|
20
|
+
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
21
|
+
device: {} as KnownDevice,
|
|
22
|
+
progress,
|
|
23
|
+
progressType,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('limits firmware progress to one event per interval', () => {
|
|
27
|
+
expect(shouldPostMessage(firmwareProgress(1))).toBe(true);
|
|
28
|
+
|
|
29
|
+
currentTime += 100;
|
|
30
|
+
expect(shouldPostMessage(firmwareProgress(1))).toBe(false);
|
|
31
|
+
|
|
32
|
+
currentTime += 150;
|
|
33
|
+
expect(shouldPostMessage(firmwareProgress(1))).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('limits transfer and install progress independently', () => {
|
|
37
|
+
expect(shouldPostMessage(firmwareProgress(1, 'transferData'))).toBe(true);
|
|
38
|
+
expect(shouldPostMessage(firmwareProgress(1, 'installingFirmware'))).toBe(true);
|
|
39
|
+
|
|
40
|
+
currentTime += 10;
|
|
41
|
+
expect(shouldPostMessage(firmwareProgress(2, 'transferData'))).toBe(false);
|
|
42
|
+
expect(shouldPostMessage(firmwareProgress(2, 'installingFirmware'))).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('emits phase boundaries immediately and suppresses duplicate boundaries', () => {
|
|
46
|
+
expect(shouldPostMessage(firmwareProgress(0))).toBe(true);
|
|
47
|
+
expect(shouldPostMessage(firmwareProgress(0))).toBe(false);
|
|
48
|
+
|
|
49
|
+
currentTime += 10;
|
|
50
|
+
expect(shouldPostMessage(firmwareProgress(50))).toBe(false);
|
|
51
|
+
expect(shouldPostMessage(firmwareProgress(100))).toBe(true);
|
|
52
|
+
expect(shouldPostMessage(firmwareProgress(100))).toBe(false);
|
|
53
|
+
|
|
54
|
+
expect(shouldPostMessage(firmwareProgress(0))).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('treats decreasing progress as a new phase', () => {
|
|
58
|
+
expect(shouldPostMessage(firmwareProgress(80))).toBe(true);
|
|
59
|
+
|
|
60
|
+
currentTime += 10;
|
|
61
|
+
expect(shouldPostMessage(firmwareProgress(20))).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('also limits device progress and leaves other UI events unchanged', () => {
|
|
65
|
+
const deviceProgress = (progress: number) =>
|
|
66
|
+
createUiMessage(UI_REQUEST.DEVICE_PROGRESS, { progress });
|
|
67
|
+
|
|
68
|
+
expect(shouldPostMessage(deviceProgress(1))).toBe(true);
|
|
69
|
+
currentTime += 10;
|
|
70
|
+
expect(shouldPostMessage(deviceProgress(2))).toBe(false);
|
|
71
|
+
|
|
72
|
+
expect(shouldPostMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW))).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createDeferred } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
consumeUiPromise,
|
|
5
|
+
findUiPromiseForResponse,
|
|
6
|
+
rejectUiPromises,
|
|
7
|
+
} from '../src/core/uiPromiseRegistry';
|
|
8
|
+
import { UI_RESPONSE } from '../src/events';
|
|
9
|
+
|
|
10
|
+
import type { UiPromise, UiPromiseResponse } from '../src/events';
|
|
11
|
+
|
|
12
|
+
const createPinPromise = (interactionId: string, deviceId: string) => {
|
|
13
|
+
const promise = createDeferred(UI_RESPONSE.RECEIVE_PIN) as UiPromise<
|
|
14
|
+
typeof UI_RESPONSE.RECEIVE_PIN
|
|
15
|
+
>;
|
|
16
|
+
promise.responseCorrelation = { interactionId, deviceId };
|
|
17
|
+
return promise;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const asRegistry = (promises: UiPromise<typeof UI_RESPONSE.RECEIVE_PIN>[]) =>
|
|
21
|
+
promises as UiPromise<UiPromiseResponse['type']>[];
|
|
22
|
+
|
|
23
|
+
describe('UI response promise correlation', () => {
|
|
24
|
+
test('consumes a rejected UI promise and normalizes its callback error', async () => {
|
|
25
|
+
const pending = createDeferred<string>();
|
|
26
|
+
const onFulfilled = jest.fn();
|
|
27
|
+
const onRejected = jest.fn();
|
|
28
|
+
|
|
29
|
+
consumeUiPromise(pending.promise, onFulfilled, onRejected);
|
|
30
|
+
pending.reject('cancelled' as unknown as Error);
|
|
31
|
+
await Promise.resolve();
|
|
32
|
+
|
|
33
|
+
expect(onFulfilled).not.toHaveBeenCalled();
|
|
34
|
+
expect(onRejected).toHaveBeenCalledWith(expect.any(Error));
|
|
35
|
+
expect(onRejected.mock.calls[0][0].message).toBe('cancelled');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('matches a sensitive response by type, interactionId and deviceId', () => {
|
|
39
|
+
const deviceA = createPinPromise('interaction-a', 'device-a');
|
|
40
|
+
const deviceB = createPinPromise('interaction-b', 'device-b');
|
|
41
|
+
|
|
42
|
+
expect(
|
|
43
|
+
findUiPromiseForResponse(asRegistry([deviceA, deviceB]), {
|
|
44
|
+
type: UI_RESPONSE.RECEIVE_PIN,
|
|
45
|
+
payload: '123',
|
|
46
|
+
interactionId: 'interaction-b',
|
|
47
|
+
deviceId: 'device-b',
|
|
48
|
+
})
|
|
49
|
+
).toBe(deviceB);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('does not match incomplete or incorrect correlation metadata', () => {
|
|
53
|
+
const pending = createPinPromise('interaction-a', 'device-a');
|
|
54
|
+
|
|
55
|
+
expect(
|
|
56
|
+
findUiPromiseForResponse(asRegistry([pending]), {
|
|
57
|
+
type: UI_RESPONSE.RECEIVE_PIN,
|
|
58
|
+
payload: '123',
|
|
59
|
+
interactionId: 'interaction-a',
|
|
60
|
+
})
|
|
61
|
+
).toBeUndefined();
|
|
62
|
+
expect(
|
|
63
|
+
findUiPromiseForResponse(asRegistry([pending]), {
|
|
64
|
+
type: UI_RESPONSE.RECEIVE_PIN,
|
|
65
|
+
payload: '123',
|
|
66
|
+
interactionId: 'interaction-a',
|
|
67
|
+
deviceId: 'device-b',
|
|
68
|
+
})
|
|
69
|
+
).toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('keeps legacy responses only when the sensitive candidate is unique', () => {
|
|
73
|
+
const deviceA = createPinPromise('interaction-a', 'device-a');
|
|
74
|
+
const deviceB = createPinPromise('interaction-b', 'device-b');
|
|
75
|
+
const legacyResponse = {
|
|
76
|
+
type: UI_RESPONSE.RECEIVE_PIN,
|
|
77
|
+
payload: '123',
|
|
78
|
+
} as const;
|
|
79
|
+
|
|
80
|
+
expect(findUiPromiseForResponse(asRegistry([deviceA]), legacyResponse)).toBe(deviceA);
|
|
81
|
+
expect(
|
|
82
|
+
findUiPromiseForResponse(asRegistry([deviceA, deviceB]), legacyResponse)
|
|
83
|
+
).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('applies the same exact matching to passphrase responses', () => {
|
|
87
|
+
const promise = createDeferred(UI_RESPONSE.RECEIVE_PASSPHRASE) as UiPromise<
|
|
88
|
+
typeof UI_RESPONSE.RECEIVE_PASSPHRASE
|
|
89
|
+
>;
|
|
90
|
+
promise.responseCorrelation = {
|
|
91
|
+
interactionId: 'passphrase-interaction',
|
|
92
|
+
deviceId: 'device-a',
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
expect(
|
|
96
|
+
findUiPromiseForResponse([promise] as UiPromise<UiPromiseResponse['type']>[], {
|
|
97
|
+
type: UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
98
|
+
payload: { value: 'redacted' },
|
|
99
|
+
interactionId: 'passphrase-interaction',
|
|
100
|
+
deviceId: 'device-a',
|
|
101
|
+
})
|
|
102
|
+
).toBe(promise);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('rejects every pending UI promise removed during cleanup', async () => {
|
|
106
|
+
const deviceA = createPinPromise('interaction-a', 'device-a');
|
|
107
|
+
const deviceB = createPinPromise('interaction-b', 'device-b');
|
|
108
|
+
const cancellation = new Error('UI request was cancelled');
|
|
109
|
+
|
|
110
|
+
rejectUiPromises(asRegistry([deviceA, deviceB]), cancellation);
|
|
111
|
+
|
|
112
|
+
await expect(deviceA.promise).rejects.toBe(cancellation);
|
|
113
|
+
await expect(deviceB.promise).rejects.toBe(cancellation);
|
|
114
|
+
});
|
|
115
|
+
});
|
package/dist/api/BaseMethod.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
2
|
import { type ProtocolType } from '@onekeyfe/hd-transport';
|
|
3
|
-
import { type UnlockPolicy } from '../protocols/protocol-v2/unlockPolicy';
|
|
4
3
|
import type { Device } from '../device/Device';
|
|
5
4
|
import type DeviceConnector from '../device/DeviceConnector';
|
|
6
5
|
import type { DeviceFirmwareRange } from '../types';
|
|
7
6
|
import type { CoreMessage } from '../events';
|
|
7
|
+
import type { UnlockPolicy } from '../protocols/protocol-v2/unlockPolicy';
|
|
8
8
|
import type { ProtocolV2InteractionDescriptor } from '../protocols/protocol-v2/uiInteraction';
|
|
9
|
+
import type { ProtocolV2UnlockContext } from '../protocols/protocol-v2/unlockPolicyRunner';
|
|
9
10
|
import type { RequestContext } from '../utils/tracing';
|
|
10
11
|
import type { CoreContext } from '../core';
|
|
11
12
|
export type { UnlockPolicy } from '../protocols/protocol-v2/unlockPolicy';
|
|
@@ -37,6 +38,7 @@ export declare abstract class BaseMethod<Params = undefined> {
|
|
|
37
38
|
getPreWarmKey(): string;
|
|
38
39
|
strictCheckDeviceSupport: boolean;
|
|
39
40
|
unlockPolicy: UnlockPolicy;
|
|
41
|
+
protocolV2UnlockContext?: ProtocolV2UnlockContext;
|
|
40
42
|
getSupportedProtocols(): readonly ProtocolType[];
|
|
41
43
|
supportsProtocol(protocol: ProtocolType): boolean;
|
|
42
44
|
assertProtocolSupported(protocol: ProtocolType, firmwareType: EFirmwareType): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseMethod.d.ts","sourceRoot":"","sources":["../../src/api/BaseMethod.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseMethod.d.ts","sourceRoot":"","sources":["../../src/api/BaseMethod.ts"],"names":[],"mappings":"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"}
|
|
@@ -13,12 +13,14 @@ type ProtocolV2FirmwareReleasePlan = {
|
|
|
13
13
|
targetsToUpdate: FirmwareUpdateV4Target[];
|
|
14
14
|
release: IFirmwareReleaseInfo | undefined;
|
|
15
15
|
};
|
|
16
|
-
export declare function buildProtocolV2FirmwareRelease({ currentVersions, currentVerification, remotePayloadHashes, firmwareType, release, }: {
|
|
16
|
+
export declare function buildProtocolV2FirmwareRelease({ currentVersions, currentVerification, checkFirmwareHash, remotePayloadHashes, firmwareType, release, deviceType, }: {
|
|
17
17
|
currentVersions: DeviceStateVersions;
|
|
18
18
|
currentVerification?: Partial<DeviceFeaturesVerify>;
|
|
19
|
+
checkFirmwareHash?: boolean;
|
|
19
20
|
remotePayloadHashes?: Readonly<Record<string, string | null>>;
|
|
20
21
|
firmwareType: EFirmwareType;
|
|
21
22
|
release: IFirmwareReleaseInfo | undefined;
|
|
23
|
+
deviceType?: 'pro2' | 'neo';
|
|
22
24
|
}): ProtocolV2FirmwareReleasePlan;
|
|
23
25
|
export default class CheckAllFirmwareRelease extends BaseMethod {
|
|
24
26
|
getSupportedProtocols(): readonly ["V1", "V2"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckAllFirmwareRelease.d.ts","sourceRoot":"","sources":["../../src/api/CheckAllFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"CheckAllFirmwareRelease.d.ts","sourceRoot":"","sources":["../../src/api/CheckAllFirmwareRelease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,aAAa,EAA6B,MAAM,qBAAqB,CAAC;AAY5F,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,OAAO,KAAK,EACV,kBAAkB,EAElB,kCAAkC,EAClC,+BAA+B,EAChC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EAGrB,MAAM,UAAU,CAAC;AA+HlB,KAAK,6BAA6B,GAAG;IACnC,YAAY,EAAE,aAAa,CAAC;IAC5B,MAAM,EAAE,+BAA+B,CAAC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,mBAAmB,CAAC;IACrC,UAAU,EAAE,kCAAkC,EAAE,CAAC;IACjD,eAAe,EAAE,sBAAsB,EAAE,CAAC;IAC1C,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAAC;CAC3C,CAAC;AAEF,wBAAgB,8BAA8B,CAAC,EAC7C,eAAe,EACf,mBAAwB,EACxB,iBAAyB,EACzB,mBAAwB,EACxB,YAAY,EACZ,OAAO,EACP,UAAU,GACX,EAAE;IACD,eAAe,EAAE,mBAAmB,CAAC;IACrC,mBAAmB,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACpD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,mBAAmB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;IAC9D,YAAY,EAAE,aAAa,CAAC;IAC5B,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC7B,GAAG,6BAA6B,CAiFhC;AAED,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,UAAU;IAC7D,qBAAqB;IAIrB,IAAI;IAME,GAAG;YAuDK,aAAa;CA4F5B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
export default class DetectDeviceConnectProtocol extends BaseMethod {
|
|
3
|
+
init(): void;
|
|
4
|
+
getSupportedProtocols(): readonly ["V1", "V2"];
|
|
5
|
+
run(): Promise<"V1" | "V2">;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=DetectDeviceConnectProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DetectDeviceConnectProtocol.d.ts","sourceRoot":"","sources":["../../src/api/DetectDeviceConnectProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,UAAU;IACjE,IAAI;IAOJ,qBAAqB;IAIrB,GAAG;CAGJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirmwareUpdate.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdate.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"FirmwareUpdate.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdate.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAW1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,KAAK,MAAM,GAAG;IACZ,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,UAAU,GAAG,KAAK,CAAC;CAChC,CAAC;AAIF,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,UAAU,CAAC,MAAM,CAAC;IAC5D,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,IAAI;IAgCJ,cAAc,YAAa,MAAM,UAS/B;IAEF,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IA0D/C,GAAG;CA+FV"}
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import { type Deferred, type EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
2
|
import { BaseMethod } from './BaseMethod';
|
|
3
3
|
import type { Features } from '../types';
|
|
4
|
-
import type { FirmwareArtifactReader, FirmwareArtifactReference } from '../types/api/firmwareUpdate';
|
|
5
|
-
import type { FirmwareUpdatePreparedPlan } from '../types/api/firmwareUpdatePreparedPlan';
|
|
6
4
|
type Params = {
|
|
7
5
|
binary?: ArrayBuffer;
|
|
8
|
-
artifact?: FirmwareArtifactReference;
|
|
9
|
-
resourceEntries?: Array<{
|
|
10
|
-
entryName: string;
|
|
11
|
-
artifact: FirmwareArtifactReference;
|
|
12
|
-
}>;
|
|
13
|
-
artifactReader?: FirmwareArtifactReader;
|
|
14
|
-
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
15
|
-
platform?: FirmwareUpdatePreparedPlan['platform'];
|
|
16
6
|
version?: number[];
|
|
17
7
|
updateType: 'firmware' | 'ble';
|
|
18
8
|
forcedUpdateRes?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirmwareUpdateV2.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EAEb,KAAK,aAAa,EAKnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"FirmwareUpdateV2.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EAEb,KAAK,aAAa,EAKnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAW1C,OAAO,KAAK,EAAE,QAAQ,EAAe,MAAM,UAAU,CAAC;AAGtD,KAAK,MAAM,GAAG;IACZ,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,UAAU,GAAG,KAAK,CAAC;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B,CAAC;AA2EF,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU,CAAC,MAAM,CAAC;IAC9D,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,IAAI;IA6CJ,cAAc,YAAa,MAAM,UAS/B;YAEY,qCAAqC;IAkBnD,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;YAmFvC,4BAA4B;IAyB1C,qBAAqB;IAUrB,uBAAuB,CAAC,UAAU,EAAE,MAAM;IAc1C,gCAAgC,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAAE,YAAY,EAAE,aAAa;IAwBtF,GAAG;CAwJV"}
|