yangbin9317
2022-05-13 15:36:50 +08:00
```
def public_key(private_key: int, compressed=True) -> bytes:
private_key = private_key.to_bytes(32, byteorder='big')
public_key = ecdsa.SigningKey.from_string(
private_key, curve=ecdsa.SECP256k1).get_verifying_key()
public_key = public_key.to_string()
if compressed:
mid = len(public_key) // 2
x = public_key[:mid]
y = public_key[mid:]
prefix = b'\x02' if y[-1] & 1 == 0 else b'\x03'
return prefix + x
else:
return b'\x04' + public_key
```
我这个行吗