mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
old_mnemonic: speed up mn_decode
mn_decode is used by mnemonic.make_seed which now takes around 25% less time
This commit is contained in:
parent
bc4f22503f
commit
6ebbaa60ef
3 changed files with 10 additions and 8 deletions
|
@ -904,7 +904,7 @@ def from_seed(seed, passphrase, is_p2sh=False):
|
|||
xtype = 'p2wsh' if is_p2sh else 'p2wpkh'
|
||||
keystore.add_xprv_from_seed(bip32_seed, xtype, der)
|
||||
else:
|
||||
raise BitcoinException('Unexpected seed type {}'.format(t))
|
||||
raise BitcoinException('Unexpected seed type {}'.format(repr(t)))
|
||||
return keystore
|
||||
|
||||
def from_private_key_list(text):
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
# list of words from http://en.wiktionary.org/wiki/Wiktionary:Frequency_lists/Contemporary_poetry
|
||||
|
||||
words = [
|
||||
words = (
|
||||
"like",
|
||||
"just",
|
||||
"love",
|
||||
|
@ -1653,7 +1653,8 @@ words = [
|
|||
"unseen",
|
||||
"weapon",
|
||||
"weary",
|
||||
]
|
||||
)
|
||||
_words_indexes = {w: i for i, w in enumerate(words)}
|
||||
|
||||
n = len(words)
|
||||
assert n == 1626
|
||||
|
@ -1679,9 +1680,9 @@ def mn_decode( wlist ):
|
|||
out = ''
|
||||
for i in range(len(wlist)//3):
|
||||
word1, word2, word3 = wlist[3*i:3*i+3]
|
||||
w1 = words.index(word1)
|
||||
w2 = (words.index(word2))%n
|
||||
w3 = (words.index(word3))%n
|
||||
w1 = _words_indexes[word1]
|
||||
w2 = (_words_indexes[word2]) % n
|
||||
w3 = (_words_indexes[word3]) % n
|
||||
x = w1 +n*((w2-w1)%n) +n*n*((w3-w2)%n)
|
||||
out += '%08x'%x
|
||||
return out
|
||||
|
|
|
@ -186,5 +186,6 @@ class Test_seeds(ElectrumTestCase):
|
|||
self.assertTrue(is_old_seed("0123456789ABCDEF" * 4))
|
||||
|
||||
def test_seed_type(self):
|
||||
for seed_words, _type in self.mnemonics:
|
||||
self.assertEqual(_type, seed_type(seed_words), msg=seed_words)
|
||||
for idx, (seed_words, _type) in enumerate(self.mnemonics):
|
||||
with self.subTest(msg=f"seed_type_subcase_{idx}", seed_words=seed_words):
|
||||
self.assertEqual(_type, seed_type(seed_words), msg=seed_words)
|
||||
|
|
Loading…
Add table
Reference in a new issue