From f59e6c402b8ce630edd51bb5b220ca5921cb6c2a Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Thu, 31 Jan 2019 09:28:44 +0800 Subject: [PATCH] Caching of ed25519 values for public keys in seed Based on: https://github.com/emesik/monero-python/issues/42#issuecomment-458780087 --- monero/seed.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/monero/seed.py b/monero/seed.py index 21f31e9..07dd924 100644 --- a/monero/seed.py +++ b/monero/seed.py @@ -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 ` represented by the seed.