@onekeyfe/hd-core 1.2.0-alpha.67 → 1.2.0-alpha.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +313 -0
- package/__tests__/DeviceCommands.test.ts +59 -13
- package/__tests__/DeviceEventRegistration.test.ts +6 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +226 -3
- package/__tests__/connectSettings.test.ts +5 -47
- package/__tests__/core-initialization.test.ts +23 -0
- package/__tests__/device-connector-protocol.test.ts +81 -0
- package/__tests__/device-lifecycle-events.test.ts +105 -3
- package/__tests__/device-pool-state.test.ts +22 -0
- package/__tests__/device-settings.test.ts +39 -18
- package/__tests__/device-state-contract.test.ts +1 -0
- package/__tests__/device-state-mapper.test.ts +13 -1
- package/__tests__/device-utils.test.ts +48 -1
- package/__tests__/deviceSettings.test.ts +11 -1
- package/__tests__/deviceUploadNft.test.ts +316 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +31 -59
- package/__tests__/get-device-state.test.ts +132 -12
- package/__tests__/homescreen.test.ts +41 -1
- package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
- package/__tests__/kaspaSignTransaction.test.ts +3 -26
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +19 -0
- package/__tests__/open-wallet-session.test.ts +568 -37
- package/__tests__/pro2Nft.test.ts +108 -0
- package/__tests__/protocol-binding.test.ts +89 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +33 -1
- package/__tests__/protocol-v2-resources.test.ts +343 -0
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
- package/__tests__/protocol-v2-unlock-policy.test.ts +300 -37
- package/__tests__/protocol-v2.test.ts +1586 -1213
- package/__tests__/protocolV2FileWrite.test.ts +193 -0
- package/__tests__/protocolV2UiInteraction.test.ts +63 -0
- package/__tests__/public-pro2-api-boundary.test.ts +1 -0
- package/__tests__/search-devices.test.ts +12 -3
- package/__tests__/tron-sign-message-init.test.ts +2 -2
- package/__tests__/uiProgressThrottle.test.ts +74 -0
- package/__tests__/uiPromiseRegistry.test.ts +115 -0
- package/dist/api/BaseMethod.d.ts +3 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +3 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/DetectDeviceConnectProtocol.d.ts +7 -0
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +0 -10
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +3 -7
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +15 -27
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +2 -2
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -5
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +4 -11
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +0 -7
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +0 -2
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +1 -9
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +9 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
- package/dist/api/polkadot/networks.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +31 -0
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +2 -2
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +1 -1
- package/dist/api/ton/TonSignProof.d.ts +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +2 -2
- package/dist/api/tron/TronSignTransaction.d.ts +1 -1
- package/dist/core/deviceEventRegistration.d.ts +2 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/uiPromiseRegistry.d.ts +6 -0
- package/dist/core/uiPromiseRegistry.d.ts.map +1 -0
- package/dist/data-manager/DataManager.d.ts +9 -4
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +29 -6
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +2 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -1
- package/dist/events/device.d.ts +4 -0
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-promise.d.ts +4 -2
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +31 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +10 -2
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +243 -247
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3135 -3785
- package/dist/inject.d.ts +6 -1
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +0 -4
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/resources.d.ts +30 -0
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +7 -4
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +1 -3
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +6 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +3 -5
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +4 -0
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/types/api/deviceUnlock.d.ts +5 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +2 -4
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +4 -70
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +7 -10
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -2
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +38 -21
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +0 -1
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +4 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +4 -0
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Nft.d.ts +31 -0
- package/dist/utils/pro2Nft.d.ts.map +1 -0
- package/dist/utils/pro2Wallpaper.d.ts +10 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/dist/utils/uiProgressThrottle.d.ts +3 -0
- package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +8 -10
- package/src/api/CheckAllFirmwareRelease.ts +78 -64
- package/src/api/DetectDeviceConnectProtocol.ts +18 -0
- package/src/api/FirmwareUpdate.ts +7 -15
- package/src/api/FirmwareUpdateV2.ts +126 -298
- package/src/api/FirmwareUpdateV3.ts +63 -265
- package/src/api/FirmwareUpdateV4.ts +645 -1018
- package/src/api/GetPassphraseState.ts +7 -1
- package/src/api/OpenWalletSession.ts +71 -17
- package/src/api/SearchDevices.ts +3 -1
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +36 -11
- package/src/api/device/DeviceSettings.ts +5 -4
- package/src/api/device/DeviceUnlock.ts +8 -3
- package/src/api/device/DeviceUpdateBootloader.ts +6 -125
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -83
- package/src/api/firmware/updateBootloader.ts +4 -19
- package/src/api/firmware/uploadFirmware.ts +39 -144
- package/src/api/helpers/protocolV2FileWrite.ts +252 -63
- package/src/api/index.ts +2 -0
- package/src/api/kaspa/KaspaGetAddress.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +2 -13
- package/src/api/polkadot/networks.ts +3 -3
- package/src/api/protocol-v2/DeviceUploadNft.ts +197 -0
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +3 -1
- package/src/api/protocol-v2/helpers.ts +1 -1
- package/src/api/solana/SolSignMessage.ts +1 -1
- package/src/api/solana/SolSignOffchainMessage.ts +1 -1
- package/src/api/solana/SolSignTransaction.ts +2 -2
- package/src/api/sui/SuiGetAddress.ts +1 -1
- package/src/api/sui/SuiGetPublicKey.ts +1 -1
- package/src/api/sui/SuiSignMessage.ts +1 -1
- package/src/api/sui/SuiSignTransaction.ts +1 -1
- package/src/api/ton/TonGetAddress.ts +1 -1
- package/src/api/ton/TonSignMessage.ts +1 -1
- package/src/api/ton/TonSignProof.ts +1 -1
- package/src/api/tron/TronSignMessage.ts +2 -2
- package/src/api/tron/TronSignTransaction.ts +1 -1
- package/src/core/deviceEventRegistration.ts +4 -0
- package/src/core/index.ts +213 -111
- package/src/core/uiPromiseRegistry.ts +63 -0
- package/src/data/messages/messages-protocol-v2.json +25 -0
- package/src/data-manager/DataManager.ts +113 -41
- package/src/data-manager/TransportManager.ts +6 -0
- package/src/data-manager/connectSettings.ts +0 -11
- package/src/device/Device.ts +274 -49
- package/src/device/DeviceCommands.ts +31 -4
- package/src/device/DeviceConnector.ts +33 -13
- package/src/device/DevicePool.ts +21 -7
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +3 -0
- package/src/events/device.ts +4 -0
- package/src/events/logBlockEvent.ts +1 -0
- package/src/events/ui-promise.ts +4 -2
- package/src/events/ui-request.ts +36 -2
- package/src/events/ui-response.ts +12 -2
- package/src/index.ts +0 -5
- package/src/inject.ts +60 -24
- package/src/lowLevelInject.ts +7 -8
- package/src/protocols/protocol-v2/features.ts +10 -7
- package/src/protocols/protocol-v2/firmware.ts +2 -0
- package/src/protocols/protocol-v2/resources.ts +394 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +46 -6
- package/src/protocols/protocol-v2/unlockPolicy.ts +1 -105
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +131 -0
- package/src/protocols/protocol-v2/walletSession.ts +214 -36
- package/src/topLevelInject.ts +7 -8
- package/src/types/api/checkAllFirmwareRelease.ts +3 -5
- package/src/types/api/detectDeviceConnectProtocol.ts +6 -0
- package/src/types/api/deviceUnlock.ts +12 -1
- package/src/types/api/deviceUpdateBootloader.ts +0 -6
- package/src/types/api/export.ts +1 -18
- package/src/types/api/firmwareUpdate.ts +6 -78
- package/src/types/api/index.ts +13 -14
- package/src/types/api/protocolV2.ts +13 -0
- package/src/types/device.ts +15 -3
- package/src/types/params.ts +7 -1
- package/src/types/settings.ts +61 -22
- package/src/utils/deviceFeaturesCompat.ts +5 -6
- package/src/utils/deviceFeaturesUtils.ts +14 -3
- package/src/utils/deviceInfoUtils.ts +2 -0
- package/src/utils/deviceSettings.ts +3 -0
- package/src/utils/homescreen.ts +32 -6
- package/src/utils/index.ts +6 -1
- package/src/utils/pro2Nft.ts +142 -0
- package/src/utils/pro2Wallpaper.ts +35 -8
- package/src/utils/uiProgressThrottle.ts +63 -0
- package/__tests__/device-initialize-timeout.test.ts +0 -56
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +0 -175
- package/__tests__/firmware-update/device-update-bootloader.test.ts +0 -87
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
- package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
- package/__tests__/firmware-update/firmware-preparation-error.test.ts +0 -27
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +0 -200
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +0 -394
- package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -593
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -231
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +0 -58
- package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -25
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
- package/dist/api/firmware/FirmwarePreparationError.d.ts +0 -3
- package/dist/api/firmware/FirmwarePreparationError.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -25
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -32
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/dist/api/firmware/progressThrottle.d.ts +0 -3
- package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -10
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePlan.d.ts +0 -28
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
- package/src/api/firmware/FirmwareHostBinding.ts +0 -100
- package/src/api/firmware/FirmwarePreparationError.ts +0 -12
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -772
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -449
- package/src/api/firmware/progressThrottle.ts +0 -44
- package/src/protocols/protocol-v2/lockedError.ts +0 -10
- package/src/protocols/protocol-v2/unlockRetry.ts +0 -109
- package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
- package/src/types/api/firmwareUpdatePlan.ts +0 -38
- package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
2
|
+
import { PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE } from '@onekeyfe/hd-transport';
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
IProtocolV2BootResources,
|
|
6
|
+
IProtocolV2Resource,
|
|
7
|
+
IProtocolV2ResourceFile,
|
|
8
|
+
IProtocolV2ResourceType,
|
|
9
|
+
IProtocolV2Resources,
|
|
10
|
+
} from '../../types';
|
|
11
|
+
import type { DeviceCommands } from '../../device/DeviceCommands';
|
|
12
|
+
|
|
13
|
+
export const PROTOCOL_V2_RESOURCE_TYPES = [
|
|
14
|
+
'images',
|
|
15
|
+
'animation',
|
|
16
|
+
'wallpaper',
|
|
17
|
+
'translations',
|
|
18
|
+
'roobert',
|
|
19
|
+
'noto',
|
|
20
|
+
'firmware_logo',
|
|
21
|
+
] as const satisfies readonly IProtocolV2ResourceType[];
|
|
22
|
+
|
|
23
|
+
export const PROTOCOL_V2_RESOURCE_DEVICE_PATHS: Readonly<Record<IProtocolV2ResourceType, string>> =
|
|
24
|
+
{
|
|
25
|
+
images: 'vol0:/bundles/images/images.okpkg',
|
|
26
|
+
animation: 'vol0:/bundles/images/animation.okpkg',
|
|
27
|
+
wallpaper: 'vol0:/bundles/images/wallpaper.okpkg',
|
|
28
|
+
translations: 'vol0:/bundles/translations/translations.okpkg',
|
|
29
|
+
roobert: 'vol0:/bundles/font/roobert.okpkg',
|
|
30
|
+
noto: 'vol0:/bundles/font/noto.okpkg',
|
|
31
|
+
firmware_logo: 'vol0:/bundles/firmware_logo.okpkg',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const RESOURCE_TYPE_SET = new Set<string>(PROTOCOL_V2_RESOURCE_TYPES);
|
|
35
|
+
const SHA256_HEX_LENGTH = 64;
|
|
36
|
+
const SHA3_512_HEX_LENGTH = 128;
|
|
37
|
+
const PROTOCOL_V2_OKPP_HEADER_SIZE = 0x52a0;
|
|
38
|
+
const PROTOCOL_V2_OKPP_TYPE_OFFSET = 0x08;
|
|
39
|
+
const PROTOCOL_V2_OKPP_HEADER_LENGTH_OFFSET = 0x0c;
|
|
40
|
+
const PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET = 0x240;
|
|
41
|
+
const PROTOCOL_V2_OKPP_HASH_SIZE = 64;
|
|
42
|
+
const PROTOCOL_V2_RESOURCE_IDENTITY_READ_SIZE =
|
|
43
|
+
PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET + PROTOCOL_V2_OKPP_HASH_SIZE;
|
|
44
|
+
const PROTOCOL_V2_MIN_FILE_READ_CHUNK_SIZE = 64;
|
|
45
|
+
export const PROTOCOL_V2_RESOURCE_INVENTORY_TIMEOUT_MS = 5 * 1000;
|
|
46
|
+
|
|
47
|
+
export type ProtocolV2ResourceInventoryItem = {
|
|
48
|
+
type: IProtocolV2ResourceType;
|
|
49
|
+
size: number;
|
|
50
|
+
headerHash: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type ProtocolV2ResourceUpdateMode = 'application' | 'bootloader-recovery';
|
|
54
|
+
|
|
55
|
+
export type ProtocolV2ResourceUpdatePlan = {
|
|
56
|
+
status: 'valid' | 'outdated' | 'unknown';
|
|
57
|
+
resources: IProtocolV2Resource[];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function toFiniteNumber(value: unknown): number | undefined {
|
|
61
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value;
|
|
62
|
+
if (typeof value === 'string') {
|
|
63
|
+
const numeric = Number(value);
|
|
64
|
+
return Number.isFinite(numeric) ? numeric : undefined;
|
|
65
|
+
}
|
|
66
|
+
if (value && typeof value === 'object') {
|
|
67
|
+
const longLike = value as { toNumber?: () => number };
|
|
68
|
+
if (typeof longLike.toNumber === 'function') {
|
|
69
|
+
const numeric = longLike.toNumber();
|
|
70
|
+
return Number.isFinite(numeric) ? numeric : undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function toUint8Array(value: unknown): Uint8Array {
|
|
77
|
+
if (value instanceof Uint8Array) return value;
|
|
78
|
+
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
79
|
+
if (ArrayBuffer.isView(value)) {
|
|
80
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
81
|
+
}
|
|
82
|
+
if (typeof value === 'string') {
|
|
83
|
+
const hex = value.replace(/^0x/i, '');
|
|
84
|
+
if (!hex || hex.length % 2 !== 0 || /[^0-9a-f]/i.test(hex)) {
|
|
85
|
+
return new Uint8Array(0);
|
|
86
|
+
}
|
|
87
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
88
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
89
|
+
bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
90
|
+
}
|
|
91
|
+
return bytes;
|
|
92
|
+
}
|
|
93
|
+
return new Uint8Array(0);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function readAscii(bytes: Uint8Array, offset: number, length: number): string {
|
|
97
|
+
return Array.from(bytes.slice(offset, offset + length), byte => String.fromCharCode(byte)).join(
|
|
98
|
+
''
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function parseProtocolV2ResourceHeaderHash(bytes: Uint8Array): string | undefined {
|
|
103
|
+
if (bytes.byteLength < PROTOCOL_V2_RESOURCE_IDENTITY_READ_SIZE) return undefined;
|
|
104
|
+
if (readAscii(bytes, 0, 4) !== 'OKPP') return undefined;
|
|
105
|
+
if (readAscii(bytes, PROTOCOL_V2_OKPP_TYPE_OFFSET, 4) !== 'RESC') return undefined;
|
|
106
|
+
|
|
107
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
108
|
+
if (
|
|
109
|
+
view.getUint32(PROTOCOL_V2_OKPP_HEADER_LENGTH_OFFSET, true) !== PROTOCOL_V2_OKPP_HEADER_SIZE
|
|
110
|
+
) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
return bytesToHex(
|
|
114
|
+
bytes.slice(
|
|
115
|
+
PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET,
|
|
116
|
+
PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET + PROTOCOL_V2_OKPP_HASH_SIZE
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function readProtocolV2ResourceIdentity({
|
|
122
|
+
commands,
|
|
123
|
+
resource,
|
|
124
|
+
chunkSize,
|
|
125
|
+
timeoutMs = PROTOCOL_V2_RESOURCE_INVENTORY_TIMEOUT_MS,
|
|
126
|
+
}: {
|
|
127
|
+
commands: Pick<DeviceCommands, 'typedCall'>;
|
|
128
|
+
resource: IProtocolV2Resource;
|
|
129
|
+
chunkSize: number;
|
|
130
|
+
timeoutMs?: number;
|
|
131
|
+
}): Promise<ProtocolV2ResourceInventoryItem | undefined> {
|
|
132
|
+
const path = PROTOCOL_V2_RESOURCE_DEVICE_PATHS[resource.type];
|
|
133
|
+
const pathInfo = await commands.typedCall(
|
|
134
|
+
'FilesystemPathInfoQuery',
|
|
135
|
+
'FilesystemPathInfo',
|
|
136
|
+
{ path },
|
|
137
|
+
{ timeoutMs }
|
|
138
|
+
);
|
|
139
|
+
const size = toFiniteNumber(pathInfo.message?.size);
|
|
140
|
+
if (
|
|
141
|
+
!pathInfo.message?.exist ||
|
|
142
|
+
pathInfo.message?.directory ||
|
|
143
|
+
!Number.isSafeInteger(size) ||
|
|
144
|
+
size !== resource.size ||
|
|
145
|
+
size < PROTOCOL_V2_OKPP_HEADER_SIZE
|
|
146
|
+
) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const header = new Uint8Array(PROTOCOL_V2_RESOURCE_IDENTITY_READ_SIZE);
|
|
151
|
+
let offset = 0;
|
|
152
|
+
while (offset < header.byteLength) {
|
|
153
|
+
const readLength = Math.min(chunkSize, header.byteLength - offset);
|
|
154
|
+
const response = await commands.typedCall(
|
|
155
|
+
'FilesystemFileRead',
|
|
156
|
+
'FilesystemFile',
|
|
157
|
+
{
|
|
158
|
+
file: { path, offset, total_size: 0 },
|
|
159
|
+
chunk_len: readLength,
|
|
160
|
+
},
|
|
161
|
+
{ timeoutMs }
|
|
162
|
+
);
|
|
163
|
+
const data = toUint8Array(response.message?.data);
|
|
164
|
+
if (data.byteLength === 0) return undefined;
|
|
165
|
+
const copied = Math.min(data.byteLength, header.byteLength - offset);
|
|
166
|
+
header.set(data.subarray(0, copied), offset);
|
|
167
|
+
offset += copied;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const headerHash = parseProtocolV2ResourceHeaderHash(header);
|
|
171
|
+
return headerHash ? { type: resource.type, size, headerHash } : undefined;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 使用已发布 Pro2 固件支持的文件系统消息构建资源清单。
|
|
176
|
+
* 缺失、无法读取或格式错误的文件不会进入清单,因此会被选中重写。
|
|
177
|
+
*/
|
|
178
|
+
export async function readProtocolV2ResourceInventory({
|
|
179
|
+
commands,
|
|
180
|
+
resources,
|
|
181
|
+
chunkSize = PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE,
|
|
182
|
+
timeoutMs = PROTOCOL_V2_RESOURCE_INVENTORY_TIMEOUT_MS,
|
|
183
|
+
}: {
|
|
184
|
+
commands: Pick<DeviceCommands, 'typedCall'>;
|
|
185
|
+
resources: readonly IProtocolV2Resource[];
|
|
186
|
+
chunkSize?: number;
|
|
187
|
+
timeoutMs?: number;
|
|
188
|
+
}): Promise<ProtocolV2ResourceInventoryItem[]> {
|
|
189
|
+
const normalizedChunkSize = Number.isFinite(chunkSize)
|
|
190
|
+
? Math.max(Math.floor(chunkSize), PROTOCOL_V2_MIN_FILE_READ_CHUNK_SIZE)
|
|
191
|
+
: PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE;
|
|
192
|
+
const inventory: ProtocolV2ResourceInventoryItem[] = [];
|
|
193
|
+
for (const resource of resources) {
|
|
194
|
+
try {
|
|
195
|
+
const item = await readProtocolV2ResourceIdentity({
|
|
196
|
+
commands,
|
|
197
|
+
resource,
|
|
198
|
+
chunkSize: normalizedChunkSize,
|
|
199
|
+
timeoutMs,
|
|
200
|
+
});
|
|
201
|
+
if (item) inventory.push(item);
|
|
202
|
+
} catch {
|
|
203
|
+
// 单个资源无法读取时按缺失处理,不阻断其余资源的增量检查。
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return inventory;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function normalizeHex(value: unknown, expectedLength: number, field: string): string {
|
|
210
|
+
if (typeof value !== 'string') {
|
|
211
|
+
throw new Error(`Invalid Pro2 resource ${field}: expected a hexadecimal string`);
|
|
212
|
+
}
|
|
213
|
+
const normalized = value.replace(/^0x/i, '').toLowerCase();
|
|
214
|
+
if (normalized.length !== expectedLength || !/^[0-9a-f]+$/.test(normalized)) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`Invalid Pro2 resource ${field}: expected ${expectedLength} hexadecimal characters`
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
return normalized;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function validateResource(value: unknown, index: number): IProtocolV2Resource {
|
|
223
|
+
if (!value || typeof value !== 'object') {
|
|
224
|
+
throw new Error(`Invalid Pro2 resource at stable[${index}]`);
|
|
225
|
+
}
|
|
226
|
+
const resource = value as Partial<IProtocolV2Resource>;
|
|
227
|
+
if (typeof resource.type !== 'string' || !RESOURCE_TYPE_SET.has(resource.type)) {
|
|
228
|
+
throw new Error(`Invalid Pro2 resource type at stable[${index}]`);
|
|
229
|
+
}
|
|
230
|
+
if (typeof resource.url !== 'string' || !resource.url.startsWith('https://')) {
|
|
231
|
+
throw new Error(`Invalid Pro2 resource url at stable[${index}]`);
|
|
232
|
+
}
|
|
233
|
+
if (!Number.isSafeInteger(resource.size) || Number(resource.size) <= 0) {
|
|
234
|
+
throw new Error(`Invalid Pro2 resource size at stable[${index}]`);
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
type: resource.type,
|
|
238
|
+
url: resource.url,
|
|
239
|
+
size: Number(resource.size),
|
|
240
|
+
fileHash: normalizeHex(resource.fileHash, SHA256_HEX_LENGTH, 'fileHash'),
|
|
241
|
+
headerHash: normalizeHex(resource.headerHash, SHA3_512_HEX_LENGTH, 'headerHash'),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function validateBootResources(value: unknown): IProtocolV2BootResources {
|
|
246
|
+
if (!value || typeof value !== 'object') {
|
|
247
|
+
throw new Error('Invalid Pro2 boot resources config');
|
|
248
|
+
}
|
|
249
|
+
const resource = value as Partial<IProtocolV2BootResources>;
|
|
250
|
+
if (resource.required !== false) {
|
|
251
|
+
throw new Error('Invalid Pro2 boot resources required flag: expected false');
|
|
252
|
+
}
|
|
253
|
+
if (resource.target !== 'RES') {
|
|
254
|
+
throw new Error('Invalid Pro2 boot resources target: expected RES');
|
|
255
|
+
}
|
|
256
|
+
if (
|
|
257
|
+
resource.manifestUrl !== undefined &&
|
|
258
|
+
(typeof resource.manifestUrl !== 'string' || !resource.manifestUrl.startsWith('https://'))
|
|
259
|
+
) {
|
|
260
|
+
throw new Error('Invalid Pro2 boot resources manifestUrl');
|
|
261
|
+
}
|
|
262
|
+
if (!Array.isArray(resource.files) || resource.files.length === 0) {
|
|
263
|
+
throw new Error('Invalid Pro2 boot resources files');
|
|
264
|
+
}
|
|
265
|
+
const files = resource.files.map((value, index): IProtocolV2ResourceFile => {
|
|
266
|
+
if (!value || typeof value !== 'object') {
|
|
267
|
+
throw new Error(`Invalid Pro2 boot resource file at files[${index}]`);
|
|
268
|
+
}
|
|
269
|
+
const file = value as Partial<IProtocolV2ResourceFile>;
|
|
270
|
+
if (typeof file.url !== 'string' || !file.url.startsWith('https://')) {
|
|
271
|
+
throw new Error(`Invalid Pro2 boot resource url at files[${index}]`);
|
|
272
|
+
}
|
|
273
|
+
if (
|
|
274
|
+
typeof file.devicePath !== 'string' ||
|
|
275
|
+
!file.devicePath.startsWith('vol0:/') ||
|
|
276
|
+
file.devicePath.includes('..') ||
|
|
277
|
+
file.devicePath.includes('\\')
|
|
278
|
+
) {
|
|
279
|
+
throw new Error(`Invalid Pro2 boot resource devicePath at files[${index}]`);
|
|
280
|
+
}
|
|
281
|
+
if (!Number.isSafeInteger(file.size) || Number(file.size) <= 0) {
|
|
282
|
+
throw new Error(`Invalid Pro2 boot resource size at files[${index}]`);
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
...(typeof file.name === 'string' && file.name ? { name: file.name } : undefined),
|
|
286
|
+
url: file.url,
|
|
287
|
+
devicePath: file.devicePath,
|
|
288
|
+
size: Number(file.size),
|
|
289
|
+
fileHash: normalizeHex(file.fileHash, SHA256_HEX_LENGTH, `boot files[${index}].fileHash`),
|
|
290
|
+
};
|
|
291
|
+
});
|
|
292
|
+
if (new Set(files.map(file => file.devicePath)).size !== files.length) {
|
|
293
|
+
throw new Error('Invalid Pro2 boot resources files: duplicate devicePath');
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
required: false,
|
|
297
|
+
target: 'RES',
|
|
298
|
+
...(resource.manifestUrl ? { manifestUrl: resource.manifestUrl } : undefined),
|
|
299
|
+
files,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Validate a complete Pro2 stable resource set from remote configuration. */
|
|
304
|
+
export function parseProtocolV2Resources(value: unknown): IProtocolV2Resources | undefined {
|
|
305
|
+
if (value === undefined) return undefined;
|
|
306
|
+
if (
|
|
307
|
+
!value ||
|
|
308
|
+
typeof value !== 'object' ||
|
|
309
|
+
!Array.isArray((value as { stable?: unknown }).stable)
|
|
310
|
+
) {
|
|
311
|
+
throw new Error('Invalid Pro2 resources config: stable must be an array');
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const config = value as { stable: unknown[]; boot?: unknown };
|
|
315
|
+
const stable = config.stable.map(validateResource);
|
|
316
|
+
const types = new Set(stable.map(resource => resource.type));
|
|
317
|
+
if (stable.length !== PROTOCOL_V2_RESOURCE_TYPES.length || types.size !== stable.length) {
|
|
318
|
+
throw new Error(
|
|
319
|
+
`Invalid Pro2 resources config: stable must contain ${PROTOCOL_V2_RESOURCE_TYPES.length} unique resource types`
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
for (const type of PROTOCOL_V2_RESOURCE_TYPES) {
|
|
323
|
+
if (!types.has(type)) {
|
|
324
|
+
throw new Error(`Invalid Pro2 resources config: stable is missing ${type}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const boot = config.boot === undefined ? undefined : validateBootResources(config.boot);
|
|
328
|
+
return {
|
|
329
|
+
stable: PROTOCOL_V2_RESOURCE_TYPES.map(type => {
|
|
330
|
+
const resource = stable.find(item => item.type === type);
|
|
331
|
+
if (!resource) {
|
|
332
|
+
throw new Error(`Invalid Pro2 resources config: stable is missing ${type}`);
|
|
333
|
+
}
|
|
334
|
+
return resource;
|
|
335
|
+
}),
|
|
336
|
+
...(boot ? { boot } : undefined),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** 比较文件系统资源清单;恢复模式无法取得清单时回退到全量更新。 */
|
|
341
|
+
export function buildProtocolV2ResourceUpdatePlan({
|
|
342
|
+
resources,
|
|
343
|
+
inventory,
|
|
344
|
+
mode,
|
|
345
|
+
forced = false,
|
|
346
|
+
}: {
|
|
347
|
+
resources: readonly IProtocolV2Resource[];
|
|
348
|
+
inventory?: readonly ProtocolV2ResourceInventoryItem[];
|
|
349
|
+
mode: ProtocolV2ResourceUpdateMode;
|
|
350
|
+
forced?: boolean;
|
|
351
|
+
}): ProtocolV2ResourceUpdatePlan {
|
|
352
|
+
if (forced) {
|
|
353
|
+
return {
|
|
354
|
+
status: resources.length > 0 ? 'outdated' : 'valid',
|
|
355
|
+
resources: [...resources],
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (!inventory) {
|
|
359
|
+
return mode === 'bootloader-recovery'
|
|
360
|
+
? {
|
|
361
|
+
status: resources.length > 0 ? 'outdated' : 'valid',
|
|
362
|
+
resources: [...resources],
|
|
363
|
+
}
|
|
364
|
+
: { status: 'unknown', resources: [] };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const inventoryByType = new Map(inventory.map(item => [item.type, item]));
|
|
368
|
+
const changedResources = resources.filter(resource => {
|
|
369
|
+
const current = inventoryByType.get(resource.type);
|
|
370
|
+
return (
|
|
371
|
+
!current ||
|
|
372
|
+
current.size !== resource.size ||
|
|
373
|
+
current.headerHash.toLowerCase() !== resource.headerHash.toLowerCase()
|
|
374
|
+
);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
status: changedResources.length === 0 ? 'valid' : 'outdated',
|
|
379
|
+
resources: changedResources,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function bytesToHex(bytes: Uint8Array): string {
|
|
384
|
+
return Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Verify the complete downloaded file before any device mutation. */
|
|
388
|
+
export function isProtocolV2ResourceFileValid(
|
|
389
|
+
binary: ArrayBuffer,
|
|
390
|
+
resource: Pick<IProtocolV2ResourceFile, 'size' | 'fileHash'>
|
|
391
|
+
): boolean {
|
|
392
|
+
if (binary.byteLength !== resource.size) return false;
|
|
393
|
+
return bytesToHex(sha256(new Uint8Array(binary))) === resource.fileHash.toLowerCase();
|
|
394
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UI_REQUEST, createUiMessage } from '../../events';
|
|
2
2
|
|
|
3
|
-
import type { CoreMessage, ProtocolV2UiCompletion } from '../../events';
|
|
3
|
+
import type { CoreMessage, HardwareUiInteractionMeta, ProtocolV2UiCompletion } from '../../events';
|
|
4
4
|
import type { Device } from '../../device/Device';
|
|
5
5
|
import type { KnownDevice } from '../../types';
|
|
6
6
|
|
|
@@ -28,7 +28,15 @@ type ProtocolV2InteractionMethod = {
|
|
|
28
28
|
protocolV2UiInteraction?: ProtocolV2InteractionDescriptor;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
type InteractionDevice = Pick<Device, 'isProtocolV2' | 'toMessageObject'
|
|
31
|
+
type InteractionDevice = Pick<Device, 'isProtocolV2' | 'toMessageObject'> &
|
|
32
|
+
Partial<
|
|
33
|
+
Pick<
|
|
34
|
+
Device,
|
|
35
|
+
| 'createProtocolV2UiPhaseMetadata'
|
|
36
|
+
| 'finishProtocolV2UiInteraction'
|
|
37
|
+
| 'hasOpenProtocolV2UiInteraction'
|
|
38
|
+
>
|
|
39
|
+
>;
|
|
32
40
|
type PostMessage = (message: CoreMessage) => void;
|
|
33
41
|
|
|
34
42
|
export const isProtocolV2UiEnabled = (method: { protocolV2UiMode?: 'auto' | 'none' }) =>
|
|
@@ -156,12 +164,17 @@ export class ProtocolV2UiInteractionCoordinator {
|
|
|
156
164
|
this.methodInteraction = interaction;
|
|
157
165
|
if (!interaction) return;
|
|
158
166
|
const { request, ...metadata } = interaction;
|
|
167
|
+
const interactionMeta = this.device.createProtocolV2UiPhaseMetadata?.(
|
|
168
|
+
request === 'pin' ? 'pin' : 'button',
|
|
169
|
+
'start'
|
|
170
|
+
);
|
|
159
171
|
|
|
160
172
|
this.emit(
|
|
161
173
|
request === 'pin' ? UI_REQUEST.REQUEST_PIN : UI_REQUEST.REQUEST_BUTTON,
|
|
162
174
|
{
|
|
163
175
|
device: this.device.toMessageObject() as KnownDevice,
|
|
164
176
|
...metadata,
|
|
177
|
+
...(interactionMeta ? { interaction: interactionMeta } : {}),
|
|
165
178
|
},
|
|
166
179
|
`method:${request}:${interaction.reason}:${interaction.page ?? ''}:${
|
|
167
180
|
interaction.operation ?? ''
|
|
@@ -169,7 +182,8 @@ export class ProtocolV2UiInteractionCoordinator {
|
|
|
169
182
|
);
|
|
170
183
|
}
|
|
171
184
|
|
|
172
|
-
enterUnlockInteraction(method?: string) {
|
|
185
|
+
enterUnlockInteraction(method?: string): HardwareUiInteractionMeta | undefined {
|
|
186
|
+
const interaction = this.device.createProtocolV2UiPhaseMetadata?.('pin', 'start');
|
|
173
187
|
this.emit(
|
|
174
188
|
UI_REQUEST.REQUEST_PIN,
|
|
175
189
|
{
|
|
@@ -178,19 +192,45 @@ export class ProtocolV2UiInteractionCoordinator {
|
|
|
178
192
|
reason: 'device-locked',
|
|
179
193
|
deviceOnly: true,
|
|
180
194
|
method,
|
|
195
|
+
...(interaction ? { interaction } : {}),
|
|
181
196
|
},
|
|
182
197
|
`unlock:${method ?? ''}`
|
|
183
198
|
);
|
|
199
|
+
return interaction;
|
|
184
200
|
}
|
|
185
201
|
|
|
186
202
|
resumeMethodInteraction() {
|
|
187
203
|
this.enterMethodInteraction(this.methodInteraction);
|
|
188
204
|
}
|
|
189
205
|
|
|
190
|
-
close(
|
|
191
|
-
|
|
206
|
+
close(
|
|
207
|
+
options: {
|
|
208
|
+
ensureOperationClose?: boolean;
|
|
209
|
+
protocolV2Operation?: boolean;
|
|
210
|
+
} = {}
|
|
211
|
+
): boolean {
|
|
212
|
+
if (
|
|
213
|
+
(!options.protocolV2Operation && !this.device.isProtocolV2()) ||
|
|
214
|
+
(!options.ensureOperationClose &&
|
|
215
|
+
!this.opened &&
|
|
216
|
+
!this.device.hasOpenProtocolV2UiInteraction?.()) ||
|
|
217
|
+
this.closed
|
|
218
|
+
)
|
|
219
|
+
return false;
|
|
192
220
|
this.closed = true;
|
|
193
|
-
this.
|
|
221
|
+
const interaction = this.device.finishProtocolV2UiInteraction?.('succeeded', {
|
|
222
|
+
ensureMetadata: options.ensureOperationClose,
|
|
223
|
+
});
|
|
224
|
+
const device = this.device.toMessageObject();
|
|
225
|
+
this.postMessage(
|
|
226
|
+
interaction
|
|
227
|
+
? createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW, {
|
|
228
|
+
...interaction,
|
|
229
|
+
...(device ? { device } : {}),
|
|
230
|
+
})
|
|
231
|
+
: createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW)
|
|
232
|
+
);
|
|
233
|
+
return true;
|
|
194
234
|
}
|
|
195
235
|
|
|
196
236
|
private emit(
|
|
@@ -1,105 +1 @@
|
|
|
1
|
-
export type UnlockPolicy = 'none' | 'unlock-before-run'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Protocol V2 methods that are safe to replay after a locked response.
|
|
5
|
-
*
|
|
6
|
-
* Keep this as an exact allowlist. Name-pattern matching can silently make a new
|
|
7
|
-
* state-changing method replayable when it happens to share a suffix.
|
|
8
|
-
*/
|
|
9
|
-
export const PROTOCOL_V2_RETRY_ON_LOCKED_METHODS = [
|
|
10
|
-
'cipherKeyValue',
|
|
11
|
-
'allNetworkGetAddress',
|
|
12
|
-
'allNetworkGetAddressByLoop',
|
|
13
|
-
'btcGetAddress',
|
|
14
|
-
'btcGetPublicKey',
|
|
15
|
-
'btcSignMessage',
|
|
16
|
-
'btcSignPsbt',
|
|
17
|
-
'btcSignTransaction',
|
|
18
|
-
'btcVerifyMessage',
|
|
19
|
-
'confluxGetAddress',
|
|
20
|
-
'confluxSignMessage',
|
|
21
|
-
'confluxSignTransaction',
|
|
22
|
-
'evmGetAddress',
|
|
23
|
-
'evmGetPublicKey',
|
|
24
|
-
'evmSignMessage',
|
|
25
|
-
'evmSignTransaction',
|
|
26
|
-
'evmSignTypedData',
|
|
27
|
-
'evmVerifyMessage',
|
|
28
|
-
'starcoinGetAddress',
|
|
29
|
-
'starcoinGetPublicKey',
|
|
30
|
-
'starcoinSignMessage',
|
|
31
|
-
'starcoinSignTransaction',
|
|
32
|
-
'starcoinVerifyMessage',
|
|
33
|
-
'nemGetAddress',
|
|
34
|
-
'nemSignTransaction',
|
|
35
|
-
'solGetAddress',
|
|
36
|
-
'solSignTransaction',
|
|
37
|
-
'solSignOffchainMessage',
|
|
38
|
-
'solSignMessage',
|
|
39
|
-
'stellarGetAddress',
|
|
40
|
-
'stellarSignTransaction',
|
|
41
|
-
'tronGetAddress',
|
|
42
|
-
'tronSignMessage',
|
|
43
|
-
'tronSignTransaction',
|
|
44
|
-
'nearGetAddress',
|
|
45
|
-
'nearSignTransaction',
|
|
46
|
-
'aptosGetAddress',
|
|
47
|
-
'aptosGetPublicKey',
|
|
48
|
-
'aptosSignTransaction',
|
|
49
|
-
'aptosSignMessage',
|
|
50
|
-
'aptosSignInMessage',
|
|
51
|
-
'algoGetAddress',
|
|
52
|
-
'algoSignTransaction',
|
|
53
|
-
'cosmosGetAddress',
|
|
54
|
-
'cosmosGetPublicKey',
|
|
55
|
-
'cosmosSignTransaction',
|
|
56
|
-
'xrpGetAddress',
|
|
57
|
-
'xrpSignTransaction',
|
|
58
|
-
'suiGetAddress',
|
|
59
|
-
'suiGetPublicKey',
|
|
60
|
-
'suiSignMessage',
|
|
61
|
-
'suiSignTransaction',
|
|
62
|
-
'cardanoGetAddress',
|
|
63
|
-
'cardanoGetPublicKey',
|
|
64
|
-
'cardanoSignTransaction',
|
|
65
|
-
'cardanoSignMessage',
|
|
66
|
-
'filecoinGetAddress',
|
|
67
|
-
'filecoinSignTransaction',
|
|
68
|
-
'polkadotGetAddress',
|
|
69
|
-
'polkadotSignTransaction',
|
|
70
|
-
'kaspaGetAddress',
|
|
71
|
-
'kaspaSignTransaction',
|
|
72
|
-
'nexaGetAddress',
|
|
73
|
-
'nexaSignTransaction',
|
|
74
|
-
'nostrGetPublicKey',
|
|
75
|
-
'nostrSignEvent',
|
|
76
|
-
'nostrEncryptMessage',
|
|
77
|
-
'nostrDecryptMessage',
|
|
78
|
-
'nostrSignSchnorr',
|
|
79
|
-
'lnurlAuth',
|
|
80
|
-
'nervosGetAddress',
|
|
81
|
-
'nervosSignTransaction',
|
|
82
|
-
'dnxGetAddress',
|
|
83
|
-
'dnxSignTransaction',
|
|
84
|
-
'tonGetAddress',
|
|
85
|
-
'tonSignMessage',
|
|
86
|
-
'tonSignProof',
|
|
87
|
-
'tonSignData',
|
|
88
|
-
'scdoGetAddress',
|
|
89
|
-
'scdoSignTransaction',
|
|
90
|
-
'scdoSignMessage',
|
|
91
|
-
'alephiumGetAddress',
|
|
92
|
-
'alephiumSignTransaction',
|
|
93
|
-
'alephiumSignMessage',
|
|
94
|
-
'benfenGetAddress',
|
|
95
|
-
'benfenGetPublicKey',
|
|
96
|
-
'benfenSignMessage',
|
|
97
|
-
'benfenSignTransaction',
|
|
98
|
-
'neoGetAddress',
|
|
99
|
-
'neoSignTransaction',
|
|
100
|
-
] as const;
|
|
101
|
-
|
|
102
|
-
const retryOnLockedMethods = new Set<string>(PROTOCOL_V2_RETRY_ON_LOCKED_METHODS);
|
|
103
|
-
|
|
104
|
-
export const getProtocolV2UnlockPolicy = (methodName: string): UnlockPolicy =>
|
|
105
|
-
retryOnLockedMethods.has(methodName) ? 'retry-on-locked' : 'none';
|
|
1
|
+
export type UnlockPolicy = 'none' | 'unlock-before-run';
|