Browse Source

add spanish wordlist and remove accents

283
ThomasV 10 years ago
parent
commit
93d073457c
  1. 2
      lib/bitcoin.py
  2. 32
      lib/mnemonic.py
  3. 8
      lib/wallet.py
  4. 2048
      lib/wordlist/spanish.txt

2
lib/bitcoin.py

@ -149,6 +149,8 @@ hash_decode = lambda x: x.decode('hex')[::-1]
hmac_sha_512 = lambda x,y: hmac.new(x, y, hashlib.sha512).digest()
def is_new_seed(x, prefix=version.SEED_BIP44):
import mnemonic
x = mnemonic.Mnemonic.prepare_seed(x)
s = hmac_sha_512("Seed version", x.encode('utf8')).encode('hex')
return s.startswith(prefix)

32
lib/mnemonic.py

@ -29,20 +29,25 @@ from util import print_error
from bitcoin import is_old_seed, is_new_seed
import version
filenames = {
'en':'english.txt',
'es':'spanish.txt',
'ja':'japanese.txt',
'pt':'portuguese.txt',
}
def remove_accents(input_str):
nkfd_form = unicodedata.normalize('NFKD', unicode(input_str))
return u''.join([c for c in nkfd_form if not unicodedata.combining(c)])
class Mnemonic(object):
# Seed derivation follows BIP39
# Mnemonic phrase uses a hash based checksum, instead of a wordlist-dependent checksum
def __init__(self, lang=None):
if lang is None:
filename = 'english.txt'
elif lang[0:2] == 'pt':
filename = 'portuguese.txt'
elif lang[0:2] == 'ja':
filename = 'japanese.txt'
else:
filename = 'english.txt'
def __init__(self, lang='en'):
filename = filenames.get(lang[0:2], 'english.txt')
path = os.path.join(os.path.dirname(__file__), 'wordlist', filename)
s = open(path,'r').read().strip()
s = unicodedata.normalize('NFKD', s.decode('utf8'))
@ -63,7 +68,10 @@ class Mnemonic(object):
@classmethod
def prepare_seed(self, seed):
return unicodedata.normalize('NFKD', unicode(seed.strip()))
# remove accents to tolerate typos
seed = unicode(remove_accents(seed.strip()))
seed = unicodedata.normalize('NFKD', seed)
return seed
def mnemonic_encode(self, i):
n = len(self.wordlist)
@ -105,7 +113,7 @@ class Mnemonic(object):
assert i == self.mnemonic_decode(seed)
if is_old_seed(seed):
continue
if is_new_seed(seed, prefix):
if is_new_seed(self.prepare_seed(seed), prefix):
break
print_error('%d words'%len(seed.split()))
return seed

8
lib/wallet.py

@ -1080,7 +1080,7 @@ class Deterministic_Wallet(Abstract_Wallet):
if self.seed:
raise Exception("a seed exists")
self.seed_version, self.seed = self.prepare_seed(seed)
self.seed_version, self.seed = self.format_seed(seed)
if password:
self.seed = pw_encode( self.seed, password)
self.use_encryption = True
@ -1301,8 +1301,8 @@ class BIP32_Wallet(Deterministic_Wallet):
lang = self.storage.config.get('language')
return Mnemonic(lang).make_seed()
def prepare_seed(self, seed):
return NEW_SEED_VERSION, Mnemonic.prepare_seed(seed)
def format_seed(self, seed):
return NEW_SEED_VERSION, ' '.join(seed.split())
class BIP32_Simple_Wallet(BIP32_Wallet):
@ -1515,7 +1515,7 @@ class OldWallet(Deterministic_Wallet):
seed = random_seed(128)
return ' '.join(old_mnemonic.mn_encode(seed))
def prepare_seed(self, seed):
def format_seed(self, seed):
import old_mnemonic
# see if seed was entered as hex
seed = seed.strip()

2048
lib/wordlist/spanish.txt

File diff suppressed because it is too large
Loading…
Cancel
Save