mirror of
https://gitlab.com/pulsechaincom/staking-deposit-cli.git
synced 2025-01-09 12:31:21 +00:00
Adds check that multiple mnemonic languages aren't detected
This commit is contained in:
parent
885826c526
commit
0d3440e7ba
@ -108,6 +108,7 @@ def reconstruct_mnemonic(mnemonic: str, words_path: str) -> Optional[str]:
|
|||||||
languages = determine_mnemonic_language(mnemonic, words_path)
|
languages = determine_mnemonic_language(mnemonic, words_path)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
|
reconstructed_mnemonic = None
|
||||||
for language in languages:
|
for language in languages:
|
||||||
try:
|
try:
|
||||||
word_list = abbreviate_words(_get_word_list(language, words_path))
|
word_list = abbreviate_words(_get_word_list(language, words_path))
|
||||||
@ -122,12 +123,17 @@ def reconstruct_mnemonic(mnemonic: str, words_path: str) -> Optional[str]:
|
|||||||
entropy_bits = entropy.to_bytes(checksum_length * 4, 'big')
|
entropy_bits = entropy.to_bytes(checksum_length * 4, 'big')
|
||||||
full_word_list = _get_word_list(language, words_path)
|
full_word_list = _get_word_list(language, words_path)
|
||||||
if _get_checksum(entropy_bits) == checksum:
|
if _get_checksum(entropy_bits) == checksum:
|
||||||
return ' '.join([_index_to_word(full_word_list, index) for index in word_indices])
|
"""
|
||||||
|
This check guarantees that only one language has a valid mnemonic.
|
||||||
|
It is needed to ensure abbrivated words aren't valid in multiple languages
|
||||||
|
"""
|
||||||
|
assert reconstructed_mnemonic is None
|
||||||
|
reconstructed_mnemonic = ' '.join([_index_to_word(full_word_list, index) for index in word_indices])
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
return None
|
return reconstructed_mnemonic
|
||||||
|
|
||||||
|
|
||||||
def get_mnemonic(*, language: str, words_path: str, entropy: Optional[bytes]=None) -> str:
|
def get_mnemonic(*, language: str, words_path: str, entropy: Optional[bytes]=None) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user