entropy_to_mnemonic fix and tests

This commit is contained in:
4tochka 2018-07-13 00:21:50 +04:00
parent 0e85e91a1a
commit b76d4122d6
3 changed files with 8 additions and 2 deletions

View File

@ -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,

View File

@ -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))

View File

@ -5,7 +5,7 @@ from setuptools import setup, find_packages
setup(name='pybtc',
version='2.0.2',
version='2.0.3',
description='Python Bitcoin library',
keywords='bitcoin',
url='https://github.com/bitaps-com/pybtc',