hash_encode = lambda x: x[::-1].encode('hex')
hash_decode = lambda x: x.decode('hex')[::-1]
-
hmac_sha_512 = lambda x,y: hmac.new(x, y, hashlib.sha512).digest()
-mnemonic_hash = lambda x: hmac_sha_512("Bitcoin mnemonic", x).encode('hex')
+
+def mnemonic_to_seed(mnemonic, passphrase):
+ from pbkdf2 import PBKDF2
+ import hmac
+ PBKDF2_ROUNDS = 2048
+ 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)
os.chmod(self.path,stat.S_IREAD | stat.S_IWRITE)
+
+
+
class Wallet:
def __init__(self, storage):
self.next_addresses = storage.get('next_addresses',{})
- if self.seed_version not in [4, 6]:
- msg = "This wallet seed is not supported."
- if self.seed_version in [5]:
- msg += "\nTo open this wallet, try 'git checkout seed_v%d'"%self.seed_version
- print msg
- sys.exit(1)
# This attribute is set when wallet.start_threads is called.
self.synchronizer = None
def init_seed(self, seed):
- import mnemonic
+ import mnemonic, unicodedata
if self.seed:
raise Exception("a seed exists")
self.seed_version = SEED_VERSION
return
+ self.seed_version = SEED_VERSION
+ self.seed = unicodedata.normalize('NFC', unicode(seed.strip()))
+ return
+
# find out what kind of wallet we are
try:
seed.strip().decode('hex')
return '&'.join(dd)
-
def get_seed(self, password):
s = pw_decode(self.seed, password)
if self.seed_version == 4:
seed = s
self.accounts[0].check_seed(seed)
else:
- seed = mnemonic_hash(s)
+ seed = mnemonic_to_seed(s,'').encode('hex')
return seed
return ' '.join(mnemonic.mn_encode(s))
else:
return s
-
def get_private_key(self, address, password):
# Updated gets called too many times from other places as well; if we use that signal we get the notification three times
self.network.trigger_callback("new_transaction")
self.was_updated = False
+
+