electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 43513adb5c6a68235ef426e9e6aa608ae334d8c7
parent f3e2e7b50164303dd2b8c1475cbd99fcdf791bee
Author: ThomasV <thomasv@gitorious>
Date:   Thu, 11 Sep 2014 15:15:50 +0200

seed_v9: strip whitespaces before hashing

Diffstat:
Mlib/mnemonic.py | 15+++++++--------
Mlib/version.py | 4++--
Mlib/wallet.py | 2+-
3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/lib/mnemonic.py b/lib/mnemonic.py @@ -21,6 +21,7 @@ import hmac import math import hashlib import unicodedata +import string import ecdsa import pbkdf2 @@ -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'): @@ -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): @@ -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 diff --git a/lib/version.py b/lib/version.py @@ -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 diff --git a/lib/wallet.py b/lib/wallet.py @@ -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)