check seed in gui. fixes #622
This commit is contained in:
@@ -71,7 +71,25 @@ def mnemonic_to_seed(mnemonic, passphrase):
|
||||
return PBKDF2(mnemonic, 'mnemonic' + passphrase, iterations = PBKDF2_ROUNDS, macmodule = hmac, digestmodule = hashlib.sha512).read(64)
|
||||
|
||||
from version import SEED_PREFIX
|
||||
is_seed = lambda x: hmac_sha_512("Seed version", x).encode('hex')[0:2].startswith(SEED_PREFIX)
|
||||
is_new_seed = lambda x: hmac_sha_512("Seed version", x).encode('hex')[0:2].startswith(SEED_PREFIX)
|
||||
|
||||
def is_old_seed(seed):
|
||||
import mnemonic
|
||||
words = seed.strip().split()
|
||||
try:
|
||||
mnemonic.mn_decode(words)
|
||||
uses_electrum_words = True
|
||||
except Exception:
|
||||
uses_electrum_words = False
|
||||
|
||||
try:
|
||||
seed.decode('hex')
|
||||
is_hex = True
|
||||
except Exception:
|
||||
is_hex = False
|
||||
|
||||
return is_hex or (uses_electrum_words and len(words) == 12)
|
||||
|
||||
|
||||
# pywallet openssl private key implementation
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ class NewWallet:
|
||||
# we keep only 13 words, that's approximately 139 bits of entropy
|
||||
words = mnemonic.mn_encode(s)[0:13]
|
||||
seed = ' '.join(words)
|
||||
if is_seed(seed):
|
||||
if is_new_seed(seed):
|
||||
break # this will remove 8 bits of entropy
|
||||
nonce += 1
|
||||
|
||||
@@ -1781,36 +1781,23 @@ class Wallet(object):
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_seed(self, seed, storage):
|
||||
import mnemonic
|
||||
def is_seed(self, seed):
|
||||
if not seed:
|
||||
return
|
||||
|
||||
words = seed.strip().split()
|
||||
try:
|
||||
mnemonic.mn_decode(words)
|
||||
uses_electrum_words = True
|
||||
except Exception:
|
||||
uses_electrum_words = False
|
||||
|
||||
try:
|
||||
seed.decode('hex')
|
||||
is_hex = True
|
||||
except Exception:
|
||||
is_hex = False
|
||||
|
||||
if is_hex or (uses_electrum_words and len(words) == 12):
|
||||
#print "old style wallet", len(words), words
|
||||
w = OldWallet(storage)
|
||||
w.init_seed(seed) #hex
|
||||
else:
|
||||
assert is_seed(seed)
|
||||
w = NewWallet(storage)
|
||||
w.init_seed(seed)
|
||||
return False
|
||||
elif is_old_seed(seed):
|
||||
return OldWallet
|
||||
elif is_new_seed(seed):
|
||||
return NewWallet
|
||||
else:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def from_seed(self, seed, storage):
|
||||
klass = self.is_seed(seed)
|
||||
w = klass(storage)
|
||||
w.init_seed(seed)
|
||||
return w
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_mpk(self, mpk, storage):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user