@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
package/src/device/Device.ts
CHANGED
|
@@ -74,9 +74,7 @@ import type { DeviceStateReadOptions } from '../types/api/getDeviceState';
|
|
|
74
74
|
import type {
|
|
75
75
|
DeviceButtonRequestPayload,
|
|
76
76
|
DeviceFeaturesPayload,
|
|
77
|
-
HardwareUiInteractionMeta,
|
|
78
77
|
PassphraseRequestPayload,
|
|
79
|
-
ProtocolV2UiEventMetadata,
|
|
80
78
|
} from '../events';
|
|
81
79
|
import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
82
80
|
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
@@ -95,10 +93,14 @@ export type InitOptions = {
|
|
|
95
93
|
passphraseState?: string;
|
|
96
94
|
deriveCardano?: boolean;
|
|
97
95
|
connectProtocol?: HardwareConnectProtocol;
|
|
98
|
-
forceProtocolDetection?: boolean;
|
|
99
96
|
protocolV2DeviceInfoTimeoutMs?: number;
|
|
100
97
|
/** Refresh Protocol V2 runtime state before returning discovery results. */
|
|
101
98
|
refreshRuntimeState?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Protocol V1 Initialize response timeout override. Reboot-wait polling passes a
|
|
101
|
+
* short value so an unanswered probe settles before the next poll tick.
|
|
102
|
+
*/
|
|
103
|
+
timeoutMs?: number;
|
|
102
104
|
};
|
|
103
105
|
|
|
104
106
|
export type RunOptions = {
|
|
@@ -135,8 +137,6 @@ const isProtocolV2DeviceStatusUnsupportedError = (error: unknown) => {
|
|
|
135
137
|
|
|
136
138
|
export interface DeviceEvents {
|
|
137
139
|
[DEVICE.PIN]: [Device, PROTO.PinMatrixRequestType | undefined, (err: any, pin: string) => void];
|
|
138
|
-
[DEVICE.PIN_ON_DEVICE]: [Device, DeviceSessionPinType, ProtocolV2UiEventMetadata?];
|
|
139
|
-
[DEVICE.PIN_ON_DEVICE_COMPLETE]: [Device, HardwareUiInteractionMeta];
|
|
140
140
|
[DEVICE.PASSPHRASE_ON_DEVICE]: [Device, PassphraseRequestPayload?];
|
|
141
141
|
[DEVICE.ATTACH_PIN_ON_DEVICE]: [Device, PassphraseRequestPayload?];
|
|
142
142
|
[DEVICE.BUTTON]: [Device, DeviceButtonRequestPayload];
|
|
@@ -235,24 +235,6 @@ export class Device extends EventEmitter {
|
|
|
235
235
|
/** Force the next initialization to reload DeviceInfo after reconnect or reboot. */
|
|
236
236
|
private protocolV2StateNeedsReload = false;
|
|
237
237
|
|
|
238
|
-
/** Runtime context negotiated once per active Protocol V2 link. */
|
|
239
|
-
private protocolV2RuntimeContext?: ProtocolInfo;
|
|
240
|
-
|
|
241
|
-
/** Coalesces concurrent first-use runtime negotiation on the same active link. */
|
|
242
|
-
private protocolV2RuntimeContextPromise?: Promise<ProtocolInfo>;
|
|
243
|
-
|
|
244
|
-
/** Invalidates an in-flight runtime-context response without adding a transport epoch. */
|
|
245
|
-
private protocolV2RuntimeContextRequestToken?: object;
|
|
246
|
-
|
|
247
|
-
private protocolV2UiInteraction?: {
|
|
248
|
-
interactionId: string;
|
|
249
|
-
phaseCounter: number;
|
|
250
|
-
sequence: number;
|
|
251
|
-
opened: boolean;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
private protocolV2UiInteractionCounter = 0;
|
|
255
|
-
|
|
256
238
|
get state() {
|
|
257
239
|
return this.stateStore.getState();
|
|
258
240
|
}
|
|
@@ -360,7 +342,7 @@ export class Device extends EventEmitter {
|
|
|
360
342
|
deviceId,
|
|
361
343
|
path: this.originalDescriptor?.path,
|
|
362
344
|
bleName,
|
|
363
|
-
name:
|
|
345
|
+
name: displayName || bleName || `OneKey ${deviceType?.toUpperCase()}`,
|
|
364
346
|
// Keep the legacy top-level field string-compatible while preserving
|
|
365
347
|
// the canonical nullable value at state.identity.label.
|
|
366
348
|
label: displayName ?? '',
|
|
@@ -378,10 +360,7 @@ export class Device extends EventEmitter {
|
|
|
378
360
|
* Device connect
|
|
379
361
|
* @returns {Promise<boolean>}
|
|
380
362
|
*/
|
|
381
|
-
connect(
|
|
382
|
-
connectProtocol?: HardwareConnectProtocol,
|
|
383
|
-
options?: { forceProtocolDetection?: boolean }
|
|
384
|
-
) {
|
|
363
|
+
connect(connectProtocol?: HardwareConnectProtocol) {
|
|
385
364
|
const env = DataManager.getSettings('env');
|
|
386
365
|
// eslint-disable-next-line no-async-promise-executor
|
|
387
366
|
return new Promise<boolean>(async (resolve, reject) => {
|
|
@@ -391,7 +370,7 @@ export class Device extends EventEmitter {
|
|
|
391
370
|
return;
|
|
392
371
|
}
|
|
393
372
|
try {
|
|
394
|
-
await this.acquire(connectProtocol
|
|
373
|
+
await this.acquire(connectProtocol);
|
|
395
374
|
resolve(true);
|
|
396
375
|
} catch (error) {
|
|
397
376
|
reject(error);
|
|
@@ -401,7 +380,7 @@ export class Device extends EventEmitter {
|
|
|
401
380
|
// 不存在 Session ID 或存在 Session ID 但设备在别处使用,都需要 acquire 获取最新 sessionID
|
|
402
381
|
if (!this.mainId || (!this.isUsedHere() && this.originalDescriptor)) {
|
|
403
382
|
try {
|
|
404
|
-
await this.acquire(connectProtocol
|
|
383
|
+
await this.acquire(connectProtocol);
|
|
405
384
|
resolve(true);
|
|
406
385
|
} catch (error) {
|
|
407
386
|
reject(error);
|
|
@@ -418,16 +397,11 @@ export class Device extends EventEmitter {
|
|
|
418
397
|
|
|
419
398
|
async acquire(
|
|
420
399
|
expectedProtocol?: HardwareConnectProtocol,
|
|
421
|
-
options?: { throwOnRunPromiseError?: boolean
|
|
400
|
+
options?: { throwOnRunPromiseError?: boolean }
|
|
422
401
|
) {
|
|
423
402
|
const env = DataManager.getSettings('env');
|
|
424
403
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
425
|
-
const
|
|
426
|
-
// A protocol stored after a successful probe is authoritative. Only the explicit
|
|
427
|
-
// first-connection/recovery path may bypass it and probe both protocols again.
|
|
428
|
-
const strictProtocol = options?.forceProtocolDetection
|
|
429
|
-
? undefined
|
|
430
|
-
: expectedProtocol ?? this.originalDescriptor.protocolType;
|
|
404
|
+
const protocolHint = expectedProtocol ? undefined : this.originalDescriptor.protocolType;
|
|
431
405
|
try {
|
|
432
406
|
let acquireResult: unknown;
|
|
433
407
|
if (DataManager.isBleConnect(env)) {
|
|
@@ -439,8 +413,8 @@ export class Device extends EventEmitter {
|
|
|
439
413
|
this.originalDescriptor.id,
|
|
440
414
|
undefined,
|
|
441
415
|
true,
|
|
442
|
-
|
|
443
|
-
|
|
416
|
+
expectedProtocol,
|
|
417
|
+
protocolHint
|
|
444
418
|
);
|
|
445
419
|
this.mainId = (acquireResult as any)?.uuid ?? '';
|
|
446
420
|
Log.debug('Expected uuid:', this.mainId);
|
|
@@ -449,31 +423,24 @@ export class Device extends EventEmitter {
|
|
|
449
423
|
this.originalDescriptor.path,
|
|
450
424
|
this.originalDescriptor.session,
|
|
451
425
|
undefined,
|
|
452
|
-
|
|
453
|
-
|
|
426
|
+
expectedProtocol,
|
|
427
|
+
protocolHint
|
|
454
428
|
);
|
|
455
429
|
this.mainId = acquireResult as string | undefined;
|
|
456
430
|
Log.debug('Expected session id:', this.mainId);
|
|
457
431
|
}
|
|
432
|
+
this.deviceAcquired = true;
|
|
433
|
+
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
434
|
+
|
|
458
435
|
// Propagate protocol version detected during acquire.
|
|
459
436
|
const detectedProtocol =
|
|
460
437
|
(acquireResult as { protocolType?: HardwareConnectProtocol } | undefined)?.protocolType ??
|
|
461
438
|
TransportManager.transport?.getProtocolType?.(
|
|
462
439
|
DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path
|
|
463
440
|
);
|
|
464
|
-
if (options?.forceProtocolDetection && !detectedProtocol) {
|
|
465
|
-
throw ERRORS.TypedError(
|
|
466
|
-
HardwareErrorCode.RuntimeError,
|
|
467
|
-
`Active protocol detection returned no protocol for ${
|
|
468
|
-
this.originalDescriptor.path || this.originalDescriptor.id
|
|
469
|
-
}`
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
441
|
if (detectedProtocol) {
|
|
473
442
|
this.originalDescriptor.protocolType = detectedProtocol;
|
|
474
443
|
}
|
|
475
|
-
this.deviceAcquired = true;
|
|
476
|
-
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
477
444
|
|
|
478
445
|
if (this.commands) {
|
|
479
446
|
await this.commands.dispose(false);
|
|
@@ -481,22 +448,6 @@ export class Device extends EventEmitter {
|
|
|
481
448
|
|
|
482
449
|
this.commands = new DeviceCommands(this, this.mainId ?? '');
|
|
483
450
|
} catch (error) {
|
|
484
|
-
if (options?.forceProtocolDetection) {
|
|
485
|
-
this.originalDescriptor.protocolType = previousProtocol;
|
|
486
|
-
const failedSession = this.mainId;
|
|
487
|
-
this.deviceAcquired = false;
|
|
488
|
-
if (failedSession) {
|
|
489
|
-
try {
|
|
490
|
-
await this.deviceConnector?.release?.(failedSession, false);
|
|
491
|
-
} catch (releaseError) {
|
|
492
|
-
Log.debug('Failed to release an unsuccessful protocol probe', releaseError);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
if (!DataManager.isBleConnect(env)) {
|
|
496
|
-
this.mainId = null;
|
|
497
|
-
this.updateDescriptor({ session: null } as DeviceDescriptor);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
451
|
if (options?.throwOnRunPromiseError) {
|
|
501
452
|
throw error;
|
|
502
453
|
}
|
|
@@ -696,7 +647,6 @@ export class Device extends EventEmitter {
|
|
|
696
647
|
// Most-specific model first; must match getMethodVersionRange in deviceInfoUtils,
|
|
697
648
|
// otherwise e.g. Classic1s resolves the looser model_mini range before model_classic1s.
|
|
698
649
|
const modelFallbacks: IDeviceModel[] = [
|
|
699
|
-
'model_pro2',
|
|
700
650
|
'model_classic1s',
|
|
701
651
|
'model_classic',
|
|
702
652
|
'model_mini',
|
|
@@ -716,8 +666,7 @@ export class Device extends EventEmitter {
|
|
|
716
666
|
if (
|
|
717
667
|
deviceType === EDeviceType.Touch ||
|
|
718
668
|
deviceType === EDeviceType.Pro ||
|
|
719
|
-
deviceType === EDeviceType.Pro2
|
|
720
|
-
deviceType === EDeviceType.Neo
|
|
669
|
+
deviceType === EDeviceType.Pro2
|
|
721
670
|
) {
|
|
722
671
|
return { support: true };
|
|
723
672
|
}
|
|
@@ -734,8 +683,7 @@ export class Device extends EventEmitter {
|
|
|
734
683
|
if (
|
|
735
684
|
deviceType === EDeviceType.Touch ||
|
|
736
685
|
deviceType === EDeviceType.Pro ||
|
|
737
|
-
deviceType === EDeviceType.Pro2
|
|
738
|
-
deviceType === EDeviceType.Neo
|
|
686
|
+
deviceType === EDeviceType.Pro2
|
|
739
687
|
) {
|
|
740
688
|
return { support: false };
|
|
741
689
|
}
|
|
@@ -908,7 +856,7 @@ export class Device extends EventEmitter {
|
|
|
908
856
|
const initStartAt = Date.now();
|
|
909
857
|
const { message } = await this.commands.typedCall('Initialize', 'Features', payload, {
|
|
910
858
|
// iOS BLE bound devices can need close to 20 seconds.
|
|
911
|
-
timeoutMs: 25 * 1000,
|
|
859
|
+
timeoutMs: options?.timeoutMs ?? 25 * 1000,
|
|
912
860
|
});
|
|
913
861
|
this.setLastInitializeDuration(Date.now() - initStartAt);
|
|
914
862
|
this._updateFeatures(message, initSession);
|
|
@@ -1021,10 +969,7 @@ export class Device extends EventEmitter {
|
|
|
1021
969
|
await this.getFeatures();
|
|
1022
970
|
}
|
|
1023
971
|
|
|
1024
|
-
|
|
1025
|
-
this.getCurrentDeviceType() === EDeviceType.Touch ||
|
|
1026
|
-
this.getCurrentDeviceType() === EDeviceType.Pro;
|
|
1027
|
-
if (!this.isProtocolV2() && refresh.has('verification') && supportsProtocolV1OnekeyFeatures) {
|
|
972
|
+
if (!this.isProtocolV2() && refresh.has('verification')) {
|
|
1028
973
|
const { message } = await this.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
1029
974
|
this.updateState(mapProtocolV1OnekeyFeaturesToState(message), 'device-info');
|
|
1030
975
|
}
|
|
@@ -1047,7 +992,13 @@ export class Device extends EventEmitter {
|
|
|
1047
992
|
}
|
|
1048
993
|
|
|
1049
994
|
if (refresh.has('status') && !initializedWithDeviceInfo) {
|
|
1050
|
-
|
|
995
|
+
const deviceInfo =
|
|
996
|
+
refreshedDeviceInfo ??
|
|
997
|
+
(await requestProtocolV2DeviceInfo({
|
|
998
|
+
commands: this.commands,
|
|
999
|
+
request: getProtocolV2DeviceInfoRequest(),
|
|
1000
|
+
}));
|
|
1001
|
+
await this.probeProtocolV2RuntimeState(deviceInfo);
|
|
1051
1002
|
}
|
|
1052
1003
|
|
|
1053
1004
|
if (refresh.has('settings') && this.state?.status.mode === 'normal') {
|
|
@@ -1118,66 +1069,19 @@ export class Device extends EventEmitter {
|
|
|
1118
1069
|
return this.features;
|
|
1119
1070
|
}
|
|
1120
1071
|
|
|
1121
|
-
async
|
|
1122
|
-
const
|
|
1123
|
-
this.
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
: undefined);
|
|
1127
|
-
if (cachedProtocolInfo) {
|
|
1128
|
-
this.protocolV2RuntimeContext = cachedProtocolInfo;
|
|
1129
|
-
return cachedProtocolInfo;
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
if (this.protocolV2RuntimeContextPromise) {
|
|
1133
|
-
return this.protocolV2RuntimeContextPromise;
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
const requestToken = {};
|
|
1137
|
-
const pendingRequest = (async () => {
|
|
1138
|
-
const protocolInfo = await requestProtocolV2ProtocolInfo({
|
|
1139
|
-
commands: this.commands,
|
|
1140
|
-
timeoutMs,
|
|
1141
|
-
});
|
|
1142
|
-
if (this.protocolV2RuntimeContextRequestToken !== requestToken) {
|
|
1143
|
-
throw ERRORS.TypedError(
|
|
1144
|
-
HardwareErrorCode.DeviceInitializeFailed,
|
|
1145
|
-
'Protocol V2 runtime context was invalidated while loading.'
|
|
1146
|
-
);
|
|
1147
|
-
}
|
|
1148
|
-
this.protocolV2RuntimeContext = protocolInfo;
|
|
1149
|
-
return protocolInfo;
|
|
1150
|
-
})();
|
|
1151
|
-
this.protocolV2RuntimeContextRequestToken = requestToken;
|
|
1152
|
-
this.protocolV2RuntimeContextPromise = pendingRequest;
|
|
1153
|
-
|
|
1154
|
-
try {
|
|
1155
|
-
return await pendingRequest;
|
|
1156
|
-
} finally {
|
|
1157
|
-
if (this.protocolV2RuntimeContextPromise === pendingRequest) {
|
|
1158
|
-
this.protocolV2RuntimeContextPromise = undefined;
|
|
1159
|
-
}
|
|
1160
|
-
if (this.protocolV2RuntimeContextRequestToken === requestToken) {
|
|
1161
|
-
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
async probeProtocolV2RuntimeState(deviceInfo?: ProtocolV2DeviceInfo, timeoutMs?: number) {
|
|
1167
|
-
const protocolInfo = await this.ensureProtocolV2RuntimeContext(timeoutMs);
|
|
1072
|
+
async probeProtocolV2RuntimeState(deviceInfo: ProtocolV2DeviceInfo, timeoutMs?: number) {
|
|
1073
|
+
const protocolInfo = await requestProtocolV2ProtocolInfo({
|
|
1074
|
+
commands: this.commands,
|
|
1075
|
+
timeoutMs,
|
|
1076
|
+
});
|
|
1168
1077
|
const runtimeMode = getProtocolV2RuntimeMode(protocolInfo);
|
|
1169
|
-
const
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
if (
|
|
1174
|
-
runtimeMode === 'romloader' &&
|
|
1175
|
-
protocolV2DeviceType !== EDeviceType.Pro2 &&
|
|
1176
|
-
protocolV2DeviceType !== EDeviceType.Neo
|
|
1177
|
-
) {
|
|
1078
|
+
const protocolV2DeviceType = resolveProtocolV2DeviceIdentity(
|
|
1079
|
+
deviceInfo.hw?.Device_type
|
|
1080
|
+
).deviceType;
|
|
1081
|
+
if (runtimeMode === 'romloader' && protocolV2DeviceType !== EDeviceType.Pro2) {
|
|
1178
1082
|
throw ERRORS.TypedError(
|
|
1179
1083
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
1180
|
-
'Protocol V2 romloader mode is only supported for Pro2
|
|
1084
|
+
'Protocol V2 romloader mode is only supported for Pro2.'
|
|
1181
1085
|
);
|
|
1182
1086
|
}
|
|
1183
1087
|
const deviceStatusSupported = supportsProtocolV2Message(
|
|
@@ -1248,9 +1152,6 @@ export class Device extends EventEmitter {
|
|
|
1248
1152
|
this.deviceAcquired = false;
|
|
1249
1153
|
if (!this.isProtocolV2()) return;
|
|
1250
1154
|
this.protocolV2StateNeedsReload = true;
|
|
1251
|
-
this.protocolV2RuntimeContext = undefined;
|
|
1252
|
-
this.protocolV2RuntimeContextPromise = undefined;
|
|
1253
|
-
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1254
1155
|
this.clearPreInitialized();
|
|
1255
1156
|
}
|
|
1256
1157
|
|
|
@@ -1259,14 +1160,9 @@ export class Device extends EventEmitter {
|
|
|
1259
1160
|
if (deviceId) {
|
|
1260
1161
|
deviceWalletSessionStore.deleteDevice(deviceId);
|
|
1261
1162
|
}
|
|
1262
|
-
if (this.isProtocolV2()) {
|
|
1263
|
-
|
|
1264
|
-
deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
|
|
1265
|
-
}
|
|
1163
|
+
if (this.isProtocolV2() && this.originalDescriptor.path !== deviceId) {
|
|
1164
|
+
deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
|
|
1266
1165
|
this.protocolV2StateNeedsReload = true;
|
|
1267
|
-
this.protocolV2RuntimeContext = undefined;
|
|
1268
|
-
this.protocolV2RuntimeContextPromise = undefined;
|
|
1269
|
-
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1270
1166
|
}
|
|
1271
1167
|
|
|
1272
1168
|
this.passphraseState = undefined;
|
|
@@ -1279,9 +1175,6 @@ export class Device extends EventEmitter {
|
|
|
1279
1175
|
if (!this.isProtocolV2()) return;
|
|
1280
1176
|
|
|
1281
1177
|
this.protocolV2StateNeedsReload = true;
|
|
1282
|
-
this.protocolV2RuntimeContext = undefined;
|
|
1283
|
-
this.protocolV2RuntimeContextPromise = undefined;
|
|
1284
|
-
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1285
1178
|
this.clearPreInitialized();
|
|
1286
1179
|
let loaderMode: 'bootloader' | 'romloader' | undefined;
|
|
1287
1180
|
if (rebootType === DeviceRebootType.Bootloader) {
|
|
@@ -1388,17 +1281,11 @@ export class Device extends EventEmitter {
|
|
|
1388
1281
|
}
|
|
1389
1282
|
};
|
|
1390
1283
|
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
await this.release();
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
if (options.forceProtocolDetection || !this.isUsedHere() || this.commands.disposed) {
|
|
1284
|
+
if (!this.isUsedHere() || this.commands.disposed) {
|
|
1285
|
+
const env = DataManager.getSettings('env');
|
|
1397
1286
|
if (env !== 'react-native') {
|
|
1398
1287
|
try {
|
|
1399
|
-
await this.acquire(options.connectProtocol
|
|
1400
|
-
forceProtocolDetection: options.forceProtocolDetection,
|
|
1401
|
-
});
|
|
1288
|
+
await this.acquire(options.connectProtocol);
|
|
1402
1289
|
} catch (error) {
|
|
1403
1290
|
clearRunPromise();
|
|
1404
1291
|
runPromise.reject(error);
|
|
@@ -1576,8 +1463,7 @@ export class Device extends EventEmitter {
|
|
|
1576
1463
|
if (!this.state) return undefined;
|
|
1577
1464
|
return (
|
|
1578
1465
|
this.isProtocolV2() &&
|
|
1579
|
-
|
|
1580
|
-
this.getCurrentDeviceType() === EDeviceType.Neo) &&
|
|
1466
|
+
this.getCurrentDeviceType() === EDeviceType.Pro2 &&
|
|
1581
1467
|
this.state.status.mode === 'romloader'
|
|
1582
1468
|
);
|
|
1583
1469
|
}
|
|
@@ -1623,8 +1509,7 @@ export class Device extends EventEmitter {
|
|
|
1623
1509
|
const isModeT =
|
|
1624
1510
|
deviceType === EDeviceType.Touch ||
|
|
1625
1511
|
deviceType === EDeviceType.Pro ||
|
|
1626
|
-
deviceType === EDeviceType.Pro2
|
|
1627
|
-
deviceType === EDeviceType.Neo;
|
|
1512
|
+
deviceType === EDeviceType.Pro2;
|
|
1628
1513
|
const unlocked = this.state?.status.unlocked;
|
|
1629
1514
|
const preCheckTouch = isModeT && unlocked === false;
|
|
1630
1515
|
const passphraseProtection = this.getCurrentPassphraseProtection();
|
|
@@ -1642,85 +1527,6 @@ export class Device extends EventEmitter {
|
|
|
1642
1527
|
return res.message;
|
|
1643
1528
|
}
|
|
1644
1529
|
|
|
1645
|
-
beginProtocolV2UiInteraction() {
|
|
1646
|
-
if (!this.isProtocolV2()) return;
|
|
1647
|
-
this.protocolV2UiInteraction = {
|
|
1648
|
-
interactionId: `${this.instanceId}:${Date.now()}:${++this.protocolV2UiInteractionCounter}`,
|
|
1649
|
-
phaseCounter: 0,
|
|
1650
|
-
sequence: 0,
|
|
1651
|
-
opened: false,
|
|
1652
|
-
};
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
createProtocolV2UiPhaseMetadata(
|
|
1656
|
-
phase: HardwareUiInteractionMeta['phase'],
|
|
1657
|
-
transition: HardwareUiInteractionMeta['transition'],
|
|
1658
|
-
options?: {
|
|
1659
|
-
phaseId?: string;
|
|
1660
|
-
outcome?: HardwareUiInteractionMeta['outcome'];
|
|
1661
|
-
}
|
|
1662
|
-
): HardwareUiInteractionMeta | undefined {
|
|
1663
|
-
if (!this.isProtocolV2()) return undefined;
|
|
1664
|
-
if (!this.protocolV2UiInteraction) this.beginProtocolV2UiInteraction();
|
|
1665
|
-
|
|
1666
|
-
const interaction = this.protocolV2UiInteraction;
|
|
1667
|
-
if (!interaction) return undefined;
|
|
1668
|
-
const phaseId =
|
|
1669
|
-
options?.phaseId ?? `${interaction.interactionId}:phase-${++interaction.phaseCounter}`;
|
|
1670
|
-
interaction.opened = true;
|
|
1671
|
-
interaction.sequence += 1;
|
|
1672
|
-
|
|
1673
|
-
return {
|
|
1674
|
-
interactionId: interaction.interactionId,
|
|
1675
|
-
phaseId,
|
|
1676
|
-
sequence: interaction.sequence,
|
|
1677
|
-
phase,
|
|
1678
|
-
transition,
|
|
1679
|
-
...(options?.outcome ? { outcome: options.outcome } : {}),
|
|
1680
|
-
protocol: 'V2',
|
|
1681
|
-
};
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
completeProtocolV2UiPhase(
|
|
1685
|
-
phase: HardwareUiInteractionMeta,
|
|
1686
|
-
outcome: HardwareUiInteractionMeta['outcome'] = 'succeeded'
|
|
1687
|
-
) {
|
|
1688
|
-
return this.createProtocolV2UiPhaseMetadata(phase.phase, 'complete', {
|
|
1689
|
-
phaseId: phase.phaseId,
|
|
1690
|
-
outcome,
|
|
1691
|
-
});
|
|
1692
|
-
}
|
|
1693
|
-
|
|
1694
|
-
finishProtocolV2UiInteraction(
|
|
1695
|
-
outcome?: HardwareUiInteractionMeta['outcome'],
|
|
1696
|
-
options?: { ensureMetadata?: boolean }
|
|
1697
|
-
) {
|
|
1698
|
-
const interaction = this.protocolV2UiInteraction;
|
|
1699
|
-
if (!interaction || (!interaction.opened && !options?.ensureMetadata)) {
|
|
1700
|
-
this.protocolV2UiInteraction = undefined;
|
|
1701
|
-
return undefined;
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
const phaseId = `${interaction.interactionId}:phase-${Math.max(interaction.phaseCounter, 1)}`;
|
|
1705
|
-
interaction.opened = true;
|
|
1706
|
-
interaction.sequence += 1;
|
|
1707
|
-
const metadata: HardwareUiInteractionMeta = {
|
|
1708
|
-
interactionId: interaction.interactionId,
|
|
1709
|
-
phaseId,
|
|
1710
|
-
sequence: interaction.sequence,
|
|
1711
|
-
phase: 'processing',
|
|
1712
|
-
transition: 'finish',
|
|
1713
|
-
outcome: outcome ?? 'succeeded',
|
|
1714
|
-
protocol: 'V2',
|
|
1715
|
-
};
|
|
1716
|
-
this.protocolV2UiInteraction = undefined;
|
|
1717
|
-
return metadata;
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
hasOpenProtocolV2UiInteraction() {
|
|
1721
|
-
return this.protocolV2UiInteraction?.opened === true;
|
|
1722
|
-
}
|
|
1723
|
-
|
|
1724
1530
|
supportUnlockVersionRange(): DeviceFirmwareRange {
|
|
1725
1531
|
// This range applies to Protocol V1 Pro devices; Pro2 has a dedicated unlock flow.
|
|
1726
1532
|
return {
|
|
@@ -1730,33 +1536,10 @@ export class Device extends EventEmitter {
|
|
|
1730
1536
|
};
|
|
1731
1537
|
}
|
|
1732
1538
|
|
|
1733
|
-
async unlockDevice(
|
|
1734
|
-
pinType?: DeviceSessionPinType,
|
|
1735
|
-
options?: ProtocolV2UiEventMetadata & { emitUiEvent?: boolean }
|
|
1736
|
-
) {
|
|
1539
|
+
async unlockDevice(pinType: DeviceSessionPinType = DeviceSessionPinType.Main) {
|
|
1737
1540
|
if (this.isProtocolV2()) {
|
|
1738
|
-
const requestedPinType = pinType ?? DeviceSessionPinType.Main;
|
|
1739
|
-
const interaction =
|
|
1740
|
-
options?.interaction ??
|
|
1741
|
-
(options?.emitUiEvent === false
|
|
1742
|
-
? undefined
|
|
1743
|
-
: this.createProtocolV2UiPhaseMetadata('pin', 'start'));
|
|
1744
|
-
if (options?.emitUiEvent !== false) {
|
|
1745
|
-
this.emit(DEVICE.PIN_ON_DEVICE, this, requestedPinType, {
|
|
1746
|
-
source: options?.source ?? 'unlock-coordinator',
|
|
1747
|
-
reason: options?.reason ?? 'device-unlock',
|
|
1748
|
-
deviceOnly: options?.deviceOnly ?? true,
|
|
1749
|
-
completion: options?.completion,
|
|
1750
|
-
method: options?.method,
|
|
1751
|
-
page: options?.page,
|
|
1752
|
-
operation: options?.operation,
|
|
1753
|
-
interaction: options?.interaction ?? interaction,
|
|
1754
|
-
});
|
|
1755
|
-
}
|
|
1756
1541
|
try {
|
|
1757
|
-
await this.commands.typedCall('DeviceSessionAskPin', 'Success', {
|
|
1758
|
-
type: requestedPinType,
|
|
1759
|
-
});
|
|
1542
|
+
await this.commands.typedCall('DeviceSessionAskPin', 'Success', { type: pinType });
|
|
1760
1543
|
} catch (error) {
|
|
1761
1544
|
const errorText =
|
|
1762
1545
|
error instanceof Error
|
|
@@ -1768,11 +1551,6 @@ export class Device extends EventEmitter {
|
|
|
1768
1551
|
throw error;
|
|
1769
1552
|
}
|
|
1770
1553
|
|
|
1771
|
-
const completion = interaction ? this.completeProtocolV2UiPhase(interaction) : undefined;
|
|
1772
|
-
if (completion) {
|
|
1773
|
-
this.emit(DEVICE.PIN_ON_DEVICE_COMPLETE, this, completion);
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
1554
|
const status = await requestProtocolV2DeviceStatus({ commands: this.commands });
|
|
1777
1555
|
return this.updateProtocolV2Status(status);
|
|
1778
1556
|
}
|
|
@@ -1834,8 +1612,7 @@ export class Device extends EventEmitter {
|
|
|
1834
1612
|
async checkPassphraseStateSafety(
|
|
1835
1613
|
passphraseState?: string,
|
|
1836
1614
|
useEmptyPassphrase?: boolean,
|
|
1837
|
-
skipPassphraseCheck?: boolean
|
|
1838
|
-
deriveCardano?: boolean
|
|
1615
|
+
skipPassphraseCheck?: boolean
|
|
1839
1616
|
) {
|
|
1840
1617
|
if (this.isUnacquired()) return false;
|
|
1841
1618
|
|
|
@@ -1844,8 +1621,6 @@ export class Device extends EventEmitter {
|
|
|
1844
1621
|
await getPassphraseStateWithRefreshDeviceInfo(this, {
|
|
1845
1622
|
expectPassphraseState: expectedPassphraseState,
|
|
1846
1623
|
onlyMainPin: useEmptyPassphrase,
|
|
1847
|
-
deriveCardano,
|
|
1848
|
-
rejectAttachPinForMainWallet: useEmptyPassphrase === true,
|
|
1849
1624
|
});
|
|
1850
1625
|
|
|
1851
1626
|
// Main wallet and unlock Attach Pin, throw safe error
|
|
@@ -54,19 +54,9 @@ const DEVICE_SESSION_CALLS = new Set([
|
|
|
54
54
|
'DeviceSessionAskPin',
|
|
55
55
|
'DeviceSessionAskPassphrase',
|
|
56
56
|
]);
|
|
57
|
-
const DEVICE_CONTROL_CALLS = new Set([
|
|
58
|
-
'DeviceReboot',
|
|
59
|
-
'DeviceSettingsGet',
|
|
60
|
-
'DeviceSettingsSet',
|
|
61
|
-
'DeviceSettingsPageShow',
|
|
62
|
-
'DeviceCertificateWrite',
|
|
63
|
-
'DeviceCertificateRead',
|
|
64
|
-
'DeviceCertificateSign',
|
|
65
|
-
'DeviceMiscUsbMscControl',
|
|
66
|
-
]);
|
|
67
57
|
|
|
68
|
-
//
|
|
69
|
-
//
|
|
58
|
+
// Protocol V2 subcodes are domain-scoped, so cross-domain cancellation fallback
|
|
59
|
+
// must use explicit firmware cancellation messages instead of a global number map.
|
|
70
60
|
const isProtocolV2ActionCancelledMessage = (message: string) =>
|
|
71
61
|
/^(?:cancel(?:led|ed)(?: on device)?|confirm dismissed|user cancel(?:led|ed)(?:\s+.*)?)$/i.test(
|
|
72
62
|
message
|
|
@@ -445,13 +435,7 @@ export class DeviceCommands {
|
|
|
445
435
|
if (!shouldReduceDebugForCall(callType)) {
|
|
446
436
|
Log.debug('_filterCommonTypes: ', {
|
|
447
437
|
request: callType,
|
|
448
|
-
response:
|
|
449
|
-
callType === 'DeviceFirmwareUpdateStatusGet'
|
|
450
|
-
? {
|
|
451
|
-
type: res.type,
|
|
452
|
-
message: getSafeTransportLogPayload(res.message, res.type),
|
|
453
|
-
}
|
|
454
|
-
: res.type,
|
|
438
|
+
response: res.type,
|
|
455
439
|
});
|
|
456
440
|
}
|
|
457
441
|
} catch (error) {
|
|
@@ -509,10 +493,6 @@ export class DeviceCommands {
|
|
|
509
493
|
const normalizedMessage = message?.trim() ?? '';
|
|
510
494
|
const isProtocolV2ActionCancelledFailure =
|
|
511
495
|
this.device.isProtocolV2() && isProtocolV2ActionCancelledMessage(normalizedMessage);
|
|
512
|
-
const isProtocolV2DeviceBusyFailure =
|
|
513
|
-
this.device.isProtocolV2() &&
|
|
514
|
-
DEVICE_CONTROL_CALLS.has(callType) &&
|
|
515
|
-
subcode === DeviceErrorCode.DeviceError_Busy;
|
|
516
496
|
const isLegacyProtocolV2LockedFailure =
|
|
517
497
|
this.device.isProtocolV2() && /^device (?:is )?locked$/i.test(normalizedMessage);
|
|
518
498
|
if (
|
|
@@ -570,15 +550,8 @@ export class DeviceCommands {
|
|
|
570
550
|
subcode,
|
|
571
551
|
firmwareMessage: message,
|
|
572
552
|
});
|
|
573
|
-
} else if (isProtocolV2DeviceBusyFailure) {
|
|
574
|
-
error = ERRORS.TypedError(HardwareErrorCode.DeviceBusy, message, {
|
|
575
|
-
failureCode: code,
|
|
576
|
-
subcode,
|
|
577
|
-
firmwareMessage: message,
|
|
578
|
-
});
|
|
579
553
|
} else if (
|
|
580
|
-
|
|
581
|
-
subcode === DeviceErrorCode.DeviceError_ActionCancelled) ||
|
|
554
|
+
subcode === DeviceErrorCode.DeviceError_ActionCancelled ||
|
|
582
555
|
isProtocolV2ActionCancelledFailure
|
|
583
556
|
) {
|
|
584
557
|
error = ERRORS.TypedError(HardwareErrorCode.ActionCancelled, message, {
|