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")
|
i = int.from_bytes(entropy, byteorder="big")
|
||||||
# append checksum
|
# append checksum
|
||||||
i = (i << len(entropy) * 8 // 32) | sha256(entropy)[0]
|
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,
|
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(private_from_xprivate_key(xpriv), "L2VnL3zxnNE1jRSemyP7U6PvWuNLvuV5iMJdc2RJGALjZ6HYik7y")
|
||||||
self.assertEqual(public_from_xpublic_key(xpub),
|
self.assertEqual(public_from_xpublic_key(xpub),
|
||||||
private_to_public_key("L2VnL3zxnNE1jRSemyP7U6PvWuNLvuV5iMJdc2RJGALjZ6HYik7y"))
|
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))
|
||||||
|
|||||||
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
|
|
||||||
setup(name='pybtc',
|
setup(name='pybtc',
|
||||||
version='2.0.2',
|
version='2.0.3',
|
||||||
description='Python Bitcoin library',
|
description='Python Bitcoin library',
|
||||||
keywords='bitcoin',
|
keywords='bitcoin',
|
||||||
url='https://github.com/bitaps-com/pybtc',
|
url='https://github.com/bitaps-com/pybtc',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user