check decoded seed with master public key instead of an address
authorThomasV <thomasv@gitorious>
Sun, 6 Jan 2013 15:31:17 +0000 (16:31 +0100)
committerThomasV <thomasv@gitorious>
Sun, 6 Jan 2013 15:31:17 +0000 (16:31 +0100)
lib/wallet.py

index e5583df..ca428af 100644 (file)
@@ -649,11 +649,18 @@ class Wallet:
             return s
 
     def decode_seed(self, password):
-        # test password on an address
-        addr = self.all_addresses()[0]
-        self.get_private_key(addr, password)
-        # return seed
-        return self.pw_decode(self.seed, password)
+        seed = self.pw_decode(self.seed, password)
+
+        # check decoded seed with master public key
+        curve = SECP256k1
+        secexp = self.stretch_key(seed)
+        master_private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve = SECP256k1 )
+        master_public_key = master_private_key.get_verifying_key().to_string().encode('hex')
+        if master_public_key != self.master_public_key:
+            print_error('invalid password (mpk)')
+            raise BaseException('Invalid password')
+
+        return seed
 
 
     def get_history(self, address):