entropy_to_mnemonic fix and tests
This commit is contained in:
parent
0e85e91a1a
commit
b76d4122d6
@ -83,7 +83,9 @@ def entropy_to_mnemonic(entropy, language='english', word_list_dir=None, word_li
|
||||
i = int.from_bytes(entropy, byteorder="big")
|
||||
# append checksum
|
||||
i = (i << len(entropy) * 8 // 32) | sha256(entropy)[0]
|
||||
return " ".join([word_list[i.__rshift__(((d - 1) * 11)) & 2047] for d in range(int(i.bit_length() // 11), 0, -1)])
|
||||
|
||||
return " ".join([word_list[i.__rshift__(((d - 1) * 11)) & 2047]
|
||||
for d in range(int((len(entropy) * 8 + 8) // 11), 0, -1)])
|
||||
|
||||
|
||||
def mnemonic_to_entropy(mnemonic, language='english', word_list_dir=None,
|
||||
|
||||
@ -33,3 +33,7 @@ class BlockDeserializeTests(unittest.TestCase):
|
||||
self.assertEqual(private_from_xprivate_key(xpriv), "L2VnL3zxnNE1jRSemyP7U6PvWuNLvuV5iMJdc2RJGALjZ6HYik7y")
|
||||
self.assertEqual(public_from_xpublic_key(xpub),
|
||||
private_to_public_key("L2VnL3zxnNE1jRSemyP7U6PvWuNLvuV5iMJdc2RJGALjZ6HYik7y"))
|
||||
for i in range(100):
|
||||
e = generate_entropy()
|
||||
m = entropy_to_mnemonic(e)
|
||||
self.assertEqual(e, mnemonic_to_entropy(m))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user