From 146958316108e27bdf9f30562f33f4e7d3aaabb7 Mon Sep 17 00:00:00 2001 From: anchaj Date: Fri, 30 Jul 2021 09:51:03 +0200 Subject: [PATCH] Update makeairdropfile to be comatible with verifymessage. --- src/wallet/rpcdump.cpp | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 5f305fa8860b9..c00423ebeb6a4 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -737,28 +737,6 @@ UniValue bip38decrypt(const UniValue& params, bool fHelp) return result; } - -bool signCompactMessage(const CKey & key, const unsigned char * message, size_t length, std::vector& vchSig) -{ - if (! key.IsValid()) - return false; - vchSig.resize(65); - int rec = -1; - RFC6979_HMAC_SHA256 prng(key.begin(), 32, message, length); - do { - uint256 nonce; - prng.Generate((unsigned char*)&nonce, 32); - int ret = secp256k1_ecdsa_sign_compact(message, length, &vchSig[1], key.begin(), (unsigned char*)&nonce, &rec); - nonce = 0; - if (ret) - break; - } while (true); - assert(rec != -1); - vchSig[0] = 27 + rec + (key.IsCompressed() ? 4 : 0); - return true; -} - - UniValue makeairdropfile(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 3) @@ -816,15 +794,18 @@ UniValue makeairdropfile(const UniValue& params, bool fHelp) for (std::vector >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) { const CKeyID& keyid = it->second; std::string strAddr = EncodeDestination(CTxDestination(keyid)); + std::string strDelimiter = "-"; CKey key; if (pwalletMain->GetKey(keyid, key)) { - CDataStream ss(SER_GETHASH, 0); + CHashWriter ss(SER_GETHASH, 0); + ss << strMessageMagic; + ss << bscAddress; + ss << strDelimiter; ss << strAddr; std::vector vchSig; - //if(key.SignCompact(Hash(ss.begin(), ss.end()), vchSig)) { - if(signCompactMessage(key, (const unsigned char *)(keyid.begin()), keyid.size(), vchSig)) { + if(key.SignCompact(ss.GetHash(), vchSig)) { const std::string signature = EncodeBase64(&vchSig[0], vchSig.size()); if(needComma) { file << ","; @@ -832,7 +813,7 @@ UniValue makeairdropfile(const UniValue& params, bool fHelp) needComma = true; file << "\n"; file << indent << indent << "{\n"; - file << indent << indent << indent << strprintf("\"phrAddress\": \"%s-%s\",\n", bscAddress, strAddr); + file << indent << indent << indent << strprintf("\"phrAddress\": \"%s\",\n", strAddr); file << indent << indent << indent << strprintf("\"signature\": \"%s\"\n", signature); file << indent << indent << "}"; }