Add handling for 12/13-word seeds (MyMonero style)

This commit is contained in:
Michał Sałaban 2018-05-26 17:42:55 +02:00
parent c9b4a5c7cb
commit 83eca24ce0
2 changed files with 14 additions and 2 deletions

View file

@ -85,6 +85,9 @@ class Seed(object):
self.hex = generate_hex()
self.encode_seed()
def is_mymonero(self):
"""Returns True if the seed is MyMonero-style (12/13-word)."""
return len(self.hex) == 32
def endian_swap(self, word):
"""Given any string, swap bits and return the result.
@ -152,12 +155,19 @@ class Seed(object):
def hex_seed(self):
return self.hex
def _hex_seed_keccak(self):
h = keccak_256()
h.update(unhexlify(self.hex))
return h.hexdigest()
def secret_spend_key(self):
return self.sc_reduce(self.hex)
a = self._hex_seed_keccak() if self.is_mymonero() else self.hex
return self.sc_reduce(a)
def secret_view_key(self):
b = self._hex_seed_keccak() if self.is_mymonero() else self.secret_spend_key()
h = keccak_256()
h.update(unhexlify(self.secret_spend_key()))
h.update(unhexlify(b))
return self.sc_reduce(h.hexdigest())
def public_spend_key(self):

View file

@ -66,6 +66,7 @@ class SeedTestCase(unittest.TestCase):
seed = Seed("adjust mugged vaults atlas nasty mews damp toenail suddenly toxic possible "\
"framed succeed fuzzy return demonstrate nucleus album noises peculiar virtual "\
"rowboat inorganic jester fuzzy")
self.assertFalse(seed.is_mymonero())
self.assertTrue(seed.validate_checksum())
self.assertEqual(
seed.secret_spend_key(),
@ -87,6 +88,7 @@ class SeedTestCase(unittest.TestCase):
'54pZ5jHDGmwNnycvZbUoj44vsbAEmKnx9aNgkjHdjtMsBrSeKiY8J4s2raH7EMawA2Fwo9utaRTV7Aw8EcTMNMxhH6cuARW')
seed = Seed("dwelt idols lopped blender haggled rabbits piloted value swagger taunts toolbox upgrade swagger")
self.assertTrue(seed.is_mymonero())
self.assertTrue(seed.validate_checksum())
# the following fails, #21 addresses that
self.assertEqual(