# Determine the first byte of the compressed public key based on the private key's sign
if private_key_int < 0:
public_key_bytes_compressed = (
b"\x03" + vk.to_string()[:32] if vk.to_string()[-1] % 2 == 0 else b"\x02" + vk.to_string()[:32]
)
else:
public_key_bytes_compressed = (
b"\x02" + vk.to_string()[:32] if vk.to_string()[-1] % 2 == 0 else b"\x03" + vk.to_string()[:32]
)
You code is incorrect. The 0x02, 0x03 prefixes are based only on the value of the public key. Furthermore, a private key does not have a sign, and testing if it is less than 0 is invalid.