add_cold_seed
authorThomasV <thomasv@gitorious>
Fri, 25 Apr 2014 15:51:41 +0000 (17:51 +0200)
committerThomasV <thomasv@gitorious>
Fri, 25 Apr 2014 15:51:41 +0000 (17:51 +0200)
gui/qt/installwizard.py
lib/wallet.py

index ef10508..3a0be28 100644 (file)
@@ -331,14 +331,19 @@ class InstallWizard(QDialog):
                 wallet = Wallet_2of3(self.storage)
 
                 if Wallet.is_seed(text1):
-                    wallet.add_root("m/", text1, password)
+                    wallet.add_seed(text1, password)
+                    if Wallet.is_seed(text2):
+                        wallet.add_cold_seed(text2, password)
+                    else:
+                        wallet.add_master_public_key("cold/", text2)
+
                 elif Wallet.is_mpk(text1):
-                    wallet.add_master_public_key("m/", text1)
-                
-                if Wallet.is_seed(text2):
-                    wallet.add_root("cold/", text2, password)
-                elif Wallet.is_mpk(text2):
-                    wallet.add_master_public_key("cold/", text2)
+                    if Wallet.is_seed(text2):
+                        wallet.add_seed(text2, password)
+                        wallet.add_master_public_key("cold/", text1)
+                    else:
+                        wallet.add_master_public_key("m/", text1)
+                        wallet.add_master_public_key("cold/", text2)
 
                 run_hook('restore_third_key', wallet, self)
 
index 505118e..9111270 100644 (file)
@@ -302,7 +302,8 @@ class NewWallet:
         return NEW_SEED_VERSION, unicodedata.normalize('NFC', unicode(seed.strip()))
 
 
-    def save_seed(self, seed, password):
+
+    def add_seed(self, seed, password):
         if self.seed: 
             raise Exception("a seed exists")
         
@@ -355,14 +356,6 @@ class NewWallet:
         return xpub
 
 
-    def add_root(self, name, mnemonic, password, add_private = True):
-        seed = mnemonic_to_seed(mnemonic,'').encode('hex')
-        xpriv, xpub = bip32_root(seed)
-        self.add_master_public_key(name, xpub)
-        if add_private:
-            self.add_master_private_key(name, xpriv, password)
-
-
     def create_master_keys(self, password):
         xpriv, xpub = bip32_root(self.get_seed(password))
         self.add_master_public_key("m/", xpub)
@@ -1506,6 +1499,20 @@ class Wallet_2of2(NewWallet):
         xpub2 = self.master_public_keys.get("cold/")
         return {'hot':xpub1, 'cold':xpub2}
 
+
+    def add_cold_seed(self, cold_seed, password):
+        seed_version, cold_seed = self.prepare_seed(cold_seed)
+        hex_seed = mnemonic_to_seed(cold_seed,'').encode('hex')
+        xpriv, xpub = bip32_root(hex_seed)
+
+        if password: 
+            cold_seed = pw_encode( cold_seed, password)
+        self.storage.put('cold_seed', cold_seed, True)
+
+        self.add_master_public_key('cold/', xpub)
+        self.add_master_private_key('cold/', xpriv, password)
+
+
 class Wallet_2of3(Wallet_2of2):
 
     def __init__(self, storage):