import type { TrezorDevice, TrezorDeviceWithState } from '@suite-common/suite-types'; import { type Device } from '@trezor/connect'; import { countBytesInString } from '@trezor/utils'; import { PASSPHRASE_MAX_LENGTH } from './deviceConstants'; type ShouldDeviceBeRememberedParams = { device: TrezorDevice | Device; isAutoEjectEnabled?: boolean; }; export const shouldDeviceBeRemembered = ({ device, isAutoEjectEnabled = false, }: ShouldDeviceBeRememberedParams) => { if (device.mode !== 'normal') return false; if (device.type !== 'acquired') return false; return !isAutoEjectEnabled; }; export const isApprovalFlowSupported = (device: TrezorDevice | undefined) => !device?.unavailableCapabilities?.['evmApproval']; export const isEvmClearSigningSupported = (device: TrezorDevice | undefined) => !device?.unavailableCapabilities?.['evmClearSigning']; export const isTrezorDeviceWithState = ( device: TrezorDevice | undefined, ): device is TrezorDeviceWithState => device !== undefined && device.id !== null && device.state?.staticSessionId !== undefined; export const getPassphraseMaxLength = (device: TrezorDevice | undefined) => device?.features?.max_passphrase_len ?? PASSPHRASE_MAX_LENGTH; export const getIsPassphraseTooLong = (passphrase: string, passphraseMaxLength: number) => countBytesInString(passphrase) > passphraseMaxLength;