@onekeyfe/hd-core 1.2.0-alpha.19 → 1.2.0-alpha.20
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 +75 -0
- package/__tests__/DeviceCommands.test.ts +143 -7
- package/__tests__/RequestQueue.test.ts +106 -0
- package/__tests__/UploadPortfolio.test.ts +46 -0
- package/__tests__/core-dispose.test.ts +34 -0
- package/__tests__/core-error-output.test.ts +39 -0
- package/__tests__/device-lifecycle-events.test.ts +117 -0
- package/__tests__/device-pool-state.test.ts +20 -1
- package/__tests__/device-settings.test.ts +184 -6
- package/__tests__/device-state-events.test.ts +1 -2
- package/__tests__/device-state-mapper.test.ts +33 -26
- package/__tests__/device-state-store.test.ts +1 -34
- package/__tests__/device-utils.test.ts +106 -0
- package/__tests__/device-wallet-session-store.test.ts +65 -29
- package/__tests__/deviceSettings.test.ts +21 -12
- package/__tests__/evmLedgerLegacySafety.test.ts +2 -2
- package/__tests__/evmSignTypedData.test.ts +80 -0
- package/__tests__/filesystemValidation.test.ts +53 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +402 -0
- package/__tests__/get-device-state.test.ts +77 -41
- package/__tests__/logBlockEvent.test.ts +24 -11
- package/__tests__/networkUtils.test.ts +386 -0
- package/__tests__/open-wallet-session-error-response.test.ts +43 -0
- package/__tests__/open-wallet-session.test.ts +559 -0
- package/__tests__/protocol-v2.test.ts +756 -452
- package/__tests__/public-device-state-api.test.ts +113 -13
- package/__tests__/public-pro2-api-boundary.test.ts +91 -0
- package/__tests__/search-devices.test.ts +43 -0
- package/dist/api/BaseMethod.d.ts +3 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/DirList.d.ts.map +1 -1
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +2 -2
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +3 -2
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts +14 -0
- package/dist/api/OpenWalletSession.d.ts.map +1 -0
- package/dist/api/PathInfo.d.ts.map +1 -1
- package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +3 -0
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
- package/dist/api/device/DeviceFullyUploadResource.d.ts +1 -2
- package/dist/api/device/DeviceFullyUploadResource.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +7 -3
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/helpers/filesystemValidation.d.ts +3 -0
- package/dist/api/helpers/filesystemValidation.d.ts.map +1 -1
- package/dist/api/helpers/paramsValidator.d.ts +1 -0
- package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +7 -11
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -1
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +17 -1
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +6 -5
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +5 -5
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts +1 -0
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts +2 -2
- package/dist/device/DeviceStateMapper.d.ts.map +1 -1
- package/dist/device/DeviceStateProjector.d.ts +1 -2
- package/dist/device/DeviceStateProjector.d.ts.map +1 -1
- package/dist/device/DeviceStateStore.d.ts +1 -3
- package/dist/device/DeviceStateStore.d.ts.map +1 -1
- package/dist/device/DeviceWalletSessionStore.d.ts +6 -1
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -1
- package/dist/device/cloneDeviceState.d.ts +2 -0
- package/dist/device/cloneDeviceState.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +3 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +608 -75
- package/dist/index.js +2287 -1706
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/deviceSession.d.ts +7 -0
- package/dist/protocols/protocol-v2/deviceSession.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/features.d.ts +11 -4
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +2 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts +16 -0
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +8 -3
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +1 -2
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceSettings.d.ts +1 -0
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +1 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/getFeatures.d.ts.map +1 -1
- package/dist/types/api/getOnekeyFeatures.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +13 -15
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +41 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -0
- package/dist/types/api/protocolV2.d.ts +6 -11
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -9
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/assets.d.ts +2 -1
- package/dist/utils/assets.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +13 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -0
- package/dist/utils/deviceFeaturesUtils.d.ts +11 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +9 -8
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts +2 -0
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/deviceVersionUtils.d.ts +6 -5
- package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/networkUtils.d.ts +9 -1
- package/dist/utils/networkUtils.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.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +17 -10
- package/src/api/CheckBootloaderRelease.ts +1 -2
- package/src/api/CheckFirmwareRelease.ts +1 -2
- package/src/api/ClearSessionCache.ts +0 -4
- package/src/api/DirList.ts +5 -3
- package/src/api/DirMake.ts +3 -3
- package/src/api/DirRemove.ts +3 -3
- package/src/api/FileDelete.ts +3 -3
- package/src/api/FileRead.ts +9 -6
- package/src/api/FileWrite.ts +3 -3
- package/src/api/FirmwareUpdate.ts +4 -4
- package/src/api/FirmwareUpdateV2.ts +133 -45
- package/src/api/FirmwareUpdateV3.ts +3 -5
- package/src/api/FirmwareUpdateV4.ts +192 -154
- package/src/api/GetPassphraseState.ts +10 -16
- package/src/api/OpenWalletSession.ts +221 -0
- package/src/api/PathInfo.ts +5 -3
- package/src/api/PromptWebDeviceAccess.ts +2 -3
- package/src/api/SearchDevices.ts +6 -2
- package/src/api/UploadPortfolio.ts +12 -3
- package/src/api/alephium/AlephiumSignTransaction.ts +2 -2
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +4 -8
- package/src/api/benfen/BenfenGetAddress.ts +1 -1
- package/src/api/btc/BTCGetPublicKey.ts +1 -1
- package/src/api/device/DeviceChangePin.ts +1 -0
- package/src/api/device/DeviceFullyUploadResource.ts +4 -5
- package/src/api/device/DeviceSettings.ts +93 -0
- package/src/api/device/DeviceUpdateBootloader.ts +1 -2
- package/src/api/device/DeviceWipe.ts +1 -0
- package/src/api/evm/EVMSignTypedData.ts +3 -5
- package/src/api/evm/legacyV1/getAddress.ts +2 -2
- package/src/api/evm/legacyV1/getPublicKey.ts +2 -2
- package/src/api/evm/legacyV1/signMessage.ts +2 -2
- package/src/api/evm/legacyV1/signTypedData.ts +2 -2
- package/src/api/evm/legacyV1/signTypedHash.ts +2 -2
- package/src/api/evm/legacyV1/verifyMessage.ts +2 -2
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -3
- package/src/api/firmware/getBinary.ts +8 -3
- package/src/api/helpers/batchGetPublickeys.ts +2 -2
- package/src/api/helpers/filesystemValidation.ts +61 -0
- package/src/api/helpers/paramsValidator.ts +1 -1
- package/src/api/helpers/protocolV2FileWrite.ts +3 -2
- package/src/api/index.ts +9 -12
- package/src/api/nervos/NervosSignTransaction.ts +2 -2
- package/src/api/nexa/NexaSignTransaction.ts +1 -1
- package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +1 -1
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +4 -4
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +6 -5
- package/src/api/protocol-v2/DeviceInfoGet.ts +4 -4
- package/src/api/protocol-v2/DeviceReboot.ts +1 -1
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +11 -8
- package/src/api/protocol-v2/DeviceSettingsSet.ts +4 -11
- package/src/api/protocol-v2/FilesystemFormat.ts +1 -1
- package/src/api/protocol-v2/FilesystemPermissionFix.ts +1 -1
- package/src/api/protocol-v2/Ping.ts +1 -1
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -1
- package/src/api/utils.ts +1 -3
- package/src/core/RequestQueue.ts +107 -6
- package/src/core/index.ts +91 -46
- package/src/data/messages/messages-protocol-v2.json +25 -79
- package/src/data-manager/DataManager.ts +6 -6
- package/src/device/Device.ts +186 -102
- package/src/device/DeviceCommands.ts +51 -21
- package/src/device/DeviceFeaturesState.ts +4 -4
- package/src/device/DevicePool.ts +17 -3
- package/src/device/DeviceStateMapper.ts +13 -29
- package/src/device/DeviceStateProjector.ts +11 -8
- package/src/device/DeviceStateStore.ts +11 -52
- package/src/device/DeviceWalletSessionStore.ts +31 -4
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +2 -2
- package/src/deviceProfile/buildDeviceFeatures.ts +29 -88
- package/src/events/logBlockEvent.ts +8 -1
- package/src/inject.ts +14 -24
- package/src/protocols/protocol-v2/deviceSession.ts +24 -0
- package/src/protocols/protocol-v2/features.ts +37 -49
- package/src/protocols/protocol-v2/firmware.ts +1 -1
- package/src/protocols/protocol-v2/index.ts +2 -3
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +61 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +4 -3
- package/src/protocols/protocol-v2/walletSession.ts +57 -146
- package/src/types/api/checkAllFirmwareRelease.ts +1 -2
- package/src/types/api/deviceSettings.ts +1 -0
- package/src/types/api/deviceUnlock.ts +1 -1
- package/src/types/api/firmwareUpdate.ts +5 -5
- package/src/types/api/getDeviceState.ts +1 -1
- package/src/types/api/getFeatures.ts +3 -0
- package/src/types/api/getOnekeyFeatures.ts +3 -0
- package/src/types/api/getPassphraseState.ts +6 -0
- package/src/types/api/index.ts +16 -23
- package/src/types/api/openWalletSession.ts +64 -0
- package/src/types/api/protocolV2.ts +36 -18
- package/src/types/device.ts +20 -14
- package/src/types/params.ts +1 -1
- package/src/types/settings.ts +8 -8
- package/src/utils/assets.ts +4 -1
- package/src/utils/deviceFeaturesCompat.ts +173 -0
- package/src/utils/deviceFeaturesUtils.ts +9 -8
- package/src/utils/deviceInfoUtils.ts +26 -64
- package/src/utils/deviceSettings.ts +18 -11
- package/src/utils/deviceVersionUtils.ts +25 -44
- package/src/utils/findDefectiveBatchDevice.ts +3 -3
- package/src/utils/index.ts +2 -5
- package/src/utils/networkUtils.ts +270 -14
- package/src/utils/pro2Wallpaper.ts +11 -13
- package/src/utils/tracing.ts +2 -2
- package/dist/api/internal.d.ts +0 -4
- package/dist/api/internal.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +0 -28
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +0 -1
- package/src/api/internal.ts +0 -9
- package/src/api/protocol-v2/DeviceSessionOpen.ts +0 -100
|
@@ -4,23 +4,24 @@ import {
|
|
|
4
4
|
getAutoLockOptions,
|
|
5
5
|
getAutoShutDownOptions,
|
|
6
6
|
getLanguageConfig,
|
|
7
|
+
mapLanguageToProtocolV2,
|
|
7
8
|
} from '../src/utils/deviceSettings';
|
|
8
9
|
|
|
9
10
|
describe('Pro 2 device settings options', () => {
|
|
10
|
-
test('returns
|
|
11
|
+
test('returns stable SDK keys plus Pro2-only BCP-47 languages', () => {
|
|
11
12
|
expect(getLanguageConfig(EDeviceType.Pro2)).toEqual([
|
|
12
|
-
{ code: 'en
|
|
13
|
-
{ code: '
|
|
14
|
-
{ code: '
|
|
13
|
+
{ code: 'en', label: 'English' },
|
|
14
|
+
{ code: 'zh_cn', label: '简体中文' },
|
|
15
|
+
{ code: 'zh_hk', label: '繁體中文' },
|
|
16
|
+
{ code: 'ja', label: '日本語' },
|
|
17
|
+
{ code: 'ko', label: '한국어' },
|
|
18
|
+
{ code: 'fr', label: 'Français' },
|
|
19
|
+
{ code: 'de', label: 'Deutsch' },
|
|
20
|
+
{ code: 'ru', label: 'Russian' },
|
|
21
|
+
{ code: 'es', label: 'Spanish' },
|
|
22
|
+
{ code: 'it', label: 'Italiano' },
|
|
23
|
+
{ code: 'pt_br', label: 'Portuguese (Brazil)' },
|
|
15
24
|
{ code: 'zh-Hant-TW', label: '繁體中文(台灣)' },
|
|
16
|
-
{ code: 'ja-Jpan-JP', label: '日本語' },
|
|
17
|
-
{ code: 'ko-Kore-KR', label: '한국어' },
|
|
18
|
-
{ code: 'fr-Latn-FR', label: 'Français' },
|
|
19
|
-
{ code: 'de-Latn-DE', label: 'Deutsch' },
|
|
20
|
-
{ code: 'ru-Cyrl-RU', label: 'Русский' },
|
|
21
|
-
{ code: 'es-Latn-ES', label: 'Español' },
|
|
22
|
-
{ code: 'it-Latn-IT', label: 'Italiano' },
|
|
23
|
-
{ code: 'pt-Latn-BR', label: 'Portuguese (Brazil)' },
|
|
24
25
|
{ code: 'vi-Latn-VN', label: 'Tiếng Việt' },
|
|
25
26
|
{ code: 'tr-Latn-TR', label: 'Türkçe' },
|
|
26
27
|
{ code: 'id-Latn-ID', label: 'Bahasa Indonesia' },
|
|
@@ -29,6 +30,14 @@ describe('Pro 2 device settings options', () => {
|
|
|
29
30
|
]);
|
|
30
31
|
});
|
|
31
32
|
|
|
33
|
+
test('maps shared language keys and preserves Pro2-only BCP-47 tags', () => {
|
|
34
|
+
expect(mapLanguageToProtocolV2('en')).toBe('en-Latn-US');
|
|
35
|
+
expect(mapLanguageToProtocolV2('zh_cn')).toBe('zh-Hans-CN');
|
|
36
|
+
expect(mapLanguageToProtocolV2('pt_br')).toBe('pt-Latn-BR');
|
|
37
|
+
expect(mapLanguageToProtocolV2('vi-Latn-VN')).toBe('vi-Latn-VN');
|
|
38
|
+
expect(mapLanguageToProtocolV2(undefined)).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
32
41
|
test('returns the firmware-supported auto-lock delays', () => {
|
|
33
42
|
expect(getAutoLockOptions(EDeviceType.Pro2)).toEqual([
|
|
34
43
|
{ seconds: 30, minute: 0, hour: 0, day: 0 },
|
|
@@ -5,7 +5,7 @@ import { findMethod } from '../src/api/utils';
|
|
|
5
5
|
import { getDeviceType, getFirmwareType, getMethodVersionRange } from '../src/utils';
|
|
6
6
|
import { getDeviceFirmwareVersion } from '../src/utils/deviceVersionUtils';
|
|
7
7
|
|
|
8
|
-
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
8
|
+
import type { EDeviceType } from '@onekeyfe/hd-shared';
|
|
9
9
|
|
|
10
10
|
jest.mock('../src/data/config', () => ({
|
|
11
11
|
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
@@ -30,7 +30,7 @@ const createDevice = (onekeyDeviceType: string) => {
|
|
|
30
30
|
commands: {
|
|
31
31
|
typedCall,
|
|
32
32
|
},
|
|
33
|
-
// BaseMethod
|
|
33
|
+
// BaseMethod reads state through Device accessors; reuse production mappers in the stub.
|
|
34
34
|
isProtocolV2: () => false,
|
|
35
35
|
getCurrentDeviceType: () => getDeviceType(features as any),
|
|
36
36
|
getCurrentSafetyChecks: () => features.safety_checks,
|
|
@@ -497,3 +497,83 @@ describe('EVMSignTypedData — hasClassicFamilyTypedDataFormatViolations', () =>
|
|
|
497
497
|
});
|
|
498
498
|
});
|
|
499
499
|
});
|
|
500
|
+
|
|
501
|
+
describe('EVMSignTypedData — OneKey Pro Safe Protocol V1', () => {
|
|
502
|
+
it('收到 Pro 的 Safe 请求后按 EthereumGnosisSafeTxAck 字段回传', async () => {
|
|
503
|
+
const data = {
|
|
504
|
+
types: {
|
|
505
|
+
EIP712Domain: [
|
|
506
|
+
{ name: 'chainId', type: 'uint256' },
|
|
507
|
+
{ name: 'verifyingContract', type: 'address' },
|
|
508
|
+
],
|
|
509
|
+
SafeTx: [
|
|
510
|
+
{ name: 'to', type: 'address' },
|
|
511
|
+
{ name: 'value', type: 'uint256' },
|
|
512
|
+
{ name: 'data', type: 'bytes' },
|
|
513
|
+
{ name: 'operation', type: 'uint8' },
|
|
514
|
+
{ name: 'safeTxGas', type: 'uint256' },
|
|
515
|
+
{ name: 'baseGas', type: 'uint256' },
|
|
516
|
+
{ name: 'gasPrice', type: 'uint256' },
|
|
517
|
+
{ name: 'gasToken', type: 'address' },
|
|
518
|
+
{ name: 'refundReceiver', type: 'address' },
|
|
519
|
+
{ name: 'nonce', type: 'uint256' },
|
|
520
|
+
],
|
|
521
|
+
},
|
|
522
|
+
primaryType: 'SafeTx',
|
|
523
|
+
domain: {
|
|
524
|
+
chainId: '0x89',
|
|
525
|
+
verifyingContract: '0x673f21761c5400531a37554a602fe0407addd0dd',
|
|
526
|
+
},
|
|
527
|
+
message: {
|
|
528
|
+
to: '0x5618207d27d78f09f61a5d92190d58c453feb4b7',
|
|
529
|
+
value: '1000',
|
|
530
|
+
data: '0x001234',
|
|
531
|
+
operation: '1',
|
|
532
|
+
safeTxGas: '256',
|
|
533
|
+
baseGas: '0',
|
|
534
|
+
gasPrice: '15',
|
|
535
|
+
gasToken: '0x0000000000000000000000000000000000000000',
|
|
536
|
+
refundReceiver: '0x0000000000000000000000000000000000000000',
|
|
537
|
+
nonce: '2',
|
|
538
|
+
},
|
|
539
|
+
} as EthereumSignTypedDataMessage<EthereumSignTypedDataTypes>;
|
|
540
|
+
const method = createMethod(data);
|
|
541
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
542
|
+
type: 'EthereumTypedDataSignatureOneKey',
|
|
543
|
+
message: {
|
|
544
|
+
address: '0x5618207d27d78f09f61a5d92190d58c453feb4b7',
|
|
545
|
+
signature: 'abcd',
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
const result = await method.handleSignTypedData({
|
|
550
|
+
typedCall: typedCall as any,
|
|
551
|
+
signData: data,
|
|
552
|
+
response: { type: 'EthereumGnosisSafeTxRequest', message: {} } as any,
|
|
553
|
+
supportTrezor: false,
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
expect(typedCall).toHaveBeenCalledWith(
|
|
557
|
+
'EthereumGnosisSafeTxAck',
|
|
558
|
+
['EthereumTypedDataSignature', 'EthereumTypedDataSignatureOneKey'],
|
|
559
|
+
{
|
|
560
|
+
to: '0x5618207d27d78f09f61a5d92190d58c453feb4b7',
|
|
561
|
+
value: '03e8',
|
|
562
|
+
data: '1234',
|
|
563
|
+
operation: 1,
|
|
564
|
+
safeTxGas: '0100',
|
|
565
|
+
baseGas: '00',
|
|
566
|
+
gasPrice: '0f',
|
|
567
|
+
gasToken: '0x0000000000000000000000000000000000000000',
|
|
568
|
+
refundReceiver: '0x0000000000000000000000000000000000000000',
|
|
569
|
+
nonce: '02',
|
|
570
|
+
chain_id: 137,
|
|
571
|
+
verifyingContract: '0x673f21761c5400531a37554a602fe0407addd0dd',
|
|
572
|
+
}
|
|
573
|
+
);
|
|
574
|
+
expect(result).toEqual({
|
|
575
|
+
address: '0x5618207d27d78f09f61a5d92190d58c453feb4b7',
|
|
576
|
+
signature: 'abcd',
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { validateProtocolV2FilesystemPath } from '../src/api/helpers/filesystemValidation';
|
|
4
|
+
|
|
5
|
+
jest.mock('../src/data/config', () => ({
|
|
6
|
+
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
7
|
+
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
describe('validateProtocolV2FilesystemPath', () => {
|
|
11
|
+
test('兼容并保留设备现有的卷内相对路径格式', () => {
|
|
12
|
+
expect(validateProtocolV2FilesystemPath('vol1:test.bin', 'path')).toBe('vol1:test.bin');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('目录查询可以使用卷根目录', () => {
|
|
16
|
+
expect(
|
|
17
|
+
validateProtocolV2FilesystemPath('VOL1:', 'path', {
|
|
18
|
+
allowVolumeRoot: true,
|
|
19
|
+
})
|
|
20
|
+
).toBe('vol1:');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test.each([
|
|
24
|
+
'vol1:/../firmware.bin',
|
|
25
|
+
'vol1:/wallets/./test.bin',
|
|
26
|
+
'vol1:/wallets//test.bin',
|
|
27
|
+
'vol1:\\wallets\\test.bin',
|
|
28
|
+
'vol2:/test.bin',
|
|
29
|
+
'/test.bin',
|
|
30
|
+
])('拒绝不安全或未知范围的路径:%s', path => {
|
|
31
|
+
expect(() => validateProtocolV2FilesystemPath(path, 'path')).toThrow(
|
|
32
|
+
expect.objectContaining({
|
|
33
|
+
errorCode: HardwareErrorCode.CallMethodInvalidParameter,
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('文件操作不允许使用卷根目录', () => {
|
|
39
|
+
expect(() => validateProtocolV2FilesystemPath('vol1:', 'path')).toThrow(
|
|
40
|
+
expect.objectContaining({
|
|
41
|
+
errorCode: HardwareErrorCode.CallMethodInvalidParameter,
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('按 UTF-8 字节数拒绝超出设备最小路径缓冲区的路径', () => {
|
|
47
|
+
expect(() => validateProtocolV2FilesystemPath(`vol1:/${'测'.repeat(41)}`, 'path')).toThrow(
|
|
48
|
+
expect.objectContaining({
|
|
49
|
+
errorCode: HardwareErrorCode.CallMethodInvalidParameter,
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { EDeviceType, EFirmwareType, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import FirmwareUpdateV2 from '../../src/api/FirmwareUpdateV2';
|
|
4
|
+
import { getBinary } from '../../src/api/firmware/getBinary';
|
|
5
|
+
import { uploadFirmware } from '../../src/api/firmware/uploadFirmware';
|
|
6
|
+
import * as utils from '../../src/utils';
|
|
7
|
+
|
|
8
|
+
jest.mock('../../src/data/config', () => ({
|
|
9
|
+
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
10
|
+
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock('../../src/api/firmware/getBinary', () => ({
|
|
14
|
+
getBinary: jest.fn(),
|
|
15
|
+
getInfo: jest.fn(),
|
|
16
|
+
getSysResourceBinary: jest.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
jest.mock('../../src/api/firmware/uploadFirmware', () => ({
|
|
20
|
+
updateResources: jest.fn(),
|
|
21
|
+
uploadFirmware: jest.fn(),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
jest.mock('../../src/device/DevicePool', () => ({
|
|
25
|
+
DevicePool: {
|
|
26
|
+
clearDeviceCache: jest.fn(),
|
|
27
|
+
devicesCache: {},
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
const mockGetBinary = getBinary as jest.MockedFunction<typeof getBinary>;
|
|
32
|
+
const mockUploadFirmware = uploadFirmware as jest.MockedFunction<typeof uploadFirmware>;
|
|
33
|
+
|
|
34
|
+
type DeviceType = 'CLASSIC1S' | 'PURE';
|
|
35
|
+
|
|
36
|
+
const createCustomBuffer = (byteLength: number) => {
|
|
37
|
+
const customBuffer: {
|
|
38
|
+
[index: number]: number;
|
|
39
|
+
byteLength: number;
|
|
40
|
+
constructor: {
|
|
41
|
+
isBuffer: (value: unknown) => boolean;
|
|
42
|
+
};
|
|
43
|
+
length: number;
|
|
44
|
+
} = {
|
|
45
|
+
byteLength,
|
|
46
|
+
constructor: {
|
|
47
|
+
isBuffer: (value: unknown) => value === customBuffer,
|
|
48
|
+
},
|
|
49
|
+
length: byteLength,
|
|
50
|
+
};
|
|
51
|
+
for (let index = 0; index < byteLength; index += 1) {
|
|
52
|
+
customBuffer[index] = index + 1;
|
|
53
|
+
}
|
|
54
|
+
return customBuffer;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const countCommandCalls = (typedCall: jest.Mock, command: string) =>
|
|
58
|
+
typedCall.mock.calls.filter(([calledCommand]) => calledCommand === command).length;
|
|
59
|
+
|
|
60
|
+
const expectNoFirmwareMutationCalls = (typedCall: jest.Mock) => {
|
|
61
|
+
expect(countCommandCalls(typedCall, 'DeviceBackToBoot')).toBe(0);
|
|
62
|
+
expect(countCommandCalls(typedCall, 'FirmwareErase')).toBe(0);
|
|
63
|
+
expect(countCommandCalls(typedCall, 'FirmwareErase_ex')).toBe(0);
|
|
64
|
+
expect(countCommandCalls(typedCall, 'FirmwareUpload')).toBe(0);
|
|
65
|
+
expect(countCommandCalls(typedCall, 'UpgradeFileHeader')).toBe(0);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const createMethod = ({
|
|
69
|
+
binary,
|
|
70
|
+
updateType = 'firmware',
|
|
71
|
+
isUpdateBootloader,
|
|
72
|
+
deviceType = 'CLASSIC1S',
|
|
73
|
+
bootloaderMode = false,
|
|
74
|
+
}: {
|
|
75
|
+
binary?: unknown;
|
|
76
|
+
updateType?: 'firmware' | 'ble';
|
|
77
|
+
isUpdateBootloader?: boolean;
|
|
78
|
+
deviceType?: DeviceType;
|
|
79
|
+
bootloaderMode?: boolean;
|
|
80
|
+
} = {}) => {
|
|
81
|
+
const method = new FirmwareUpdateV2({
|
|
82
|
+
id: 1,
|
|
83
|
+
payload: {
|
|
84
|
+
method: 'firmwareUpdateV2',
|
|
85
|
+
connectId: 'connect-id',
|
|
86
|
+
deviceId: 'device-id',
|
|
87
|
+
platform: 'desktop',
|
|
88
|
+
updateType,
|
|
89
|
+
isUpdateBootloader,
|
|
90
|
+
...(binary !== undefined ? { binary } : { version: [3, 0, 0] }),
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
method.init();
|
|
94
|
+
|
|
95
|
+
const typedCall = jest.fn().mockResolvedValue({ type: 'Success' });
|
|
96
|
+
const checkDisposed = jest.fn();
|
|
97
|
+
const acquire = jest.fn().mockResolvedValue(undefined);
|
|
98
|
+
const commands = {
|
|
99
|
+
typedCall,
|
|
100
|
+
checkDisposed,
|
|
101
|
+
disposed: false,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
method.device = {
|
|
105
|
+
features: {
|
|
106
|
+
onekey_device_type: deviceType,
|
|
107
|
+
onekey_serial_no: deviceType === 'PURE' ? 'CP123456' : 'CL123456',
|
|
108
|
+
bootloader_mode: bootloaderMode,
|
|
109
|
+
major_version: 3,
|
|
110
|
+
minor_version: 0,
|
|
111
|
+
patch_version: 0,
|
|
112
|
+
capabilities: [],
|
|
113
|
+
},
|
|
114
|
+
commands,
|
|
115
|
+
getCommands: () => commands,
|
|
116
|
+
getCurrentDeviceType: () =>
|
|
117
|
+
deviceType === 'PURE' ? EDeviceType.ClassicPure : EDeviceType.Classic1s,
|
|
118
|
+
getCurrentFirmwareType: () => EFirmwareType.Universal,
|
|
119
|
+
getCurrentFirmwareVersionString: () => '3.0.0',
|
|
120
|
+
getCurrentBootloaderVersionString: () => '0.0.0',
|
|
121
|
+
getCurrentSerialNo: () => (deviceType === 'PURE' ? 'CP123456' : 'CL123456'),
|
|
122
|
+
isBootloader: () => bootloaderMode,
|
|
123
|
+
isProtocolV2: () => false,
|
|
124
|
+
acquire,
|
|
125
|
+
toMessageObject: jest.fn(() => ({})),
|
|
126
|
+
} as any;
|
|
127
|
+
method.postMessage = jest.fn();
|
|
128
|
+
jest.spyOn(method, 'checkDeviceToBootloader').mockImplementation(() => {
|
|
129
|
+
method.checkPromise = {
|
|
130
|
+
promise: Promise.resolve(true),
|
|
131
|
+
} as any;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
method,
|
|
136
|
+
typedCall,
|
|
137
|
+
acquire,
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
describe('FirmwareUpdateV2 download-before-reboot safety', () => {
|
|
142
|
+
beforeEach(() => {
|
|
143
|
+
jest.clearAllMocks();
|
|
144
|
+
jest.spyOn(utils, 'wait').mockResolvedValue(undefined);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
afterEach(() => {
|
|
148
|
+
jest.restoreAllMocks();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it.each([
|
|
152
|
+
{
|
|
153
|
+
context: 'Classic 1S normal mode',
|
|
154
|
+
deviceType: 'CLASSIC1S' as const,
|
|
155
|
+
bootloaderMode: false,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
context: 'Classic Pure normal mode',
|
|
159
|
+
deviceType: 'PURE' as const,
|
|
160
|
+
bootloaderMode: false,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
context: 'initial bootloader mode',
|
|
164
|
+
deviceType: 'CLASSIC1S' as const,
|
|
165
|
+
bootloaderMode: true,
|
|
166
|
+
},
|
|
167
|
+
])('blocks all firmware mutation after final download failure in $context', async options => {
|
|
168
|
+
mockGetBinary.mockRejectedValue(new Error('request failed'));
|
|
169
|
+
const { method, typedCall, acquire } = createMethod(options);
|
|
170
|
+
|
|
171
|
+
await expect(method.run()).rejects.toMatchObject({
|
|
172
|
+
errorCode: HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(mockGetBinary).toHaveBeenCalledTimes(1);
|
|
176
|
+
expectNoFirmwareMutationCalls(typedCall);
|
|
177
|
+
expect(acquire).not.toHaveBeenCalled();
|
|
178
|
+
expect(mockUploadFirmware).not.toHaveBeenCalled();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it.each([
|
|
182
|
+
{
|
|
183
|
+
mode: 'firmware release.url',
|
|
184
|
+
updateType: 'firmware' as const,
|
|
185
|
+
isUpdateBootloader: undefined,
|
|
186
|
+
deviceType: 'CLASSIC1S' as const,
|
|
187
|
+
firmwareBinary: new ArrayBuffer(4),
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
mode: 'BLE webUpdate',
|
|
191
|
+
updateType: 'ble' as const,
|
|
192
|
+
isUpdateBootloader: undefined,
|
|
193
|
+
deviceType: 'PURE' as const,
|
|
194
|
+
firmwareBinary: Buffer.from([1, 2, 3, 4]),
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
mode: 'bootloaderResource',
|
|
198
|
+
updateType: 'firmware' as const,
|
|
199
|
+
isUpdateBootloader: true,
|
|
200
|
+
deviceType: 'CLASSIC1S' as const,
|
|
201
|
+
firmwareBinary: new ArrayBuffer(8),
|
|
202
|
+
},
|
|
203
|
+
])(
|
|
204
|
+
'acquires $mode before rebooting and preserves the response shape',
|
|
205
|
+
async ({ updateType, isUpdateBootloader, deviceType = 'CLASSIC1S', firmwareBinary }) => {
|
|
206
|
+
const callOrder: string[] = [];
|
|
207
|
+
const expectedResponse = {
|
|
208
|
+
success: true,
|
|
209
|
+
payload: {
|
|
210
|
+
firmwareVersion: '3.0.0',
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
mockGetBinary.mockImplementation(() => {
|
|
214
|
+
callOrder.push('download');
|
|
215
|
+
return Promise.resolve({
|
|
216
|
+
binary: firmwareBinary,
|
|
217
|
+
} as Awaited<ReturnType<typeof getBinary>>);
|
|
218
|
+
});
|
|
219
|
+
mockUploadFirmware.mockImplementation(() => {
|
|
220
|
+
callOrder.push('upload');
|
|
221
|
+
return Promise.resolve(expectedResponse as Awaited<ReturnType<typeof uploadFirmware>>);
|
|
222
|
+
});
|
|
223
|
+
const { method, typedCall } = createMethod({
|
|
224
|
+
updateType,
|
|
225
|
+
isUpdateBootloader,
|
|
226
|
+
deviceType,
|
|
227
|
+
});
|
|
228
|
+
typedCall.mockImplementation(type => {
|
|
229
|
+
if (type === 'DeviceBackToBoot') {
|
|
230
|
+
callOrder.push('reboot');
|
|
231
|
+
}
|
|
232
|
+
return Promise.resolve({ type: 'Success' });
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
await expect(method.run()).resolves.toBe(expectedResponse);
|
|
236
|
+
|
|
237
|
+
expect(callOrder).toEqual(['download', 'reboot', 'upload']);
|
|
238
|
+
expect(mockGetBinary).toHaveBeenCalledWith(
|
|
239
|
+
expect.objectContaining({
|
|
240
|
+
updateType,
|
|
241
|
+
isUpdateBootloader,
|
|
242
|
+
requestOptions: {
|
|
243
|
+
connectTimeoutMs: 60_000,
|
|
244
|
+
readTimeoutMs: 60_000,
|
|
245
|
+
overallTimeoutMs: 180_000,
|
|
246
|
+
maxRetries: 2,
|
|
247
|
+
retryDelayMs: 500,
|
|
248
|
+
},
|
|
249
|
+
})
|
|
250
|
+
);
|
|
251
|
+
expect(mockUploadFirmware).toHaveBeenCalledWith(
|
|
252
|
+
updateType,
|
|
253
|
+
expect.any(Function),
|
|
254
|
+
expect.any(Function),
|
|
255
|
+
method.device,
|
|
256
|
+
{
|
|
257
|
+
payload: firmwareBinary,
|
|
258
|
+
rebootOnSuccess: true,
|
|
259
|
+
},
|
|
260
|
+
isUpdateBootloader
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
it('downloads before acquiring and uploading when the device starts in bootloader mode', async () => {
|
|
266
|
+
const callOrder: string[] = [];
|
|
267
|
+
const firmwareBinary = new ArrayBuffer(4);
|
|
268
|
+
mockGetBinary.mockImplementation(() => {
|
|
269
|
+
callOrder.push('download');
|
|
270
|
+
return Promise.resolve({
|
|
271
|
+
binary: firmwareBinary,
|
|
272
|
+
} as Awaited<ReturnType<typeof getBinary>>);
|
|
273
|
+
});
|
|
274
|
+
mockUploadFirmware.mockImplementation(() => {
|
|
275
|
+
callOrder.push('upload');
|
|
276
|
+
return Promise.resolve({
|
|
277
|
+
success: true,
|
|
278
|
+
} as Awaited<ReturnType<typeof uploadFirmware>>);
|
|
279
|
+
});
|
|
280
|
+
const { method, typedCall, acquire } = createMethod({
|
|
281
|
+
bootloaderMode: true,
|
|
282
|
+
});
|
|
283
|
+
acquire.mockImplementation(() => {
|
|
284
|
+
callOrder.push('acquire');
|
|
285
|
+
return Promise.resolve();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
await method.run();
|
|
289
|
+
|
|
290
|
+
expect(callOrder).toEqual(['download', 'acquire', 'upload']);
|
|
291
|
+
expect(countCommandCalls(typedCall, 'DeviceBackToBoot')).toBe(0);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('does not reboot while the firmware download is pending', async () => {
|
|
295
|
+
let resolveDownload!: (result: Awaited<ReturnType<typeof getBinary>>) => void;
|
|
296
|
+
const firmwareBinary = new ArrayBuffer(4);
|
|
297
|
+
mockGetBinary.mockImplementation(
|
|
298
|
+
() =>
|
|
299
|
+
new Promise(resolve => {
|
|
300
|
+
resolveDownload = resolve;
|
|
301
|
+
})
|
|
302
|
+
);
|
|
303
|
+
mockUploadFirmware.mockResolvedValue({
|
|
304
|
+
success: true,
|
|
305
|
+
} as Awaited<ReturnType<typeof uploadFirmware>>);
|
|
306
|
+
const { method, typedCall } = createMethod();
|
|
307
|
+
|
|
308
|
+
const runPromise = method.run();
|
|
309
|
+
|
|
310
|
+
expect(mockGetBinary).toHaveBeenCalledTimes(1);
|
|
311
|
+
expect(countCommandCalls(typedCall, 'DeviceBackToBoot')).toBe(0);
|
|
312
|
+
|
|
313
|
+
resolveDownload({
|
|
314
|
+
binary: firmwareBinary,
|
|
315
|
+
} as Awaited<ReturnType<typeof getBinary>>);
|
|
316
|
+
await runPromise;
|
|
317
|
+
|
|
318
|
+
expect(countCommandCalls(typedCall, 'DeviceBackToBoot')).toBe(1);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it.each([
|
|
322
|
+
['ArrayBuffer', new ArrayBuffer(0)],
|
|
323
|
+
['Buffer', Buffer.alloc(0)],
|
|
324
|
+
])('does not reboot or upload an empty downloaded %s', async (_kind, firmwareBinary) => {
|
|
325
|
+
mockGetBinary.mockResolvedValue({
|
|
326
|
+
binary: firmwareBinary,
|
|
327
|
+
} as Awaited<ReturnType<typeof getBinary>>);
|
|
328
|
+
const { method, typedCall, acquire } = createMethod();
|
|
329
|
+
|
|
330
|
+
await expect(method.run()).rejects.toMatchObject({
|
|
331
|
+
errorCode: HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
expectNoFirmwareMutationCalls(typedCall);
|
|
335
|
+
expect(acquire).not.toHaveBeenCalled();
|
|
336
|
+
expect(mockUploadFirmware).not.toHaveBeenCalled();
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it.each([
|
|
340
|
+
['ArrayBuffer', new ArrayBuffer(4)],
|
|
341
|
+
['Buffer', Buffer.from([1, 2, 3, 4])],
|
|
342
|
+
])(
|
|
343
|
+
'keeps the non-empty %s binary overload and never downloads it again',
|
|
344
|
+
async (_kind, binary) => {
|
|
345
|
+
mockUploadFirmware.mockResolvedValue({
|
|
346
|
+
success: true,
|
|
347
|
+
} as Awaited<ReturnType<typeof uploadFirmware>>);
|
|
348
|
+
const { method } = createMethod({ binary });
|
|
349
|
+
|
|
350
|
+
await method.run();
|
|
351
|
+
|
|
352
|
+
expect(mockGetBinary).not.toHaveBeenCalled();
|
|
353
|
+
expect(mockUploadFirmware).toHaveBeenCalledWith(
|
|
354
|
+
'firmware',
|
|
355
|
+
expect.any(Function),
|
|
356
|
+
expect.any(Function),
|
|
357
|
+
method.device,
|
|
358
|
+
{
|
|
359
|
+
payload: binary,
|
|
360
|
+
rebootOnSuccess: true,
|
|
361
|
+
},
|
|
362
|
+
undefined
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
it.each([
|
|
368
|
+
['Uint8Array subview', new Uint8Array([9, 1, 2, 9]).subarray(1, 3), [1, 2]],
|
|
369
|
+
['DataView', new DataView(new Uint8Array([9, 3, 4, 9]).buffer, 1, 2), [3, 4]],
|
|
370
|
+
['custom Buffer', createCustomBuffer(4), [1, 2, 3, 4]],
|
|
371
|
+
])('normalizes a non-empty %s before rebooting', async (_kind, binary, expectedBytes) => {
|
|
372
|
+
mockUploadFirmware.mockResolvedValue({
|
|
373
|
+
success: true,
|
|
374
|
+
} as Awaited<ReturnType<typeof uploadFirmware>>);
|
|
375
|
+
const { method } = createMethod({ binary });
|
|
376
|
+
|
|
377
|
+
await method.run();
|
|
378
|
+
|
|
379
|
+
expect(mockGetBinary).not.toHaveBeenCalled();
|
|
380
|
+
const normalizedBinary = mockUploadFirmware.mock.calls[0][4].payload;
|
|
381
|
+
expect(normalizedBinary).toBeInstanceOf(ArrayBuffer);
|
|
382
|
+
expect(Array.from(new Uint8Array(normalizedBinary))).toEqual(expectedBytes);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it.each([
|
|
386
|
+
['ArrayBuffer', new ArrayBuffer(0)],
|
|
387
|
+
['Buffer', Buffer.alloc(0)],
|
|
388
|
+
['ArrayBufferView', new Uint8Array(0)],
|
|
389
|
+
['custom Buffer', createCustomBuffer(0)],
|
|
390
|
+
])('rejects an empty supplied %s before rebooting', async (_kind, binary) => {
|
|
391
|
+
const { method, typedCall, acquire } = createMethod({ binary });
|
|
392
|
+
|
|
393
|
+
await expect(method.run()).rejects.toMatchObject({
|
|
394
|
+
errorCode: HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
expect(mockGetBinary).not.toHaveBeenCalled();
|
|
398
|
+
expectNoFirmwareMutationCalls(typedCall);
|
|
399
|
+
expect(acquire).not.toHaveBeenCalled();
|
|
400
|
+
expect(mockUploadFirmware).not.toHaveBeenCalled();
|
|
401
|
+
});
|
|
402
|
+
});
|