From ef58d031eab877c3a98ea1ee902037afd3d0946f Mon Sep 17 00:00:00 2001 From: tadeubas Date: Mon, 12 Aug 2024 20:09:35 -0300 Subject: [PATCH] optimizing mnemonic_to_bytes --- src/krux/bip39.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/krux/bip39.py b/src/krux/bip39.py index c11c4bf5..2786aafe 100644 --- a/src/krux/bip39.py +++ b/src/krux/bip39.py @@ -14,14 +14,15 @@ def mnemonic_to_bytes( raise ValueError("Invalid recovery phrase") accumulator = 0 - for word in words: - try: - if wordlist is WORDLIST: + try: + if wordlist is WORDLIST: + for word in words: accumulator = (accumulator << 11) + WORDINDEX[word] - else: + else: + for word in words: accumulator = (accumulator << 11) + wordlist.index(word) - except Exception: - raise ValueError("Word '%s' is not in the dictionary" % word) + except Exception: + raise ValueError("Word '%s' is not in the dictionary" % word) entropy_length_bits = len(words) * 11 // 33 * 32 checksum_length_bits = len(words) * 11 // 33