Cache public key in the secret key to speed up `generate_kfrags()`

pull/263/head
Bogdan Opanchuk 2021-03-27 14:10:33 -07:00
parent a08a552708
commit 7d0f2fe3e2
1 changed files with 6 additions and 1 deletions

View File

@ -25,6 +25,11 @@ class SecretKey(Serializable):
def __init__(self, scalar_key: CurveScalar):
self._scalar_key = scalar_key
# Cached public key. Access it via `PublicKey.from_secret_key()` -
# it may be removed later.
# We are assuming here that there will be on average more calls to
# `PublicKey.from_secret_key()` than secret key instantiations.
self._public_key_point = CurvePoint.generator() * self._scalar_key
@classmethod
def random(cls) -> 'SecretKey':
@ -130,7 +135,7 @@ class PublicKey(Serializable):
"""
Creates the public key corresponding to the given secret key.
"""
return cls(CurvePoint.generator() * sk.secret_scalar())
return cls(sk._public_key_point)
@classmethod
def __take__(cls, data: bytes) -> Tuple['PublicKey', bytes]: