@onekeyfe/hd-core 1.2.0-alpha.98 → 1.2.0
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 +20 -4
- package/__tests__/DeviceCommands.test.ts +203 -27
- package/__tests__/base64Data.test.ts +69 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +89 -38
- package/__tests__/check-firmware-release-protocol-v2.test.ts +83 -14
- package/__tests__/device-connector-protocol.test.ts +21 -0
- package/__tests__/device-lifecycle-events.test.ts +427 -7
- package/__tests__/device-pool-state.test.ts +25 -0
- package/__tests__/device-settings.test.ts +237 -9
- package/__tests__/device-state-events.test.ts +2 -2
- package/__tests__/device-state-mapper.test.ts +61 -5
- package/__tests__/device-utils.test.ts +15 -1
- package/__tests__/device-wallet-session-store.test.ts +147 -21
- package/__tests__/deviceSettings.test.ts +7 -3
- package/__tests__/deviceUploadNft.test.ts +36 -4
- package/__tests__/firmware-update/device-update-bootloader.test.ts +14 -3
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +61 -9
- package/__tests__/firmware-update/firmware-prepared-host-digest.test.ts +19 -9
- package/__tests__/firmware-update/firmware-prepared-resource-archive.test.ts +21 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +128 -2
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +80 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +114 -50
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +19 -5
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +116 -0
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +678 -0
- package/__tests__/firmware-update/firmware-update-v4-parameters.test.ts +85 -0
- package/__tests__/get-device-state.test.ts +60 -21
- package/__tests__/logBlockEvent.test.ts +13 -1
- package/__tests__/open-wallet-session.test.ts +127 -1
- package/__tests__/protocol-v2-firmware-targets.test.ts +39 -0
- package/__tests__/protocol-v2-resources.test.ts +185 -88
- package/__tests__/protocol-v2-unlock-policy.test.ts +235 -2
- package/__tests__/protocol-v2.test.ts +2274 -466
- package/__tests__/refresh-device-state.test.ts +3 -1
- package/__tests__/resourceBase64Boundary.test.ts +48 -0
- package/__tests__/search-devices.test.ts +79 -32
- package/__tests__/ton-sign-message.test.ts +84 -0
- package/dist/api/BaseMethod.d.ts +2 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +22 -7
- package/dist/api/FirmwareUpdateV4.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/UploadPortfolio.d.ts +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/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceVerify.d.ts +1 -0
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +5 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -1
- package/dist/api/firmware/FirmwarePreparedResourceArchive.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -15
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +3 -2
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/protocolV2Release.d.ts.map +1 -1
- package/dist/api/helpers/base64Data.d.ts +16 -0
- package/dist/api/helpers/base64Data.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +3 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +2 -3
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +2 -3
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/core/index.d.ts +6 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +4 -3
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +16 -3
- 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 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +3 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +54 -84
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2333 -1515
- package/dist/protocols/protocol-v2/features.d.ts +13 -5
- 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/resources.d.ts +12 -7
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +3 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +3 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdatePlan.d.ts +2 -2
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +1 -1
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/settings.d.ts +3 -31
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +3 -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 +1 -0
- package/dist/utils/deviceSettings.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 +7 -0
- package/dist/utils/pro2Nft.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/api/BaseMethod.ts +8 -1
- package/src/api/CheckAllFirmwareRelease.ts +8 -5
- package/src/api/CheckBLEFirmwareRelease.ts +2 -2
- package/src/api/CheckBootloaderRelease.ts +3 -2
- package/src/api/CheckFirmwareRelease.ts +2 -2
- package/src/api/FirmwareUpdateV2.ts +130 -69
- package/src/api/FirmwareUpdateV3.ts +29 -19
- package/src/api/FirmwareUpdateV4.ts +966 -743
- package/src/api/OpenWalletSession.ts +39 -9
- package/src/api/PromptWebDeviceAccess.ts +2 -2
- package/src/api/SearchDevices.ts +6 -3
- package/src/api/UploadPortfolio.ts +9 -2
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +2 -1
- package/src/api/device/DeviceChangePin.ts +4 -1
- package/src/api/device/DeviceRebootToBoardloader.ts +3 -1
- package/src/api/device/DeviceRebootToBootloader.ts +3 -1
- package/src/api/device/DeviceSettings.ts +34 -20
- package/src/api/device/DeviceVerify.ts +25 -0
- package/src/api/device/DeviceWipe.ts +4 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +41 -14
- package/src/api/firmware/FirmwareHostBinding.ts +10 -0
- package/src/api/firmware/FirmwarePreparedResourceArchive.ts +16 -27
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +131 -76
- package/src/api/firmware/FirmwareUpdatePlan.ts +55 -82
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +32 -15
- package/src/api/firmware/protocolV2Release.ts +7 -2
- package/src/api/helpers/base64Data.ts +85 -0
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +6 -28
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +7 -1
- package/src/api/protocol-v2/DeviceInfoGet.ts +3 -3
- package/src/api/protocol-v2/DeviceReboot.ts +5 -0
- package/src/api/protocol-v2/DeviceUploadNft.ts +61 -9
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +53 -19
- package/src/api/protocol-v2/helpers.ts +8 -0
- package/src/api/ton/TonSignMessage.ts +5 -3
- package/src/core/index.ts +264 -55
- package/src/data/messages/messages-protocol-v2.json +140 -13
- package/src/data-manager/DataManager.ts +46 -39
- package/src/data-manager/TransportManager.ts +3 -1
- package/src/device/Device.ts +210 -44
- package/src/device/DeviceCommands.ts +27 -18
- package/src/device/DeviceConnector.ts +17 -3
- package/src/device/DevicePool.ts +9 -2
- package/src/device/DeviceStateMapper.ts +30 -24
- package/src/deviceProfile/buildDeviceFeatures.ts +10 -5
- package/src/events/logBlockEvent.ts +14 -1
- package/src/events/ui-request.ts +3 -0
- package/src/index.ts +0 -10
- package/src/protocols/protocol-v2/features.ts +22 -5
- package/src/protocols/protocol-v2/index.ts +2 -0
- package/src/protocols/protocol-v2/resources.ts +110 -147
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +13 -1
- package/src/protocols/protocol-v2/walletSession.ts +65 -22
- package/src/types/api/firmwareUpdate.ts +1 -1
- package/src/types/api/firmwareUpdatePlan.ts +2 -2
- package/src/types/api/protocolV2.ts +1 -1
- package/src/types/device.ts +2 -1
- package/src/types/settings.ts +6 -34
- package/src/utils/deviceFeaturesCompat.ts +9 -4
- package/src/utils/deviceFeaturesUtils.ts +4 -0
- package/src/utils/deviceInfoUtils.ts +9 -2
- package/src/utils/deviceSettings.ts +11 -4
- package/src/utils/index.ts +1 -0
- package/src/utils/pro2Nft.ts +31 -8
- package/__tests__/firmware-memory-host.test.ts +0 -112
- package/dist/api/firmware/FirmwareMemoryHost.d.ts +0 -22
- package/dist/api/firmware/FirmwareMemoryHost.d.ts.map +0 -1
- package/src/api/firmware/FirmwareMemoryHost.ts +0 -142
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import {
|
|
3
|
-
PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS,
|
|
4
|
-
PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
|
|
5
|
-
isProtocolV2DeviceDisconnectedError,
|
|
6
|
-
normalizeFirmwareTargets,
|
|
7
|
-
} from './helpers';
|
|
8
|
-
import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
2
|
+
import { isProtocolV2DeviceDisconnectedError, normalizeFirmwareTargets } from './helpers';
|
|
9
3
|
|
|
10
|
-
import type { KnownDevice } from '../../types';
|
|
11
|
-
import type { MessageFromOneKey } from '@onekeyfe/hd-transport';
|
|
12
4
|
import type { DeviceFirmwareUpdateParams } from './helpers';
|
|
13
5
|
|
|
14
6
|
export default class DeviceFirmwareUpdate extends BaseMethod<DeviceFirmwareUpdateParams> {
|
|
@@ -31,27 +23,13 @@ export default class DeviceFirmwareUpdate extends BaseMethod<DeviceFirmwareUpdat
|
|
|
31
23
|
async run() {
|
|
32
24
|
const targets = normalizeFirmwareTargets(this.params);
|
|
33
25
|
try {
|
|
34
|
-
|
|
26
|
+
await this.device.commands.typedCall('DeviceFirmwareUpdateStage', 'Success', { targets });
|
|
27
|
+
await this.device.commands.call(
|
|
35
28
|
'DeviceFirmwareUpdateRequest',
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
targets,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
...PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS,
|
|
42
|
-
onIntermediateResponse: (response: MessageFromOneKey) => {
|
|
43
|
-
if (response.type !== 'DeviceFirmwareUpdateStatus') return;
|
|
44
|
-
this.postMessage(
|
|
45
|
-
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
46
|
-
device: this.device.toMessageObject() as KnownDevice,
|
|
47
|
-
progress: 99,
|
|
48
|
-
progressType: 'installingFirmware',
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
},
|
|
52
|
-
}
|
|
29
|
+
{},
|
|
30
|
+
{ returnAfterWrite: true }
|
|
53
31
|
);
|
|
54
|
-
return
|
|
32
|
+
return { message: 'Device firmware update started' };
|
|
55
33
|
} catch (error) {
|
|
56
34
|
if (isProtocolV2DeviceDisconnectedError(error)) {
|
|
57
35
|
return {
|
|
@@ -4,7 +4,13 @@ import { invalidParameter } from '../helpers/filesystemValidation';
|
|
|
4
4
|
import type { DeviceFirmwareUpdateStatusGetParams } from './helpers';
|
|
5
5
|
import type { DeviceFirmwareUpdateRecordFields } from '@onekeyfe/hd-transport';
|
|
6
6
|
|
|
7
|
-
const DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS = [
|
|
7
|
+
const DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS = [
|
|
8
|
+
'status',
|
|
9
|
+
'progress_percent',
|
|
10
|
+
'phase_info',
|
|
11
|
+
'payload_version',
|
|
12
|
+
'path',
|
|
13
|
+
] as const;
|
|
8
14
|
|
|
9
15
|
function normalizeStatusFields(
|
|
10
16
|
fields: DeviceFirmwareUpdateStatusGetParams['fields']
|
|
@@ -5,7 +5,7 @@ import { invalidParameter } from '../helpers/filesystemValidation';
|
|
|
5
5
|
|
|
6
6
|
export type DeviceInfoGetTargets = {
|
|
7
7
|
hw?: boolean;
|
|
8
|
-
|
|
8
|
+
main_mcu?: boolean;
|
|
9
9
|
coprocessor?: boolean;
|
|
10
10
|
se1?: boolean;
|
|
11
11
|
se2?: boolean;
|
|
@@ -27,7 +27,7 @@ export type DeviceInfoGetParams = {
|
|
|
27
27
|
|
|
28
28
|
const TARGET_KEYS: (keyof DeviceInfoGetTargets)[] = [
|
|
29
29
|
'hw',
|
|
30
|
-
'
|
|
30
|
+
'main_mcu',
|
|
31
31
|
'coprocessor',
|
|
32
32
|
'se1',
|
|
33
33
|
'se2',
|
|
@@ -39,7 +39,7 @@ const TYPE_KEYS: (keyof DeviceInfoGetTypes)[] = ['version', 'build_id', 'hash',
|
|
|
39
39
|
|
|
40
40
|
const DEFAULT_TARGETS: DeviceInfoGetTargets = {
|
|
41
41
|
hw: true,
|
|
42
|
-
|
|
42
|
+
main_mcu: true,
|
|
43
43
|
coprocessor: true,
|
|
44
44
|
};
|
|
45
45
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
1
3
|
import { BaseMethod } from '../BaseMethod';
|
|
2
4
|
import { normalizeRebootType } from './helpers';
|
|
3
5
|
|
|
@@ -11,6 +13,9 @@ export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
|
|
|
11
13
|
init() {
|
|
12
14
|
this.skipForceUpdateCheck = true;
|
|
13
15
|
this.useDevicePassphraseState = false;
|
|
16
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
17
|
+
// Device-management action: main PIN or Attach PIN may authorize reboot.
|
|
18
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
14
19
|
this.params = {
|
|
15
20
|
rebootType: this.payload.rebootType,
|
|
16
21
|
reboot_type: this.payload.reboot_type,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode, createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
3
4
|
import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
4
5
|
import { supportsProtocolV2Message } from '../../protocols/protocol-v2/features';
|
|
@@ -7,21 +8,26 @@ import {
|
|
|
7
8
|
PRO2_NFT_DEFAULT_PACE_MS,
|
|
8
9
|
PRO2_NFT_DEFAULT_TIMEOUT_MS,
|
|
9
10
|
PRO2_NFT_DIRECTORY,
|
|
11
|
+
PRO2_NFT_IMAGE_HEIGHT,
|
|
12
|
+
PRO2_NFT_IMAGE_WIDTH,
|
|
10
13
|
PRO2_NFT_MAX_CHUNK_SIZE,
|
|
11
14
|
PRO2_NFT_MAX_ITEMS,
|
|
12
15
|
PRO2_NFT_MIN_CHUNK_SIZE,
|
|
16
|
+
PRO2_NFT_THUMBNAIL_HEIGHT,
|
|
17
|
+
PRO2_NFT_THUMBNAIL_WIDTH,
|
|
13
18
|
type Pro2NftBundle,
|
|
14
|
-
|
|
15
|
-
buildPro2NftBundle,
|
|
19
|
+
buildPro2NftBundleFromEncodedImages,
|
|
16
20
|
getCompletePro2NftBasenames,
|
|
17
21
|
} from '../../utils/pro2Nft';
|
|
22
|
+
import { encodePro2Image } from '../../utils/pro2Wallpaper';
|
|
18
23
|
import { BaseMethod } from '../BaseMethod';
|
|
24
|
+
import { decodeJpegBase64ToRgba } from '../helpers/base64Data';
|
|
19
25
|
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
20
26
|
import { writeProtocolV2File } from '../helpers/protocolV2FileWrite';
|
|
21
27
|
|
|
22
28
|
export type DeviceUploadNftParams = {
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
imageJpegBase64: string;
|
|
30
|
+
thumbnailJpegBase64: string;
|
|
25
31
|
title: string;
|
|
26
32
|
subtitle: string;
|
|
27
33
|
timestampMs?: number;
|
|
@@ -54,8 +60,8 @@ export default class DeviceUploadNft extends BaseMethod<DeviceUploadNftParams> {
|
|
|
54
60
|
|
|
55
61
|
init() {
|
|
56
62
|
const {
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
imageJpegBase64,
|
|
64
|
+
thumbnailJpegBase64,
|
|
59
65
|
title,
|
|
60
66
|
subtitle,
|
|
61
67
|
timestampMs = Date.now(),
|
|
@@ -79,9 +85,55 @@ export default class DeviceUploadNft extends BaseMethod<DeviceUploadNftParams> {
|
|
|
79
85
|
throw invalidParameter('Parameter [timeoutMs] must be a positive integer.');
|
|
80
86
|
}
|
|
81
87
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
const encodedImage = (() => {
|
|
89
|
+
const decoded = decodeJpegBase64ToRgba({
|
|
90
|
+
jpegBase64: imageJpegBase64,
|
|
91
|
+
parameterName: 'imageJpegBase64',
|
|
92
|
+
expectedWidth: PRO2_NFT_IMAGE_WIDTH,
|
|
93
|
+
expectedHeight: PRO2_NFT_IMAGE_HEIGHT,
|
|
94
|
+
});
|
|
95
|
+
return encodePro2Image({
|
|
96
|
+
width: PRO2_NFT_IMAGE_WIDTH,
|
|
97
|
+
height: PRO2_NFT_IMAGE_HEIGHT,
|
|
98
|
+
rgba: decoded.data,
|
|
99
|
+
alphaMode: 'black-background',
|
|
100
|
+
}).data;
|
|
101
|
+
})();
|
|
102
|
+
const encodedThumbnail = (() => {
|
|
103
|
+
const decoded = decodeJpegBase64ToRgba({
|
|
104
|
+
jpegBase64: thumbnailJpegBase64,
|
|
105
|
+
parameterName: 'thumbnailJpegBase64',
|
|
106
|
+
expectedWidth: PRO2_NFT_THUMBNAIL_WIDTH,
|
|
107
|
+
expectedHeight: PRO2_NFT_THUMBNAIL_HEIGHT,
|
|
108
|
+
});
|
|
109
|
+
return encodePro2Image({
|
|
110
|
+
width: PRO2_NFT_THUMBNAIL_WIDTH,
|
|
111
|
+
height: PRO2_NFT_THUMBNAIL_HEIGHT,
|
|
112
|
+
rgba: decoded.data,
|
|
113
|
+
alphaMode: 'black-background',
|
|
114
|
+
}).data;
|
|
115
|
+
})();
|
|
116
|
+
this.bundle = buildPro2NftBundleFromEncodedImages({
|
|
117
|
+
image: encodedImage,
|
|
118
|
+
thumbnail: encodedThumbnail,
|
|
119
|
+
title,
|
|
120
|
+
subtitle,
|
|
121
|
+
timestampMs,
|
|
122
|
+
});
|
|
123
|
+
this.params = {
|
|
124
|
+
imageJpegBase64,
|
|
125
|
+
thumbnailJpegBase64,
|
|
126
|
+
title,
|
|
127
|
+
subtitle,
|
|
128
|
+
timestampMs,
|
|
129
|
+
chunkSize,
|
|
130
|
+
paceMs,
|
|
131
|
+
timeoutMs,
|
|
132
|
+
};
|
|
133
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
134
|
+
// File writes and NftUpdate require an unlocked device. Either PIN may
|
|
135
|
+
// authorize this device-management action.
|
|
136
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
85
137
|
this.skipForceUpdateCheck = true;
|
|
86
138
|
this.useDevicePassphraseState = false;
|
|
87
139
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { blake2s } from '@noble/hashes/blake2s';
|
|
2
2
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
3
|
+
import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
4
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
3
5
|
|
|
4
6
|
import { BaseMethod } from '../BaseMethod';
|
|
7
|
+
import { decodeJpegBase64ToRgba } from '../helpers/base64Data';
|
|
5
8
|
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
6
9
|
import { writeProtocolV2File } from '../helpers/protocolV2FileWrite';
|
|
7
10
|
import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
11
|
+
import { supportsProtocolV2Message } from '../../protocols/protocol-v2/features';
|
|
12
|
+
import { LoggerNames, getLogger } from '../../utils';
|
|
8
13
|
import {
|
|
9
14
|
PRO2_WALLPAPER_HEIGHT,
|
|
10
15
|
PRO2_WALLPAPER_WIDTH,
|
|
@@ -13,9 +18,7 @@ import {
|
|
|
13
18
|
} from '../../utils/pro2Wallpaper';
|
|
14
19
|
|
|
15
20
|
export type DeviceUploadWallpaperParams = {
|
|
16
|
-
|
|
17
|
-
height: number;
|
|
18
|
-
rgba: Uint8Array | ArrayBuffer;
|
|
21
|
+
jpegBase64: string;
|
|
19
22
|
fileName?: string;
|
|
20
23
|
chunkSize?: number;
|
|
21
24
|
};
|
|
@@ -29,6 +32,10 @@ export type DeviceUploadWallpaperResponse = {
|
|
|
29
32
|
|
|
30
33
|
const WALLPAPER_DIRECTORY = 'vol1:/wallpapers';
|
|
31
34
|
const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
35
|
+
const DEVICE_SETTINGS_SET_MESSAGE_TYPE = 60412;
|
|
36
|
+
const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE = 60805;
|
|
37
|
+
const FILESYSTEM_DIR_MAKE_MESSAGE_TYPE = 60809;
|
|
38
|
+
const Log = getLogger(LoggerNames.Method);
|
|
32
39
|
|
|
33
40
|
function normalizeFileName(fileName: string | undefined, data: Uint8Array): string {
|
|
34
41
|
if (fileName !== undefined && (!fileName || !SAFE_FILE_NAME.test(fileName))) {
|
|
@@ -54,31 +61,48 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
54
61
|
private path = '';
|
|
55
62
|
|
|
56
63
|
init() {
|
|
57
|
-
const {
|
|
58
|
-
if (width !== PRO2_WALLPAPER_WIDTH || height !== PRO2_WALLPAPER_HEIGHT) {
|
|
59
|
-
throw invalidParameter(
|
|
60
|
-
`Pro2 wallpaper dimensions must be ${PRO2_WALLPAPER_WIDTH}x${PRO2_WALLPAPER_HEIGHT}.`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
if (!(rgba instanceof ArrayBuffer) && !ArrayBuffer.isView(rgba)) {
|
|
64
|
-
throw invalidParameter('Parameter [rgba] must be an ArrayBuffer or Uint8Array.');
|
|
65
|
-
}
|
|
64
|
+
const { jpegBase64, fileName, chunkSize } = this.payload;
|
|
66
65
|
if (chunkSize !== undefined && (!Number.isInteger(chunkSize) || chunkSize <= 0)) {
|
|
67
66
|
throw invalidParameter('Parameter [chunkSize] must be a positive integer.');
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
const decoded = decodeJpegBase64ToRgba({
|
|
70
|
+
jpegBase64,
|
|
71
|
+
parameterName: 'jpegBase64',
|
|
72
|
+
expectedWidth: PRO2_WALLPAPER_WIDTH,
|
|
73
|
+
expectedHeight: PRO2_WALLPAPER_HEIGHT,
|
|
74
|
+
});
|
|
75
|
+
this.encoded = encodePro2Wallpaper({
|
|
76
|
+
width: PRO2_WALLPAPER_WIDTH,
|
|
77
|
+
height: PRO2_WALLPAPER_HEIGHT,
|
|
78
|
+
rgba: decoded.data,
|
|
79
|
+
});
|
|
75
80
|
this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
|
|
76
|
-
this.params = {
|
|
77
|
-
this.unlockPolicy = '
|
|
81
|
+
this.params = { jpegBase64, fileName, chunkSize };
|
|
82
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
83
|
+
// File writes and wallpaper apply require an unlocked device. Either PIN
|
|
84
|
+
// may authorize this device-management action.
|
|
85
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
78
86
|
this.skipForceUpdateCheck = true;
|
|
79
87
|
this.useDevicePassphraseState = false;
|
|
80
88
|
}
|
|
81
89
|
|
|
90
|
+
private async assertCapabilities() {
|
|
91
|
+
const protocolInfo = await this.device.ensureProtocolV2RuntimeContext();
|
|
92
|
+
const requiredMessageTypes = [
|
|
93
|
+
DEVICE_SETTINGS_SET_MESSAGE_TYPE,
|
|
94
|
+
FILESYSTEM_FILE_WRITE_MESSAGE_TYPE,
|
|
95
|
+
FILESYSTEM_DIR_MAKE_MESSAGE_TYPE,
|
|
96
|
+
];
|
|
97
|
+
if (
|
|
98
|
+
requiredMessageTypes.some(
|
|
99
|
+
messageType => !supportsProtocolV2Message(protocolInfo, messageType)
|
|
100
|
+
)
|
|
101
|
+
) {
|
|
102
|
+
throw createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
82
106
|
private async ensureDirectory() {
|
|
83
107
|
if (this.directoryReady) return;
|
|
84
108
|
try {
|
|
@@ -119,11 +143,21 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
119
143
|
async run(): Promise<DeviceUploadWallpaperResponse> {
|
|
120
144
|
const { encoded } = this;
|
|
121
145
|
if (!encoded) throw invalidParameter('Wallpaper data has not been initialized.');
|
|
146
|
+
await this.assertCapabilities();
|
|
122
147
|
await this.ensureDirectory();
|
|
123
148
|
await this.upload();
|
|
124
149
|
const response = await this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
125
150
|
settings: { wallpaper_path: this.path },
|
|
126
151
|
});
|
|
152
|
+
try {
|
|
153
|
+
await this.device.refreshProtocolV2SettingsAfterMutation();
|
|
154
|
+
} catch (error) {
|
|
155
|
+
// The wallpaper is already applied. A transient read-back failure must not
|
|
156
|
+
// make callers retry the completed file upload.
|
|
157
|
+
Log.warn('Protocol V2 wallpaper settings refresh failed after apply', {
|
|
158
|
+
error: error instanceof Error ? error.message : String(error),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
127
161
|
return {
|
|
128
162
|
path: this.path,
|
|
129
163
|
size: encoded.data.byteLength,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
|
+
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
3
|
|
|
3
4
|
import { invalidParameter, validateNonEmptyString } from '../helpers/filesystemValidation';
|
|
4
5
|
import { ProtocolV2FirmwareTargetType } from '../../protocols/protocol-v2/firmware';
|
|
@@ -103,6 +104,13 @@ export const getProtocolV2UnknownErrorText = (error: unknown) => {
|
|
|
103
104
|
};
|
|
104
105
|
|
|
105
106
|
export const isProtocolV2DeviceDisconnectedError = (error: unknown) => {
|
|
107
|
+
const errorCode =
|
|
108
|
+
error && typeof error === 'object'
|
|
109
|
+
? (error as { errorCode?: number; code?: number }).errorCode ??
|
|
110
|
+
(error as { errorCode?: number; code?: number }).code
|
|
111
|
+
: undefined;
|
|
112
|
+
if (errorCode === HardwareErrorCode.BleDeviceDisconnected) return true;
|
|
113
|
+
|
|
106
114
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
107
115
|
const compactMessage = message.replace(/\s+/g, '');
|
|
108
116
|
return (
|
|
@@ -174,12 +174,14 @@ export default class TonSignMessage extends BaseMethod<HardwareTonSignMessage> {
|
|
|
174
174
|
if (!request.init_data_length) {
|
|
175
175
|
const deviceType = this.device.getCurrentDeviceType();
|
|
176
176
|
const hasClassic = DeviceModelToTypes.model_classic1s.includes(deviceType);
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
const signingMessage = request.signing_message ?? request.signning_message;
|
|
178
|
+
// Blind signing omits the signing message in both protocol schemas.
|
|
179
|
+
const shouldSkipValidation = signingMessage == null;
|
|
179
180
|
|
|
180
181
|
return Promise.resolve({
|
|
181
182
|
...request,
|
|
182
|
-
|
|
183
|
+
signing_message: signingMessage,
|
|
184
|
+
skip_validate: hasClassic || shouldSkipValidation,
|
|
183
185
|
});
|
|
184
186
|
}
|
|
185
187
|
|