Post
Topic
Board Development & Technical Discussion
Merits 2 from 2 users
Re: Determining the positivity or negativity of a Bitcoin public key
by
odolvlobo
on 14/11/2024, 20:37:00 UTC
⭐ Merited by ABCbits (1) ,vapourminer (1)
Code:
    # 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.