tseed_v9: strip whitespaces before hashing - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 43513adb5c6a68235ef426e9e6aa608ae334d8c7 DIR parent f3e2e7b50164303dd2b8c1475cbd99fcdf791bee HTML Author: ThomasV <thomasv@gitorious> Date: Thu, 11 Sep 2014 15:15:50 +0200 seed_v9: strip whitespaces before hashing Diffstat: M lib/mnemonic.py | 15 +++++++-------- M lib/version.py | 4 ++-- M lib/wallet.py | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) --- DIR diff --git a/lib/mnemonic.py b/lib/mnemonic.py t@@ -21,6 +21,7 @@ import hmac import math import hashlib import unicodedata +import string import ecdsa import pbkdf2 t@@ -37,13 +38,10 @@ filenames = { '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 + # Seed derivation no longer follows BIP39 # Mnemonic phrase uses a hash based checksum, instead of a wordlist-dependent checksum def __init__(self, lang='en'): t@@ -68,9 +66,10 @@ class Mnemonic(object): @classmethod def prepare_seed(self, seed): - # remove accents to tolerate typos - seed = unicode(remove_accents(seed.strip())) - seed = unicodedata.normalize('NFKD', seed) + # normalize + seed = unicodedata.normalize('NFKD', unicode(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 def mnemonic_encode(self, i): t@@ -113,7 +112,7 @@ class Mnemonic(object): assert i == self.mnemonic_decode(seed) if is_old_seed(seed): continue - if is_new_seed(self.prepare_seed(seed), prefix): + if is_new_seed(seed, prefix): break print_error('%d words'%len(seed.split())) return seed DIR diff --git a/lib/version.py b/lib/version.py t@@ -1,7 +1,7 @@ ELECTRUM_VERSION = "2.0" # version of the client package PROTOCOL_VERSION = '0.9' # protocol version requested -NEW_SEED_VERSION = 8 # bip32 wallets -OLD_SEED_VERSION = 4 # old electrum deterministic generation +NEW_SEED_VERSION = 9 # electrum versions >= 2.0 +OLD_SEED_VERSION = 4 # electrum versions < 2.0 # The hash of the mnemonic seed must begin with this DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -1614,7 +1614,7 @@ class Wallet(object): if seed_version not in [OLD_SEED_VERSION, NEW_SEED_VERSION]: 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 print msg sys.exit(1)