Add support for signing and verifying to NewcoinAddress.

This commit is contained in:
Arthur Britto
2012-04-29 13:57:53 -07:00
parent 62ed100198
commit f4a0c1b48f
2 changed files with 39 additions and 0 deletions

View File

@@ -137,6 +137,31 @@ void NewcoinAddress::setNodePublic(const std::vector<unsigned char>& vPublic)
SetData(VER_NODE_PUBLIC, vPublic); SetData(VER_NODE_PUBLIC, vPublic);
} }
bool NewcoinAddress::verifyNodePublic(const uint256& hash, const std::vector<unsigned char>& 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<unsigned char> vchSig(strSig.begin(), strSig.end());
return verifyNodePublic(hash, vchSig);
}
// //
// NodePrivate // NodePrivate
// //
@@ -197,6 +222,17 @@ void NewcoinAddress::setNodePrivate(uint256 hash256)
SetData(VER_NODE_PRIVATE, hash256.begin(), 32); SetData(VER_NODE_PRIVATE, hash256.begin(), 32);
} }
void NewcoinAddress::signNodePrivate(const uint256& hash, std::vector<unsigned char>& 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 // AccountID
// //

View File

@@ -50,6 +50,8 @@ public:
bool setNodePublic(const std::string& strPublic); bool setNodePublic(const std::string& strPublic);
void setNodePublic(const std::vector<unsigned char>& vPublic); void setNodePublic(const std::vector<unsigned char>& vPublic);
bool verifyNodePublic(const uint256& hash, const std::vector<unsigned char>& vchSig) const;
bool verifyNodePublic(const uint256& hash, const std::string& strSig) const;
// //
// Node Private // Node Private
@@ -62,6 +64,7 @@ public:
bool setNodePrivate(const std::string& strPrivate); bool setNodePrivate(const std::string& strPrivate);
void setNodePrivate(const std::vector<unsigned char>& vPrivate); void setNodePrivate(const std::vector<unsigned char>& vPrivate);
void setNodePrivate(uint256 hash256); void setNodePrivate(uint256 hash256);
void signNodePrivate(const uint256& hash, std::vector<unsigned char>& vchSig) const;
// //
// Accounts IDs // Accounts IDs