store mnemonic words in python files instead of txt, this avoids packaging issues
This commit is contained in:
parent
94b920ab2a
commit
eedc9bf9ed
13 changed files with 9843 additions and 9873 deletions
3
setup.py
3
setup.py
|
@ -1,5 +1,3 @@
|
|||
import os
|
||||
import re
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
import torba
|
||||
|
@ -26,7 +24,6 @@ setup(
|
|||
'Topic :: Utilities',
|
||||
),
|
||||
packages=find_packages(exclude=('tests',)),
|
||||
include_package_data=True,
|
||||
python_requires='>=3.6',
|
||||
install_requires=(
|
||||
'twisted',
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
# Copyright (C) 2014 Thomas Voegtlin
|
||||
# Copyright (C) 2018 LBRY Inc.
|
||||
|
||||
import os
|
||||
import io
|
||||
import hmac
|
||||
import math
|
||||
import hashlib
|
||||
import importlib
|
||||
import unicodedata
|
||||
import string
|
||||
from binascii import hexlify
|
||||
|
@ -77,28 +76,20 @@ def normalize_text(seed):
|
|||
return seed
|
||||
|
||||
|
||||
def load_words(filename):
|
||||
path = os.path.join(os.path.dirname(__file__), 'words', filename)
|
||||
with io.open(path, 'r', encoding='utf-8') as f:
|
||||
s = f.read().strip()
|
||||
s = unicodedata.normalize('NFKD', s)
|
||||
lines = s.split('\n')
|
||||
words = []
|
||||
for line in lines:
|
||||
line = line.split('#')[0]
|
||||
line = line.strip(' \r')
|
||||
assert ' ' not in line
|
||||
if line:
|
||||
words.append(line)
|
||||
return words
|
||||
def load_words(language_name):
|
||||
language_module = importlib.import_module('torba.words.'+language_name)
|
||||
return list(map(
|
||||
lambda s: unicodedata.normalize('NFKD', s),
|
||||
language_module.words
|
||||
))
|
||||
|
||||
|
||||
FILE_NAMES = {
|
||||
'en': 'english.txt',
|
||||
'es': 'spanish.txt',
|
||||
'ja': 'japanese.txt',
|
||||
'pt': 'portuguese.txt',
|
||||
'zh': 'chinese_simplified.txt'
|
||||
LANGUAGE_NAMES = {
|
||||
'en': 'english',
|
||||
'es': 'spanish',
|
||||
'ja': 'japanese',
|
||||
'pt': 'portuguese',
|
||||
'zh': 'chinese_simplified'
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,8 +98,8 @@ class Mnemonic:
|
|||
# Mnemonic phrase uses a hash based checksum, instead of a words-dependent checksum
|
||||
|
||||
def __init__(self, lang='en'):
|
||||
filename = FILE_NAMES.get(lang, 'english.txt')
|
||||
self.words = load_words(filename)
|
||||
language_name = LANGUAGE_NAMES.get(lang, 'english')
|
||||
self.words = load_words(language_name)
|
||||
|
||||
@staticmethod
|
||||
def mnemonic_to_seed(mnemonic, passphrase=u''):
|
||||
|
|
0
torba/words/__init__.py
Normal file
0
torba/words/__init__.py
Normal file
2050
torba/words/chinese_simplified.py
Normal file
2050
torba/words/chinese_simplified.py
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
2050
torba/words/english.py
Normal file
2050
torba/words/english.py
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
2050
torba/words/japanese.py
Normal file
2050
torba/words/japanese.py
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
1628
torba/words/portuguese.py
Normal file
1628
torba/words/portuguese.py
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
2050
torba/words/spanish.py
Normal file
2050
torba/words/spanish.py
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue