Browse Source
old_mnemonic: speed up mn_decode
mn_decode is used by mnemonic.make_seed which now takes around 25% less time
ln-negative-red
SomberNight
5 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
3 changed files with
10 additions and
8 deletions
-
electrum/keystore.py
-
electrum/old_mnemonic.py
-
electrum/tests/test_mnemonic.py
|
@ -904,7 +904,7 @@ def from_seed(seed, passphrase, is_p2sh=False): |
|
|
xtype = 'p2wsh' if is_p2sh else 'p2wpkh' |
|
|
xtype = 'p2wsh' if is_p2sh else 'p2wpkh' |
|
|
keystore.add_xprv_from_seed(bip32_seed, xtype, der) |
|
|
keystore.add_xprv_from_seed(bip32_seed, xtype, der) |
|
|
else: |
|
|
else: |
|
|
raise BitcoinException('Unexpected seed type {}'.format(t)) |
|
|
raise BitcoinException('Unexpected seed type {}'.format(repr(t))) |
|
|
return keystore |
|
|
return keystore |
|
|
|
|
|
|
|
|
def from_private_key_list(text): |
|
|
def from_private_key_list(text): |
|
|
|
@ -26,7 +26,7 @@ |
|
|
|
|
|
|
|
|
# list of words from http://en.wiktionary.org/wiki/Wiktionary:Frequency_lists/Contemporary_poetry |
|
|
# list of words from http://en.wiktionary.org/wiki/Wiktionary:Frequency_lists/Contemporary_poetry |
|
|
|
|
|
|
|
|
words = [ |
|
|
words = ( |
|
|
"like", |
|
|
"like", |
|
|
"just", |
|
|
"just", |
|
|
"love", |
|
|
"love", |
|
@ -1653,7 +1653,8 @@ words = [ |
|
|
"unseen", |
|
|
"unseen", |
|
|
"weapon", |
|
|
"weapon", |
|
|
"weary", |
|
|
"weary", |
|
|
] |
|
|
) |
|
|
|
|
|
_words_indexes = {w: i for i, w in enumerate(words)} |
|
|
|
|
|
|
|
|
n = len(words) |
|
|
n = len(words) |
|
|
assert n == 1626 |
|
|
assert n == 1626 |
|
@ -1679,9 +1680,9 @@ def mn_decode( wlist ): |
|
|
out = '' |
|
|
out = '' |
|
|
for i in range(len(wlist)//3): |
|
|
for i in range(len(wlist)//3): |
|
|
word1, word2, word3 = wlist[3*i:3*i+3] |
|
|
word1, word2, word3 = wlist[3*i:3*i+3] |
|
|
w1 = words.index(word1) |
|
|
w1 = _words_indexes[word1] |
|
|
w2 = (words.index(word2))%n |
|
|
w2 = (_words_indexes[word2]) % n |
|
|
w3 = (words.index(word3))%n |
|
|
w3 = (_words_indexes[word3]) % n |
|
|
x = w1 +n*((w2-w1)%n) +n*n*((w3-w2)%n) |
|
|
x = w1 +n*((w2-w1)%n) +n*n*((w3-w2)%n) |
|
|
out += '%08x'%x |
|
|
out += '%08x'%x |
|
|
return out |
|
|
return out |
|
|
|
@ -186,5 +186,6 @@ class Test_seeds(ElectrumTestCase): |
|
|
self.assertTrue(is_old_seed("0123456789ABCDEF" * 4)) |
|
|
self.assertTrue(is_old_seed("0123456789ABCDEF" * 4)) |
|
|
|
|
|
|
|
|
def test_seed_type(self): |
|
|
def test_seed_type(self): |
|
|
for seed_words, _type in self.mnemonics: |
|
|
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) |
|
|
self.assertEqual(_type, seed_type(seed_words), msg=seed_words) |
|
|