@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,89 +0,0 @@
|
|
|
1
|
-
import { createCoreApi, createProtocolAwareCall } from '../src/inject';
|
|
2
|
-
|
|
3
|
-
import type { CoreApi } from '../src/types/api';
|
|
4
|
-
|
|
5
|
-
describe('SDK protocol binding', () => {
|
|
6
|
-
test('exposes a minimal API that returns the actively detected protocol', async () => {
|
|
7
|
-
const response = { success: true as const, payload: 'V2' as const };
|
|
8
|
-
const rawCall = jest.fn().mockResolvedValue(response);
|
|
9
|
-
const api = createCoreApi(rawCall as CoreApi['call']);
|
|
10
|
-
|
|
11
|
-
await expect(api.detectDeviceConnectProtocol('USB_DEVICE_A')).resolves.toBe(response);
|
|
12
|
-
expect(rawCall).toHaveBeenCalledWith({
|
|
13
|
-
connectId: 'USB_DEVICE_A',
|
|
14
|
-
forceProtocolDetection: true,
|
|
15
|
-
method: 'detectDeviceConnectProtocol',
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('injects a strict protocol into every later call and isolates devices', async () => {
|
|
20
|
-
const rawCall = jest.fn(params => Promise.resolve({ success: true, payload: params }));
|
|
21
|
-
const protocolAwareCall = createProtocolAwareCall(rawCall as CoreApi['call']);
|
|
22
|
-
const api = createCoreApi(protocolAwareCall.call);
|
|
23
|
-
|
|
24
|
-
protocolAwareCall.setDeviceConnectProtocol('USB_DEVICE_A', 'V2');
|
|
25
|
-
protocolAwareCall.setDeviceConnectProtocol('ble-device-b', 'V1');
|
|
26
|
-
|
|
27
|
-
await api.deviceWipe('usb_device_a');
|
|
28
|
-
await api.deviceSupportFeatures('BLE-DEVICE-B');
|
|
29
|
-
await api.getFeatures('USB_DEVICE_A', { connectProtocol: 'V1' });
|
|
30
|
-
await api.getDeviceState('USB_DEVICE_A', { forceProtocolDetection: true });
|
|
31
|
-
await protocolAwareCall.call({
|
|
32
|
-
connectId: 'USB_DEVICE_A',
|
|
33
|
-
method: 'deviceUpdateReboot',
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
expect(rawCall).toHaveBeenNthCalledWith(1, {
|
|
37
|
-
connectId: 'usb_device_a',
|
|
38
|
-
method: 'deviceWipe',
|
|
39
|
-
connectProtocol: 'V2',
|
|
40
|
-
});
|
|
41
|
-
expect(rawCall).toHaveBeenNthCalledWith(2, {
|
|
42
|
-
connectId: 'BLE-DEVICE-B',
|
|
43
|
-
method: 'deviceSupportFeatures',
|
|
44
|
-
connectProtocol: 'V1',
|
|
45
|
-
});
|
|
46
|
-
expect(rawCall).toHaveBeenNthCalledWith(3, {
|
|
47
|
-
connectId: 'USB_DEVICE_A',
|
|
48
|
-
method: 'getFeatures',
|
|
49
|
-
connectProtocol: 'V1',
|
|
50
|
-
});
|
|
51
|
-
expect(rawCall).toHaveBeenNthCalledWith(4, {
|
|
52
|
-
connectId: 'USB_DEVICE_A',
|
|
53
|
-
method: 'getDeviceState',
|
|
54
|
-
forceProtocolDetection: true,
|
|
55
|
-
});
|
|
56
|
-
expect(rawCall).toHaveBeenNthCalledWith(5, {
|
|
57
|
-
connectId: 'USB_DEVICE_A',
|
|
58
|
-
method: 'deviceUpdateReboot',
|
|
59
|
-
connectProtocol: 'V2',
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('keeps bindings local to one SDK instance and supports clearing them', async () => {
|
|
64
|
-
const firstRawCall = jest.fn(() => Promise.resolve({ success: true, payload: {} }));
|
|
65
|
-
const secondRawCall = jest.fn(() => Promise.resolve({ success: true, payload: {} }));
|
|
66
|
-
const first = createProtocolAwareCall(firstRawCall as CoreApi['call']);
|
|
67
|
-
const second = createProtocolAwareCall(secondRawCall as CoreApi['call']);
|
|
68
|
-
|
|
69
|
-
first.setDeviceConnectProtocol('same-device', 'V2');
|
|
70
|
-
await first.call({ connectId: 'same-device', method: 'deviceWipe' });
|
|
71
|
-
await second.call({ connectId: 'same-device', method: 'deviceWipe' });
|
|
72
|
-
first.setDeviceConnectProtocol('same-device', undefined);
|
|
73
|
-
await first.call({ connectId: 'same-device', method: 'deviceWipe' });
|
|
74
|
-
|
|
75
|
-
expect(firstRawCall).toHaveBeenNthCalledWith(1, {
|
|
76
|
-
connectId: 'same-device',
|
|
77
|
-
method: 'deviceWipe',
|
|
78
|
-
connectProtocol: 'V2',
|
|
79
|
-
});
|
|
80
|
-
expect(secondRawCall).toHaveBeenCalledWith({
|
|
81
|
-
connectId: 'same-device',
|
|
82
|
-
method: 'deviceWipe',
|
|
83
|
-
});
|
|
84
|
-
expect(firstRawCall).toHaveBeenNthCalledWith(2, {
|
|
85
|
-
connectId: 'same-device',
|
|
86
|
-
method: 'deviceWipe',
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { sha256 } from '@noble/hashes/sha256';
|
|
3
|
-
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
4
|
-
|
|
5
|
-
import { DataManager } from '../src/data-manager';
|
|
6
|
-
import {
|
|
7
|
-
PROTOCOL_V2_RESOURCE_DEVICE_PATHS,
|
|
8
|
-
PROTOCOL_V2_RESOURCE_TYPES,
|
|
9
|
-
buildProtocolV2ResourceUpdatePlan,
|
|
10
|
-
isProtocolV2ResourceFileValid,
|
|
11
|
-
parseProtocolV2Resources,
|
|
12
|
-
readProtocolV2ResourceInventory,
|
|
13
|
-
} from '../src/protocols/protocol-v2/resources';
|
|
14
|
-
|
|
15
|
-
import type {
|
|
16
|
-
ConnectSettings,
|
|
17
|
-
IProtocolV2BootResources,
|
|
18
|
-
IProtocolV2Resource,
|
|
19
|
-
RemoteConfigResponse,
|
|
20
|
-
} from '../src/types';
|
|
21
|
-
|
|
22
|
-
jest.mock('axios');
|
|
23
|
-
jest.mock('../src/data/config', () => ({
|
|
24
|
-
getSDKVersion: jest.fn(() => '1.0.0-test'),
|
|
25
|
-
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0-test/',
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
const bytesToHex = (bytes: Uint8Array) =>
|
|
29
|
-
Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
30
|
-
|
|
31
|
-
const PROTOCOL_V2_OKPP_HEADER_SIZE = 0x52a0;
|
|
32
|
-
|
|
33
|
-
const createResourceHeader = (headerHash: string) => {
|
|
34
|
-
const header = new Uint8Array(PROTOCOL_V2_OKPP_HEADER_SIZE);
|
|
35
|
-
const view = new DataView(header.buffer);
|
|
36
|
-
'OKPP'.split('').forEach((char, index) => {
|
|
37
|
-
header[index] = char.charCodeAt(0);
|
|
38
|
-
});
|
|
39
|
-
'RESC'.split('').forEach((char, index) => {
|
|
40
|
-
header[0x08 + index] = char.charCodeAt(0);
|
|
41
|
-
});
|
|
42
|
-
view.setUint32(0x0c, header.byteLength, true);
|
|
43
|
-
for (let index = 0; index < headerHash.length / 2; index++) {
|
|
44
|
-
header[0x240 + index] = Number.parseInt(headerHash.slice(index * 2, index * 2 + 2), 16);
|
|
45
|
-
}
|
|
46
|
-
return header;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const resources: IProtocolV2Resource[] = PROTOCOL_V2_RESOURCE_TYPES.map((type, index) => ({
|
|
50
|
-
type,
|
|
51
|
-
url: `https://example.com/${type}.okpkg`,
|
|
52
|
-
size: index + 100,
|
|
53
|
-
fileHash: index.toString(16).padStart(64, '0'),
|
|
54
|
-
headerHash: index.toString(16).padStart(128, '0'),
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
const bootResources: IProtocolV2BootResources = {
|
|
58
|
-
required: false,
|
|
59
|
-
target: 'RES',
|
|
60
|
-
manifestUrl: 'https://example.com/manifest.json',
|
|
61
|
-
files: [
|
|
62
|
-
{
|
|
63
|
-
name: 'bootloader_crest.bin',
|
|
64
|
-
url: 'https://example.com/assets/bootloader_crest.bin',
|
|
65
|
-
devicePath: 'vol0:/assets/loaders/boot.staging/graphics/bootloader_crest.bin',
|
|
66
|
-
size: 1234,
|
|
67
|
-
fileHash: 'ab'.repeat(32),
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const createSettings = (configFetcher: ConnectSettings['configFetcher']): ConnectSettings =>
|
|
73
|
-
({
|
|
74
|
-
env: 'node',
|
|
75
|
-
fetchConfig: true,
|
|
76
|
-
preRelease: true,
|
|
77
|
-
configFetcher,
|
|
78
|
-
} as ConnectSettings);
|
|
79
|
-
|
|
80
|
-
const createRemoteConfig = (): RemoteConfigResponse =>
|
|
81
|
-
({
|
|
82
|
-
classic: { firmware: [], ble: [] },
|
|
83
|
-
classic1s: { firmware: [], ble: [] },
|
|
84
|
-
classicpure: { firmware: [], ble: [] },
|
|
85
|
-
mini: { firmware: [], ble: [] },
|
|
86
|
-
touch: { firmware: [], ble: [] },
|
|
87
|
-
pro: { firmware: [], ble: [] },
|
|
88
|
-
pro2: { firmware: [], ble: [], resources: { stable: resources, boot: bootResources } },
|
|
89
|
-
bridge: {},
|
|
90
|
-
} as unknown as RemoteConfigResponse);
|
|
91
|
-
|
|
92
|
-
describe('Pro2 resource configuration', () => {
|
|
93
|
-
beforeEach(() => {
|
|
94
|
-
jest.clearAllMocks();
|
|
95
|
-
DataManager.lastCheckTimestamp = 0;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('accepts exactly six resources and normalizes their deterministic order', () => {
|
|
99
|
-
const parsed = parseProtocolV2Resources({
|
|
100
|
-
stable: [...resources].reverse(),
|
|
101
|
-
boot: bootResources,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
expect(parsed?.stable.map(item => item.type)).toEqual(PROTOCOL_V2_RESOURCE_TYPES);
|
|
105
|
-
expect(parsed?.boot).toEqual(bootResources);
|
|
106
|
-
expect(PROTOCOL_V2_RESOURCE_DEVICE_PATHS.translations).toBe(
|
|
107
|
-
'vol0:/bundles/translations/translations.okpkg'
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('rejects incomplete, duplicate, or malformed stable sets', () => {
|
|
112
|
-
expect(() => parseProtocolV2Resources({ stable: resources.slice(1) })).toThrow(
|
|
113
|
-
'six unique resource types'
|
|
114
|
-
);
|
|
115
|
-
expect(() =>
|
|
116
|
-
parseProtocolV2Resources({ stable: [...resources.slice(0, 5), resources[0]] })
|
|
117
|
-
).toThrow('six unique resource types');
|
|
118
|
-
expect(() =>
|
|
119
|
-
parseProtocolV2Resources({
|
|
120
|
-
stable: resources.map((resource, index) =>
|
|
121
|
-
index === 0 ? { ...resource, headerHash: 'bad' } : resource
|
|
122
|
-
),
|
|
123
|
-
})
|
|
124
|
-
).toThrow('headerHash');
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('requires boot resources to remain optional and use RES file entries', () => {
|
|
128
|
-
expect(() =>
|
|
129
|
-
parseProtocolV2Resources({
|
|
130
|
-
stable: resources,
|
|
131
|
-
boot: { ...bootResources, required: true },
|
|
132
|
-
})
|
|
133
|
-
).toThrow('required flag');
|
|
134
|
-
expect(() =>
|
|
135
|
-
parseProtocolV2Resources({
|
|
136
|
-
stable: resources,
|
|
137
|
-
boot: { ...bootResources, target: 'INVALID' },
|
|
138
|
-
})
|
|
139
|
-
).toThrow('expected RES');
|
|
140
|
-
expect(() =>
|
|
141
|
-
parseProtocolV2Resources({
|
|
142
|
-
stable: resources,
|
|
143
|
-
boot: {
|
|
144
|
-
...bootResources,
|
|
145
|
-
files: [{ ...bootResources.files[0], devicePath: '../outside.bin' }],
|
|
146
|
-
},
|
|
147
|
-
})
|
|
148
|
-
).toThrow('devicePath');
|
|
149
|
-
|
|
150
|
-
for (const devicePath of [
|
|
151
|
-
'vol0:/assets/loaders\\bootloader_crest.bin',
|
|
152
|
-
'vol0:/assets/loaders\\\\bootloader_crest.bin',
|
|
153
|
-
]) {
|
|
154
|
-
expect(() =>
|
|
155
|
-
parseProtocolV2Resources({
|
|
156
|
-
stable: resources,
|
|
157
|
-
boot: {
|
|
158
|
-
...bootResources,
|
|
159
|
-
files: [{ ...bootResources.files[0], devicePath }],
|
|
160
|
-
},
|
|
161
|
-
})
|
|
162
|
-
).toThrow('devicePath');
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test('downloads nothing when all resource identities match', () => {
|
|
167
|
-
const inventory = resources.map(({ type, size, headerHash }) => ({ type, size, headerHash }));
|
|
168
|
-
|
|
169
|
-
expect(
|
|
170
|
-
buildProtocolV2ResourceUpdatePlan({ resources, inventory, mode: 'application' })
|
|
171
|
-
).toEqual({ status: 'valid', resources: [] });
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test('builds inventory from existing filesystem calls without ResourceInventoryGet', async () => {
|
|
175
|
-
const installedResources = resources.map((resource, index) => ({
|
|
176
|
-
...resource,
|
|
177
|
-
size: PROTOCOL_V2_OKPP_HEADER_SIZE + index + 1,
|
|
178
|
-
}));
|
|
179
|
-
const resourceByPath = new Map(
|
|
180
|
-
installedResources.map(resource => [
|
|
181
|
-
PROTOCOL_V2_RESOURCE_DEVICE_PATHS[resource.type],
|
|
182
|
-
resource,
|
|
183
|
-
])
|
|
184
|
-
);
|
|
185
|
-
const typedCall = jest.fn(
|
|
186
|
-
(requestType: string, _responseType: string, payload: Record<string, any>) => {
|
|
187
|
-
if (requestType === 'ResourceInventoryGet') {
|
|
188
|
-
throw new Error('ResourceInventoryGet is unavailable on released firmware');
|
|
189
|
-
}
|
|
190
|
-
if (requestType === 'FilesystemPathInfoQuery') {
|
|
191
|
-
const resource = resourceByPath.get(payload.path);
|
|
192
|
-
return {
|
|
193
|
-
message: {
|
|
194
|
-
exist: Boolean(resource),
|
|
195
|
-
directory: false,
|
|
196
|
-
size: resource?.size ?? 0,
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
if (requestType === 'FilesystemFileRead') {
|
|
201
|
-
const resource = resourceByPath.get(payload.file.path);
|
|
202
|
-
if (!resource) throw new Error('missing resource');
|
|
203
|
-
const header = createResourceHeader(resource.headerHash);
|
|
204
|
-
const offset = Number(payload.file.offset);
|
|
205
|
-
const chunkLength = Number(payload.chunk_len);
|
|
206
|
-
return {
|
|
207
|
-
message: {
|
|
208
|
-
data: header.slice(offset, offset + chunkLength),
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
throw new Error(`Unexpected request: ${requestType}`);
|
|
213
|
-
}
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
await expect(
|
|
217
|
-
readProtocolV2ResourceInventory({
|
|
218
|
-
commands: { typedCall },
|
|
219
|
-
resources: installedResources,
|
|
220
|
-
chunkSize: 4000,
|
|
221
|
-
})
|
|
222
|
-
).resolves.toEqual(
|
|
223
|
-
installedResources.map(({ type, size, headerHash }) => ({ type, size, headerHash }))
|
|
224
|
-
);
|
|
225
|
-
expect(typedCall.mock.calls.some(call => call[0] === 'ResourceInventoryGet')).toBe(false);
|
|
226
|
-
expect(typedCall.mock.calls.filter(call => call[0] === 'FilesystemPathInfoQuery')).toHaveLength(
|
|
227
|
-
6
|
|
228
|
-
);
|
|
229
|
-
expect(typedCall.mock.calls.some(call => call[0] === 'FilesystemFileRead')).toBe(true);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
test('selects only the changed or missing resource in application mode', () => {
|
|
233
|
-
const inventory = resources
|
|
234
|
-
.filter(resource => resource.type !== 'noto')
|
|
235
|
-
.map(({ type, size, headerHash }) => ({
|
|
236
|
-
type,
|
|
237
|
-
size: type === 'images' ? size + 1 : size,
|
|
238
|
-
headerHash,
|
|
239
|
-
}));
|
|
240
|
-
|
|
241
|
-
const result = buildProtocolV2ResourceUpdatePlan({
|
|
242
|
-
resources,
|
|
243
|
-
inventory,
|
|
244
|
-
mode: 'application',
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
expect(result.status).toBe('outdated');
|
|
248
|
-
expect(result.resources.map(resource => resource.type)).toEqual(['images', 'noto']);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
test('reports unknown without an application inventory and selects all in recovery mode', () => {
|
|
252
|
-
expect(buildProtocolV2ResourceUpdatePlan({ resources, mode: 'application' })).toEqual({
|
|
253
|
-
status: 'unknown',
|
|
254
|
-
resources: [],
|
|
255
|
-
});
|
|
256
|
-
expect(
|
|
257
|
-
buildProtocolV2ResourceUpdatePlan({ resources, mode: 'bootloader-recovery' }).resources
|
|
258
|
-
).toHaveLength(6);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test('uses a filesystem inventory for incremental recovery mode updates', () => {
|
|
262
|
-
const inventory = resources.slice(1).map(({ type, size, headerHash }) => ({
|
|
263
|
-
type,
|
|
264
|
-
size,
|
|
265
|
-
headerHash,
|
|
266
|
-
}));
|
|
267
|
-
|
|
268
|
-
expect(
|
|
269
|
-
buildProtocolV2ResourceUpdatePlan({
|
|
270
|
-
resources,
|
|
271
|
-
inventory,
|
|
272
|
-
mode: 'bootloader-recovery',
|
|
273
|
-
}).resources.map(resource => resource.type)
|
|
274
|
-
).toEqual(['images']);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
test('verifies both full file size and SHA-256 before transfer', () => {
|
|
278
|
-
const bytes = new Uint8Array([1, 2, 3]);
|
|
279
|
-
const binary = bytes.buffer;
|
|
280
|
-
const identity = { size: bytes.byteLength, fileHash: bytesToHex(sha256(bytes)) };
|
|
281
|
-
|
|
282
|
-
expect(isProtocolV2ResourceFileValid(binary, identity)).toBe(true);
|
|
283
|
-
expect(isProtocolV2ResourceFileValid(binary, { ...identity, size: 4 })).toBe(false);
|
|
284
|
-
expect(isProtocolV2ResourceFileValid(binary, { ...identity, fileHash: '0'.repeat(64) })).toBe(
|
|
285
|
-
false
|
|
286
|
-
);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
test('applies a validated pre-release config and exposes the stable resource set', async () => {
|
|
290
|
-
const configFetcher = jest.fn().mockResolvedValue(createRemoteConfig());
|
|
291
|
-
|
|
292
|
-
await expect(DataManager.load(createSettings(configFetcher))).resolves.toBe(true);
|
|
293
|
-
|
|
294
|
-
expect(configFetcher).toHaveBeenCalledWith(
|
|
295
|
-
expect.stringMatching(/^https:\/\/data\.onekey\.so\/pre-config\.json\?noCache=/)
|
|
296
|
-
);
|
|
297
|
-
expect(DataManager.getProtocolV2Resources()).toEqual(resources);
|
|
298
|
-
expect(DataManager.getProtocolV2BootResources()).toEqual(bootResources);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
test('keeps base SDK initialization available when remote Pro2 resources are invalid', async () => {
|
|
302
|
-
const remoteConfig = createRemoteConfig();
|
|
303
|
-
(remoteConfig.pro2 as { resources?: unknown }).resources = { stable: [] };
|
|
304
|
-
const configFetcher = jest.fn().mockResolvedValue(remoteConfig);
|
|
305
|
-
|
|
306
|
-
await expect(DataManager.load(createSettings(configFetcher))).resolves.toBe(true);
|
|
307
|
-
|
|
308
|
-
expect(DataManager.getProtocolV2Resources()).toBeUndefined();
|
|
309
|
-
expect(DataManager.getProtocolV2BootResources()).toBeUndefined();
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
test('only blocks resource mutation when the refreshed Pro2 resources are invalid', async () => {
|
|
313
|
-
const remoteConfig = createRemoteConfig();
|
|
314
|
-
(remoteConfig.pro2 as { resources?: unknown }).resources = { stable: [] };
|
|
315
|
-
const settings = createSettings(jest.fn().mockResolvedValue(remoteConfig));
|
|
316
|
-
DataManager.settings = settings;
|
|
317
|
-
|
|
318
|
-
await expect(DataManager.forceReloadData()).resolves.toBeUndefined();
|
|
319
|
-
await expect(DataManager.forceReloadData({ requireResources: true })).rejects.toMatchObject({
|
|
320
|
-
errorCode: HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
321
|
-
message: expect.stringContaining('Invalid Pro2 resources config'),
|
|
322
|
-
});
|
|
323
|
-
expect(DataManager.lastCheckTimestamp).toBeGreaterThan(0);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
test('does not advance the cache timestamp when refresh fails', async () => {
|
|
327
|
-
jest.spyOn(axios, 'get').mockRejectedValue(new Error('offline'));
|
|
328
|
-
const settings = createSettings(jest.fn().mockResolvedValue(null));
|
|
329
|
-
DataManager.settings = settings;
|
|
330
|
-
|
|
331
|
-
await DataManager.checkAndReloadData();
|
|
332
|
-
|
|
333
|
-
expect(DataManager.lastCheckTimestamp).toBe(0);
|
|
334
|
-
await expect(DataManager.forceReloadData()).rejects.toMatchObject({
|
|
335
|
-
errorCode: HardwareErrorCode.NetworkError,
|
|
336
|
-
message: 'Unable to refresh the latest remote config',
|
|
337
|
-
});
|
|
338
|
-
expect(DataManager.lastCheckTimestamp).toBe(0);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
|
-
|
|
3
|
-
import { DEVICE } from '../src/events';
|
|
4
|
-
import { Device } from '../src/device/Device';
|
|
5
|
-
|
|
6
|
-
jest.mock('../src/data/config', () => ({
|
|
7
|
-
getSDKVersion: jest.fn(() => '1.0.0-test'),
|
|
8
|
-
DEFAULT_DOMAIN: 'https://example.com/',
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
describe('Protocol V2 UI interaction lifecycle', () => {
|
|
12
|
-
test('synthesizes finish metadata for a progress-only operation', () => {
|
|
13
|
-
const device = new Device({ id: 'connect-progress' } as any);
|
|
14
|
-
device.isProtocolV2 = jest.fn(() => true);
|
|
15
|
-
device.beginProtocolV2UiInteraction();
|
|
16
|
-
|
|
17
|
-
const metadata = device.finishProtocolV2UiInteraction('succeeded', {
|
|
18
|
-
ensureMetadata: true,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
expect(metadata).toMatchObject({
|
|
22
|
-
phase: 'processing',
|
|
23
|
-
transition: 'finish',
|
|
24
|
-
outcome: 'succeeded',
|
|
25
|
-
protocol: 'V2',
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('keeps finish metadata after the Protocol V2 transport is released', () => {
|
|
30
|
-
const device = new Device({ id: 'connect-released' } as any);
|
|
31
|
-
const isProtocolV2 = jest.fn().mockReturnValueOnce(true).mockReturnValue(false);
|
|
32
|
-
device.isProtocolV2 = isProtocolV2;
|
|
33
|
-
device.beginProtocolV2UiInteraction();
|
|
34
|
-
|
|
35
|
-
const metadata = device.finishProtocolV2UiInteraction('succeeded', {
|
|
36
|
-
ensureMetadata: true,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
expect(metadata).toMatchObject({
|
|
40
|
-
phase: 'processing',
|
|
41
|
-
transition: 'finish',
|
|
42
|
-
outcome: 'succeeded',
|
|
43
|
-
protocol: 'V2',
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('emits a matching PIN phase completion after DeviceSessionAskPin succeeds', async () => {
|
|
48
|
-
const device = new Device({ id: 'connect-1' } as any);
|
|
49
|
-
device.isProtocolV2 = jest.fn(() => true);
|
|
50
|
-
device.updateProtocolV2Status = jest.fn(() => undefined as any);
|
|
51
|
-
device.commands = {
|
|
52
|
-
typedCall: jest.fn().mockResolvedValue({
|
|
53
|
-
message: { unlocked: true },
|
|
54
|
-
}),
|
|
55
|
-
} as any;
|
|
56
|
-
device.beginProtocolV2UiInteraction();
|
|
57
|
-
|
|
58
|
-
const starts: unknown[] = [];
|
|
59
|
-
const completions: unknown[] = [];
|
|
60
|
-
device.on(DEVICE.PIN_ON_DEVICE, (...args) => starts.push(args));
|
|
61
|
-
device.on(DEVICE.PIN_ON_DEVICE_COMPLETE, (...args) => completions.push(args));
|
|
62
|
-
|
|
63
|
-
await device.unlockDevice(DeviceSessionPinType.Main, {
|
|
64
|
-
source: 'unlock-coordinator',
|
|
65
|
-
reason: 'device-locked',
|
|
66
|
-
deviceOnly: true,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const startMetadata = (starts[0] as unknown[])[2] as Record<string, unknown>;
|
|
70
|
-
const completionMetadata = (completions[0] as unknown[])[1] as Record<string, unknown>;
|
|
71
|
-
expect(startMetadata.interaction).toMatchObject({
|
|
72
|
-
phase: 'pin',
|
|
73
|
-
transition: 'start',
|
|
74
|
-
protocol: 'V2',
|
|
75
|
-
});
|
|
76
|
-
expect(completionMetadata).toMatchObject({
|
|
77
|
-
interactionId: (startMetadata.interaction as { interactionId: string }).interactionId,
|
|
78
|
-
phaseId: (startMetadata.interaction as { phaseId: string }).phaseId,
|
|
79
|
-
phase: 'pin',
|
|
80
|
-
transition: 'complete',
|
|
81
|
-
outcome: 'succeeded',
|
|
82
|
-
protocol: 'V2',
|
|
83
|
-
});
|
|
84
|
-
expect(completionMetadata.sequence).toBeGreaterThan(
|
|
85
|
-
(startMetadata.interaction as { sequence: number }).sequence
|
|
86
|
-
);
|
|
87
|
-
expect(completionMetadata.phaseId).toBe(
|
|
88
|
-
(startMetadata.interaction as { phaseId: string }).phaseId
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
});
|