mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-11 15:27:57 +00:00
Merge pull request #1936 from sipa/morehashwriter
Use CHashWriter also in SignatureHash(), and for message signing
This commit is contained in:
commit
f50fb5470b
@ -329,12 +329,12 @@ Value signmessage(const Array& params, bool fHelp)
|
|||||||
if (!pwalletMain->GetKey(keyID, key))
|
if (!pwalletMain->GetKey(keyID, key))
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
|
||||||
|
|
||||||
CDataStream ss(SER_GETHASH, 0);
|
CHashWriter ss(SER_GETHASH, 0);
|
||||||
ss << strMessageMagic;
|
ss << strMessageMagic;
|
||||||
ss << strMessage;
|
ss << strMessage;
|
||||||
|
|
||||||
vector<unsigned char> vchSig;
|
vector<unsigned char> vchSig;
|
||||||
if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig))
|
if (!key.SignCompact(ss.GetHash(), vchSig))
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
|
||||||
|
|
||||||
return EncodeBase64(&vchSig[0], vchSig.size());
|
return EncodeBase64(&vchSig[0], vchSig.size());
|
||||||
@ -365,12 +365,12 @@ Value verifymessage(const Array& params, bool fHelp)
|
|||||||
if (fInvalid)
|
if (fInvalid)
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
|
||||||
|
|
||||||
CDataStream ss(SER_GETHASH, 0);
|
CHashWriter ss(SER_GETHASH, 0);
|
||||||
ss << strMessageMagic;
|
ss << strMessageMagic;
|
||||||
ss << strMessage;
|
ss << strMessage;
|
||||||
|
|
||||||
CKey key;
|
CKey key;
|
||||||
if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig))
|
if (!key.SetCompactSignature(ss.GetHash(), vchSig))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (key.GetPubKey().GetID() == keyID);
|
return (key.GetPubKey().GetID() == keyID);
|
||||||
|
@ -1183,10 +1183,9 @@ uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Serialize and hash
|
// Serialize and hash
|
||||||
CDataStream ss(SER_GETHASH, 0);
|
CHashWriter ss(SER_GETHASH, 0);
|
||||||
ss.reserve(10000);
|
|
||||||
ss << txTmp << nHashType;
|
ss << txTmp << nHashType;
|
||||||
return Hash(ss.begin(), ss.end());
|
return ss.GetHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user