@@ -66,6 +66,7 @@ def b58encode(v: bytes) -> str:
66
66
67
67
class Mnemonic (object ):
68
68
def __init__ (self , language : str ):
69
+ self .language = language
69
70
self .radix = 2048
70
71
with open (
71
72
"%s/%s.txt" % (self ._get_directory (), language ), "r" , encoding = "utf-8"
@@ -81,14 +82,6 @@ def __init__(self, language: str):
81
82
def _get_directory () -> str :
82
83
return os .path .join (os .path .dirname (__file__ ), "wordlist" )
83
84
84
- @classmethod
85
- def list_languages (cls ) -> List [str ]:
86
- return [
87
- f .split ("." )[0 ]
88
- for f in os .listdir (cls ._get_directory ())
89
- if f .endswith (".txt" )
90
- ]
91
-
92
85
@staticmethod
93
86
def normalize_string (txt : AnyStr ) -> str :
94
87
if isinstance (txt , bytes ):
@@ -100,19 +93,6 @@ def normalize_string(txt: AnyStr) -> str:
100
93
101
94
return unicodedata .normalize ("NFKD" , utxt )
102
95
103
- @classmethod
104
- def detect_language (cls , code : str ) -> str :
105
- code = cls .normalize_string (code )
106
- first = code .split (" " )[0 ]
107
- languages = cls .list_languages ()
108
-
109
- for lang in languages :
110
- mnemo = cls (lang )
111
- if first in mnemo .wordlist :
112
- return lang
113
-
114
- raise ConfigurationError ("Language not detected" )
115
-
116
96
def generate (self , strength : int = 128 ) -> str :
117
97
if strength not in [128 , 160 , 192 , 224 , 256 ]:
118
98
raise ValueError (
@@ -135,7 +115,7 @@ def to_entropy(self, words: Union[List[str], str]) -> bytearray:
135
115
concatLenBits = len (words ) * 11
136
116
concatBits = [False ] * concatLenBits
137
117
wordindex = 0
138
- if self .detect_language ( " " . join ( words )) == "english" :
118
+ if self .language == "english" :
139
119
use_binary_search = True
140
120
else :
141
121
use_binary_search = False
@@ -189,7 +169,7 @@ def to_mnemonic(self, data: bytes) -> str:
189
169
idx = int (b [i * 11 : (i + 1 ) * 11 ], 2 )
190
170
result .append (self .wordlist [idx ])
191
171
if (
192
- self .detect_language ( " " . join ( result )) == "japanese"
172
+ self .language == "japanese"
193
173
): # Japanese must be joined by ideographic space.
194
174
result_phrase = u"\u3000 " .join (result )
195
175
else :
0 commit comments