Caching of ed25519 values for public keys in seed

Based on:

https://github.com/emesik/monero-python/issues/42#issuecomment-458780087
This commit is contained in:
moneroexamples 2019-01-31 09:28:44 +08:00
parent c999f68cf1
commit f59e6c402b
1 changed files with 11 additions and 2 deletions

View File

@ -61,6 +61,9 @@ class Seed(object):
self.word_list = wordlists.get_wordlist(wordlist)
self._ed_pub_spend_key = None
self._ed_pub_view_key = None
if phrase_or_hex:
seed_split = phrase_or_hex.split(" ")
if len(seed_split) >= 24:
@ -137,10 +140,16 @@ class Seed(object):
return self.sc_reduce(h.digest())
def public_spend_key(self):
return ed25519.public_from_secret_hex(self.secret_spend_key())
if self._ed_pub_spend_key:
return self._ed_pub_spend_key
self._ed_pub_spend_key = ed25519.public_from_secret_hex(self.secret_spend_key())
return self._ed_pub_spend_key
def public_view_key(self):
return ed25519.public_from_secret_hex(self.secret_view_key())
if self._ed_pub_view_key:
return self._ed_pub_view_key
self._ed_pub_view_key = ed25519.public_from_secret_hex(self.secret_view_key())
return self._ed_pub_view_key
def public_address(self, net='mainnet'):
"""Returns the master :class:`Address <monero.address.Address>` represented by the seed.