Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_public_key(self) -> PublicKey:
public_key_impl = keys.get_public_key(self.impl, self.curve)
return ECCPublicKey(public_key_impl, self.curve)
def sign_with_k(bytes_msg: bytes,
bytes_private: bytes,
k: int) -> Optional[bytes]:
private_key = int.from_bytes(bytes_private, "big")
order = CURVE.q
Q = CURVE.G * k
bytes_Q_x = encode_public(Q.x, Q.y)
pub_key = keys.get_public_key(private_key, CURVE)
bytes_pub_x = encode_public(pub_key.x, pub_key.y)
hasher = sha256()
hasher.update(bytes_Q_x + bytes_pub_x + bytes_msg)
r = hasher.digest()
r = int.from_bytes(r, "big") % order
s = (k - r * private_key) % order
if r == 0 or s == 0:
return None
return encode_signature(r, s)
def get_pub_key(priv_key: str) -> str:
'''
Returns the public key associated with
the private key. 'x' is used to split
up the x and y coordinates of the public
key
'''
pub_key = keys.get_public_key(int(priv_key, 16), curve.P256)
return '{:x}'.format(pub_key.x) + 'x' + '{:x}'.format(pub_key.y)