diff --git a/src/NewcoinAddress.cpp b/src/NewcoinAddress.cpp index f09a45789..47b064baf 100644 --- a/src/NewcoinAddress.cpp +++ b/src/NewcoinAddress.cpp @@ -137,6 +137,31 @@ void NewcoinAddress::setNodePublic(const std::vector& vPublic) SetData(VER_NODE_PUBLIC, vPublic); } +bool NewcoinAddress::verifyNodePublic(const uint256& hash, const std::vector& vchSig) const +{ + CKey pubkey = CKey(); + bool bVerified; + + if (!pubkey.SetPubKey(getNodePublic())) + { + // Failed to set public key. + bVerified = false; + } + else + { + bVerified = pubkey.Verify(hash, vchSig); + } + + return bVerified; +} + +bool NewcoinAddress::verifyNodePublic(const uint256& hash, const std::string& strSig) const +{ + std::vector vchSig(strSig.begin(), strSig.end()); + + return verifyNodePublic(hash, vchSig); +} + // // NodePrivate // @@ -197,6 +222,17 @@ void NewcoinAddress::setNodePrivate(uint256 hash256) SetData(VER_NODE_PRIVATE, hash256.begin(), 32); } +void NewcoinAddress::signNodePrivate(const uint256& hash, std::vector& vchSig) const +{ + CKey privkey = CKey(); + + if (!privkey.SetSecret(getNodePrivateData())) + throw std::runtime_error("SetSecret failed."); + + if (!privkey.Sign(hash, vchSig)) + throw std::runtime_error("Signing failed."); +} + // // AccountID // diff --git a/src/NewcoinAddress.h b/src/NewcoinAddress.h index 8a560d49b..e07d510f6 100644 --- a/src/NewcoinAddress.h +++ b/src/NewcoinAddress.h @@ -50,6 +50,8 @@ public: bool setNodePublic(const std::string& strPublic); void setNodePublic(const std::vector& vPublic); + bool verifyNodePublic(const uint256& hash, const std::vector& vchSig) const; + bool verifyNodePublic(const uint256& hash, const std::string& strSig) const; // // Node Private @@ -62,6 +64,7 @@ public: bool setNodePrivate(const std::string& strPrivate); void setNodePrivate(const std::vector& vPrivate); void setNodePrivate(uint256 hash256); + void signNodePrivate(const uint256& hash, std::vector& vchSig) const; // // Accounts IDs