1
0

mnemonic: implement Wordlist class

Wordlist subclasses 'tuple' so it can be transparently used.
'in' and '.index()' are fast.
Use Wordlist in bip39_is_checksum_valid, which makes that faster.
This commit is contained in:
SomberNight
2020-02-29 00:20:11 +01:00
parent e1dcdde272
commit a0b096dcb2
5 changed files with 59 additions and 35 deletions

View File

@@ -42,7 +42,7 @@ from .crypto import (pw_decode, pw_encode, sha256, sha256d, PW_HASH_VERSION_LATE
SUPPORTED_PW_HASH_VERSIONS, UnsupportedPasswordHashVersion, hash_160)
from .util import (InvalidPassword, WalletFileException,
BitcoinException, bh2u, bfh, inv_dict, is_hex_str)
from .mnemonic import Mnemonic, load_wordlist, seed_type, is_seed
from .mnemonic import Mnemonic, Wordlist, seed_type, is_seed
from .plugin import run_hook
from .logging import Logger
@@ -811,7 +811,7 @@ def bip39_is_checksum_valid(mnemonic: str) -> Tuple[bool, bool]:
"""
words = [ normalize('NFKD', word) for word in mnemonic.split() ]
words_len = len(words)
wordlist = load_wordlist("english.txt")
wordlist = Wordlist.from_file("english.txt")
n = len(wordlist)
i = 0
words.reverse()