commit 043d6addffb5ad960216222802e98ccde315ea80
parent 50305e1f57bca1f499430a3069d189e2f619e669
Author: ThomasV <thomasv@gitorious>
Date: Sun, 3 Feb 2013 15:08:26 +0100
init_seed method. save seed and master public key separately
Diffstat:
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/electrum b/electrum
@@ -220,8 +220,7 @@ if __name__ == '__main__':
s = gui.network_dialog()
if a =='create':
- wallet.new_seed(None)
- wallet.init_mpk( wallet.seed )
+ wallet.init_seed(None)
else:
# ask for seed and gap.
sg = gui.seed_dialog()
@@ -230,11 +229,10 @@ if __name__ == '__main__':
if not seed: exit()
wallet.gap_limit = gap
if len(seed) == 128:
- wallet.seed = None
+ wallet.seed = ''
wallet.master_public_key = seed
else:
- wallet.seed = str(seed)
- wallet.init_mpk( wallet.seed )
+ wallet.init_seed(str(seed))
# generate the first addresses, in case we are offline
@@ -343,8 +341,7 @@ if __name__ == '__main__':
wallet.save()
print_msg("Wallet saved in '%s'"%wallet.config.path)
else:
- wallet.new_seed(None)
- wallet.init_mpk( wallet.seed )
+ wallet.init_seed(None)
wallet.synchronize() # there is no wallet thread
wallet.save()
print_msg("Your wallet generation seed is: " + wallet.seed)
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -141,11 +141,13 @@ class Wallet:
return address
- def new_seed(self, password):
- seed = "%032x"%ecdsa.util.randrange( pow(2,128) )
- #self.init_mpk(seed)
- # encrypt
- self.seed = self.pw_encode( seed, password )
+ def init_seed(self, seed):
+ if not seed:
+ seed = "%032x"%ecdsa.util.randrange( pow(2,128) )
+ self.seed = seed
+ self.config.set_key('seed', self.seed, True)
+ self.config.set_key('seed_version', self.seed_version, True)
+ self.init_mpk(self.seed)
def init_mpk(self,seed):
# public key
@@ -153,6 +155,7 @@ class Wallet:
secexp = self.stretch_key(seed)
master_private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve = SECP256k1 )
self.master_public_key = master_private_key.get_verifying_key().to_string().encode('hex')
+ self.config.set_key('master_public_key', self.master_public_key, True)
def all_addresses(self):
return self.addresses + self.change_addresses + self.imported_keys.keys()
@@ -913,6 +916,7 @@ class Wallet:
if new_password == '': new_password = None
self.use_encryption = (new_password != None)
self.seed = self.pw_encode( seed, new_password)
+ self.config.set_key('seed', self.seed, True)
for k in self.imported_keys.keys():
a = self.imported_keys[k]
b = self.pw_decode(a, old_password)
@@ -1048,12 +1052,9 @@ class Wallet:
def save(self):
s = {
- 'seed_version': self.seed_version,
'use_encryption': self.use_encryption,
'use_change': self.use_change,
- 'master_public_key': self.master_public_key,
'fee': self.fee,
- 'seed': self.seed,
'addresses': self.addresses,
'change_addresses': self.change_addresses,
'addr_history': self.history,