Browse Source

seed_v9: strip whitespaces before hashing

master
ThomasV 11 years ago
parent
commit
43513adb5c
  1. 15
      lib/mnemonic.py
  2. 4
      lib/version.py
  3. 2
      lib/wallet.py

15
lib/mnemonic.py

@ -21,6 +21,7 @@ import hmac
import math import math
import hashlib import hashlib
import unicodedata import unicodedata
import string
import ecdsa import ecdsa
import pbkdf2 import pbkdf2
@ -37,13 +38,10 @@ filenames = {
'pt':'portuguese.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): class Mnemonic(object):
# Seed derivation follows BIP39 # Seed derivation no longer follows BIP39
# Mnemonic phrase uses a hash based checksum, instead of a wordlist-dependent checksum # Mnemonic phrase uses a hash based checksum, instead of a wordlist-dependent checksum
def __init__(self, lang='en'): def __init__(self, lang='en'):
@ -68,9 +66,10 @@ class Mnemonic(object):
@classmethod @classmethod
def prepare_seed(self, seed): def prepare_seed(self, seed):
# remove accents to tolerate typos # normalize
seed = unicode(remove_accents(seed.strip())) seed = unicodedata.normalize('NFKD', unicode(seed))
seed = unicodedata.normalize('NFKD', seed) # remove accents and whitespaces
seed = u''.join([c for c in seed if not unicodedata.combining(c) and not c in string.whitespace])
return seed return seed
def mnemonic_encode(self, i): def mnemonic_encode(self, i):
@ -113,7 +112,7 @@ class Mnemonic(object):
assert i == self.mnemonic_decode(seed) assert i == self.mnemonic_decode(seed)
if is_old_seed(seed): if is_old_seed(seed):
continue continue
if is_new_seed(self.prepare_seed(seed), prefix): if is_new_seed(seed, prefix):
break break
print_error('%d words'%len(seed.split())) print_error('%d words'%len(seed.split()))
return seed return seed

4
lib/version.py

@ -1,7 +1,7 @@
ELECTRUM_VERSION = "2.0" # version of the client package ELECTRUM_VERSION = "2.0" # version of the client package
PROTOCOL_VERSION = '0.9' # protocol version requested PROTOCOL_VERSION = '0.9' # protocol version requested
NEW_SEED_VERSION = 8 # bip32 wallets NEW_SEED_VERSION = 9 # electrum versions >= 2.0
OLD_SEED_VERSION = 4 # old electrum deterministic generation OLD_SEED_VERSION = 4 # electrum versions < 2.0
# The hash of the mnemonic seed must begin with this # The hash of the mnemonic seed must begin with this

2
lib/wallet.py

@ -1614,7 +1614,7 @@ class Wallet(object):
if seed_version not in [OLD_SEED_VERSION, NEW_SEED_VERSION]: if seed_version not in [OLD_SEED_VERSION, NEW_SEED_VERSION]:
msg = "This wallet seed is not supported anymore." msg = "This wallet seed is not supported anymore."
if seed_version in [5, 7]: if seed_version in [5, 7, 8]:
msg += "\nTo open this wallet, try 'git checkout seed_v%d'"%seed_version msg += "\nTo open this wallet, try 'git checkout seed_v%d'"%seed_version
print msg print msg
sys.exit(1) sys.exit(1)

Loading…
Cancel
Save