mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add support for signing and verifying to NewcoinAddress.
This commit is contained in:
@@ -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
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user