@onekeyfe/hd-core 1.2.0-alpha.66 → 1.2.0-alpha.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +0 -313
- package/__tests__/DeviceCommands.test.ts +13 -59
- package/__tests__/DeviceEventRegistration.test.ts +0 -6
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +3 -198
- package/__tests__/connectSettings.test.ts +47 -5
- package/__tests__/device-initialize-timeout.test.ts +56 -0
- package/__tests__/device-lifecycle-events.test.ts +3 -105
- package/__tests__/device-pool-state.test.ts +0 -22
- package/__tests__/device-settings.test.ts +18 -39
- package/__tests__/device-state-contract.test.ts +0 -1
- package/__tests__/device-state-mapper.test.ts +1 -13
- package/__tests__/device-utils.test.ts +1 -48
- package/__tests__/deviceSettings.test.ts +1 -11
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +175 -0
- package/__tests__/firmware-update/device-update-bootloader.test.ts +87 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
- package/__tests__/firmware-update/firmware-preparation-error.test.ts +27 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +200 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +394 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +231 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +59 -31
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +12 -132
- package/__tests__/homescreen.test.ts +1 -41
- package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
- package/__tests__/kaspaSignTransaction.test.ts +26 -3
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +0 -19
- package/__tests__/open-wallet-session.test.ts +37 -568
- package/__tests__/protocol-v2-unlock-policy.test.ts +37 -300
- package/__tests__/protocol-v2.test.ts +1153 -1458
- package/__tests__/protocolV2FileWrite.test.ts +0 -152
- package/__tests__/protocolV2UiInteraction.test.ts +0 -63
- package/__tests__/public-pro2-api-boundary.test.ts +0 -1
- package/__tests__/search-devices.test.ts +3 -12
- package/__tests__/tron-sign-message-init.test.ts +2 -2
- package/dist/api/BaseMethod.d.ts +1 -3
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +1 -2
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +10 -0
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +7 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +27 -13
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +2 -2
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +25 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts +3 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +11 -4
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +25 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +32 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts +7 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- package/dist/api/firmware/updateBootloader.d.ts +2 -0
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +9 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +0 -9
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
- package/dist/api/polkadot/networks.d.ts +1 -1
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +2 -2
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +1 -1
- package/dist/api/ton/TonSignProof.d.ts +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +2 -2
- package/dist/api/tron/TronSignTransaction.d.ts +1 -1
- package/dist/core/deviceEventRegistration.d.ts +0 -2
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +4 -9
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +6 -29
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +1 -2
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -1
- package/dist/events/device.d.ts +0 -4
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-promise.d.ts +2 -4
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +2 -31
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +2 -10
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +247 -243
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3773 -3054
- package/dist/inject.d.ts +1 -6
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +4 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +4 -7
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +3 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +1 -6
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +5 -3
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +1 -5
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +4 -2
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +70 -4
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +28 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +10 -7
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +0 -3
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -2
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +0 -1
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +21 -38
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +1 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +0 -4
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +0 -4
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Wallpaper.d.ts +0 -10
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +10 -8
- package/src/api/CheckAllFirmwareRelease.ts +60 -59
- package/src/api/FirmwareUpdate.ts +15 -7
- package/src/api/FirmwareUpdateV2.ts +298 -126
- package/src/api/FirmwareUpdateV3.ts +265 -63
- package/src/api/FirmwareUpdateV4.ts +1017 -602
- package/src/api/GetPassphraseState.ts +1 -7
- package/src/api/OpenWalletSession.ts +17 -71
- package/src/api/SearchDevices.ts +1 -3
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -36
- package/src/api/device/DeviceSettings.ts +4 -5
- package/src/api/device/DeviceUnlock.ts +3 -8
- package/src/api/device/DeviceUpdateBootloader.ts +125 -6
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwarePreparationError.ts +12 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +83 -27
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +772 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +449 -0
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +144 -39
- package/src/api/helpers/protocolV2FileWrite.ts +63 -202
- package/src/api/index.ts +0 -2
- package/src/api/kaspa/KaspaGetAddress.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +13 -2
- package/src/api/polkadot/networks.ts +3 -3
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -3
- package/src/api/protocol-v2/helpers.ts +1 -1
- package/src/api/solana/SolSignMessage.ts +1 -1
- package/src/api/solana/SolSignOffchainMessage.ts +1 -1
- package/src/api/solana/SolSignTransaction.ts +2 -2
- package/src/api/sui/SuiGetAddress.ts +1 -1
- package/src/api/sui/SuiGetPublicKey.ts +1 -1
- package/src/api/sui/SuiSignMessage.ts +1 -1
- package/src/api/sui/SuiSignTransaction.ts +1 -1
- package/src/api/ton/TonGetAddress.ts +1 -1
- package/src/api/ton/TonSignMessage.ts +1 -1
- package/src/api/ton/TonSignProof.ts +1 -1
- package/src/api/tron/TronSignMessage.ts +2 -2
- package/src/api/tron/TronSignTransaction.ts +1 -1
- package/src/core/deviceEventRegistration.ts +0 -4
- package/src/core/index.ts +111 -213
- package/src/data/messages/messages-protocol-v2.json +0 -25
- package/src/data-manager/DataManager.ts +41 -113
- package/src/data-manager/TransportManager.ts +0 -6
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +49 -274
- package/src/device/DeviceCommands.ts +4 -31
- package/src/device/DeviceConnector.ts +13 -33
- package/src/device/DevicePool.ts +7 -21
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +0 -3
- package/src/events/device.ts +0 -4
- package/src/events/logBlockEvent.ts +0 -1
- package/src/events/ui-promise.ts +2 -4
- package/src/events/ui-request.ts +2 -36
- package/src/events/ui-response.ts +2 -12
- package/src/index.ts +5 -0
- package/src/inject.ts +24 -60
- package/src/lowLevelInject.ts +8 -7
- package/src/protocols/protocol-v2/features.ts +7 -10
- package/src/protocols/protocol-v2/firmware.ts +0 -2
- package/src/protocols/protocol-v2/lockedError.ts +10 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +6 -46
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -1
- package/src/protocols/protocol-v2/unlockRetry.ts +109 -0
- package/src/protocols/protocol-v2/walletSession.ts +36 -214
- package/src/topLevelInject.ts +8 -7
- package/src/types/api/checkAllFirmwareRelease.ts +5 -3
- package/src/types/api/deviceUnlock.ts +1 -12
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +18 -1
- package/src/types/api/firmwareUpdate.ts +78 -6
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +38 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
- package/src/types/api/index.ts +14 -13
- package/src/types/api/protocolV2.ts +0 -13
- package/src/types/device.ts +3 -15
- package/src/types/params.ts +1 -7
- package/src/types/settings.ts +22 -60
- package/src/utils/deviceFeaturesCompat.ts +6 -5
- package/src/utils/deviceFeaturesUtils.ts +3 -14
- package/src/utils/deviceInfoUtils.ts +0 -2
- package/src/utils/deviceSettings.ts +0 -3
- package/src/utils/homescreen.ts +6 -32
- package/src/utils/index.ts +1 -6
- package/src/utils/pro2Wallpaper.ts +8 -35
- package/__tests__/core-initialization.test.ts +0 -23
- package/__tests__/device-connector-protocol.test.ts +0 -81
- package/__tests__/deviceUploadNft.test.ts +0 -316
- package/__tests__/pro2Nft.test.ts +0 -108
- package/__tests__/protocol-binding.test.ts +0 -89
- package/__tests__/protocol-v2-resources.test.ts +0 -340
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +0 -91
- package/__tests__/uiProgressThrottle.test.ts +0 -74
- package/__tests__/uiPromiseRegistry.test.ts +0 -115
- package/dist/api/DetectDeviceConnectProtocol.d.ts +0 -7
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +0 -31
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +0 -1
- package/dist/core/uiPromiseRegistry.d.ts +0 -6
- package/dist/core/uiPromiseRegistry.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/resources.d.ts +0 -30
- package/dist/protocols/protocol-v2/resources.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -22
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +0 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +0 -4
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/utils/pro2Nft.d.ts +0 -31
- package/dist/utils/pro2Nft.d.ts.map +0 -1
- package/dist/utils/uiProgressThrottle.d.ts +0 -3
- package/dist/utils/uiProgressThrottle.d.ts.map +0 -1
- package/src/api/DetectDeviceConnectProtocol.ts +0 -18
- package/src/api/protocol-v2/DeviceUploadNft.ts +0 -197
- package/src/core/uiPromiseRegistry.ts +0 -63
- package/src/protocols/protocol-v2/resources.ts +0 -390
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -131
- package/src/types/api/detectDeviceConnectProtocol.ts +0 -6
- package/src/utils/pro2Nft.ts +0 -142
- package/src/utils/uiProgressThrottle.ts +0 -63
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UI_REQUEST, createUiMessage } from '../../events';
|
|
2
2
|
|
|
3
|
-
import type { CoreMessage,
|
|
3
|
+
import type { CoreMessage, ProtocolV2UiCompletion } from '../../events';
|
|
4
4
|
import type { Device } from '../../device/Device';
|
|
5
5
|
import type { KnownDevice } from '../../types';
|
|
6
6
|
|
|
@@ -28,15 +28,7 @@ type ProtocolV2InteractionMethod = {
|
|
|
28
28
|
protocolV2UiInteraction?: ProtocolV2InteractionDescriptor;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
type InteractionDevice = Pick<Device, 'isProtocolV2' | 'toMessageObject'
|
|
32
|
-
Partial<
|
|
33
|
-
Pick<
|
|
34
|
-
Device,
|
|
35
|
-
| 'createProtocolV2UiPhaseMetadata'
|
|
36
|
-
| 'finishProtocolV2UiInteraction'
|
|
37
|
-
| 'hasOpenProtocolV2UiInteraction'
|
|
38
|
-
>
|
|
39
|
-
>;
|
|
31
|
+
type InteractionDevice = Pick<Device, 'isProtocolV2' | 'toMessageObject'>;
|
|
40
32
|
type PostMessage = (message: CoreMessage) => void;
|
|
41
33
|
|
|
42
34
|
export const isProtocolV2UiEnabled = (method: { protocolV2UiMode?: 'auto' | 'none' }) =>
|
|
@@ -164,17 +156,12 @@ export class ProtocolV2UiInteractionCoordinator {
|
|
|
164
156
|
this.methodInteraction = interaction;
|
|
165
157
|
if (!interaction) return;
|
|
166
158
|
const { request, ...metadata } = interaction;
|
|
167
|
-
const interactionMeta = this.device.createProtocolV2UiPhaseMetadata?.(
|
|
168
|
-
request === 'pin' ? 'pin' : 'button',
|
|
169
|
-
'start'
|
|
170
|
-
);
|
|
171
159
|
|
|
172
160
|
this.emit(
|
|
173
161
|
request === 'pin' ? UI_REQUEST.REQUEST_PIN : UI_REQUEST.REQUEST_BUTTON,
|
|
174
162
|
{
|
|
175
163
|
device: this.device.toMessageObject() as KnownDevice,
|
|
176
164
|
...metadata,
|
|
177
|
-
...(interactionMeta ? { interaction: interactionMeta } : {}),
|
|
178
165
|
},
|
|
179
166
|
`method:${request}:${interaction.reason}:${interaction.page ?? ''}:${
|
|
180
167
|
interaction.operation ?? ''
|
|
@@ -182,8 +169,7 @@ export class ProtocolV2UiInteractionCoordinator {
|
|
|
182
169
|
);
|
|
183
170
|
}
|
|
184
171
|
|
|
185
|
-
enterUnlockInteraction(method?: string)
|
|
186
|
-
const interaction = this.device.createProtocolV2UiPhaseMetadata?.('pin', 'start');
|
|
172
|
+
enterUnlockInteraction(method?: string) {
|
|
187
173
|
this.emit(
|
|
188
174
|
UI_REQUEST.REQUEST_PIN,
|
|
189
175
|
{
|
|
@@ -192,45 +178,19 @@ export class ProtocolV2UiInteractionCoordinator {
|
|
|
192
178
|
reason: 'device-locked',
|
|
193
179
|
deviceOnly: true,
|
|
194
180
|
method,
|
|
195
|
-
...(interaction ? { interaction } : {}),
|
|
196
181
|
},
|
|
197
182
|
`unlock:${method ?? ''}`
|
|
198
183
|
);
|
|
199
|
-
return interaction;
|
|
200
184
|
}
|
|
201
185
|
|
|
202
186
|
resumeMethodInteraction() {
|
|
203
187
|
this.enterMethodInteraction(this.methodInteraction);
|
|
204
188
|
}
|
|
205
189
|
|
|
206
|
-
close(
|
|
207
|
-
|
|
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;
|
|
190
|
+
close() {
|
|
191
|
+
if (!this.device.isProtocolV2() || !this.opened || this.closed) return;
|
|
220
192
|
this.closed = true;
|
|
221
|
-
|
|
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;
|
|
193
|
+
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
|
|
234
194
|
}
|
|
235
195
|
|
|
236
196
|
private emit(
|
|
@@ -1 +1,105 @@
|
|
|
1
|
-
export type UnlockPolicy = 'none' | 'unlock-before-run';
|
|
1
|
+
export type UnlockPolicy = 'none' | 'unlock-before-run' | 'retry-on-locked';
|
|
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';
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { LoggerNames, getLogger } from '../../utils';
|
|
2
|
+
import { isDeviceLockedError } from './lockedError';
|
|
3
|
+
import { isProtocolV2UiEnabled, resolveProtocolV2UiInteraction } from './uiInteraction';
|
|
4
|
+
import { refreshProtocolV2DeviceStatus, restoreProtocolV2WalletSession } from './walletSession';
|
|
5
|
+
|
|
6
|
+
import type { BaseMethod } from '../../api/BaseMethod';
|
|
7
|
+
import type { Device } from '../../device/Device';
|
|
8
|
+
import type { ProtocolV2UiInteractionCoordinator } from './uiInteraction';
|
|
9
|
+
|
|
10
|
+
const Log = getLogger(LoggerNames.Core);
|
|
11
|
+
|
|
12
|
+
type RunnableMethod = Pick<
|
|
13
|
+
BaseMethod,
|
|
14
|
+
| 'run'
|
|
15
|
+
| 'unlockPolicy'
|
|
16
|
+
| 'protocolV2UiInteraction'
|
|
17
|
+
| 'protocolV2UiMode'
|
|
18
|
+
| 'params'
|
|
19
|
+
| 'payload'
|
|
20
|
+
| 'useDevicePassphraseState'
|
|
21
|
+
> & { name?: string };
|
|
22
|
+
type UiInteractionCoordinator = Pick<
|
|
23
|
+
ProtocolV2UiInteractionCoordinator,
|
|
24
|
+
'enterMethodInteraction' | 'enterUnlockInteraction' | 'resumeMethodInteraction'
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
const restoreExpectedWalletSessionAfterUnlock = async (method: RunnableMethod, device: Device) => {
|
|
28
|
+
const expectedPassphraseState = method.payload?.useEmptyPassphrase
|
|
29
|
+
? undefined
|
|
30
|
+
: method.payload?.passphraseState ?? device.passphraseState;
|
|
31
|
+
if (
|
|
32
|
+
!method.useDevicePassphraseState ||
|
|
33
|
+
typeof expectedPassphraseState !== 'string' ||
|
|
34
|
+
expectedPassphraseState.length === 0
|
|
35
|
+
) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await restoreProtocolV2WalletSession(device, expectedPassphraseState);
|
|
40
|
+
Log.debug('Protocol V2 wallet session restored after unlock', { method: method.name });
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export async function runMethodWithUnlockRetry(
|
|
44
|
+
method: RunnableMethod,
|
|
45
|
+
device: Device,
|
|
46
|
+
uiCoordinator?: UiInteractionCoordinator
|
|
47
|
+
) {
|
|
48
|
+
const shouldEmitUi = isProtocolV2UiEnabled(method);
|
|
49
|
+
const isProtocolV2 = device.isProtocolV2();
|
|
50
|
+
const requiresFreshStatus =
|
|
51
|
+
isProtocolV2 &&
|
|
52
|
+
method.unlockPolicy === 'unlock-before-run' &&
|
|
53
|
+
!device.isBootloader?.() &&
|
|
54
|
+
!device.isRomloader?.();
|
|
55
|
+
|
|
56
|
+
if (requiresFreshStatus) {
|
|
57
|
+
await refreshProtocolV2DeviceStatus(device);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const shouldUnlockBeforeRun =
|
|
61
|
+
isProtocolV2 &&
|
|
62
|
+
method.unlockPolicy !== 'none' &&
|
|
63
|
+
!device.isBootloader?.() &&
|
|
64
|
+
!device.isRomloader?.() &&
|
|
65
|
+
device.features?.unlocked === false;
|
|
66
|
+
|
|
67
|
+
if (shouldUnlockBeforeRun) {
|
|
68
|
+
if (shouldEmitUi) {
|
|
69
|
+
uiCoordinator?.enterUnlockInteraction(method.name);
|
|
70
|
+
}
|
|
71
|
+
await device.unlockDevice();
|
|
72
|
+
Log.debug('Protocol V2 pre-unlock completed', { method: method.name });
|
|
73
|
+
await restoreExpectedWalletSessionAfterUnlock(method, device);
|
|
74
|
+
if (shouldEmitUi) {
|
|
75
|
+
uiCoordinator?.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
|
|
76
|
+
}
|
|
77
|
+
return method.run();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (shouldEmitUi) {
|
|
81
|
+
uiCoordinator?.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return await method.run();
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (!isProtocolV2 || method.unlockPolicy !== 'retry-on-locked' || !isDeviceLockedError(error)) {
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Log.debug('Protocol V2 unlock retry triggered', { method: method.name });
|
|
91
|
+
if (shouldEmitUi) {
|
|
92
|
+
uiCoordinator?.enterUnlockInteraction(method.name);
|
|
93
|
+
}
|
|
94
|
+
await device.unlockDevice();
|
|
95
|
+
Log.debug('Protocol V2 unlock completed', { method: method.name });
|
|
96
|
+
await restoreExpectedWalletSessionAfterUnlock(method, device);
|
|
97
|
+
if (shouldEmitUi) {
|
|
98
|
+
uiCoordinator?.resumeMethodInteraction();
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const response = await method.run();
|
|
102
|
+
Log.debug('Protocol V2 method retry completed', { method: method.name, success: true });
|
|
103
|
+
return response;
|
|
104
|
+
} catch (retryError) {
|
|
105
|
+
Log.debug('Protocol V2 method retry completed', { method: method.name, success: false });
|
|
106
|
+
throw retryError;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|