from typing import Optional


def hex_to_bytearray(hex_str: str) -> Optional[bytearray]:
    """Convert hexstring (starting with 0x) to bytearray."""

    return bytearray.fromhex(hex_str[2:]) if hex_str is not None else None