Update copyrights to 2012 for files modified this year
[novacoin.git] / src / key.h
index c0fce18..8b033a0 100644 (file)
--- a/src/key.h
+++ b/src/key.h
@@ -1,13 +1,21 @@
 // Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2009-2012 The Bitcoin developers
 // Distributed under the MIT/X11 software license, see the accompanying
 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
 #ifndef BITCOIN_KEY_H
 #define BITCOIN_KEY_H
 
+#include <stdexcept>
+#include <vector>
+
 #include <openssl/ec.h>
 #include <openssl/ecdsa.h>
 #include <openssl/obj_mac.h>
 
+#include "serialize.h"
+#include "uint256.h"
+#include "base58.h"
+
 // secp160k1
 // const unsigned int PRIVATE_KEY_SIZE = 192;
 // const unsigned int PUBLIC_KEY_SIZE  = 41;
@@ -221,20 +229,20 @@ public:
         return true;
     }
 
-    static bool Sign(const CPrivKey& vchPrivKey, uint256 hash, std::vector<unsigned char>& vchSig)
+    CBitcoinAddress GetAddress() const
     {
-        CKey key;
-        if (!key.SetPrivKey(vchPrivKey))
-            return false;
-        return key.Sign(hash, vchSig);
+        return CBitcoinAddress(GetPubKey());
     }
 
-    static bool Verify(const std::vector<unsigned char>& vchPubKey, uint256 hash, const std::vector<unsigned char>& vchSig)
+    bool IsValid()
     {
-        CKey key;
-        if (!key.SetPubKey(vchPubKey))
+        if (!fSet)
             return false;
-        return key.Verify(hash, vchSig);
+
+        CSecret secret = GetSecret();
+        CKey key2;
+        key2.SetSecret(secret);
+        return GetPubKey() == key2.GetPubKey();
     }
 };