Skip to content

Commit

Permalink
Update makeairdropfile to be comatible with verifymessage.
Browse files Browse the repository at this point in the history
  • Loading branch information
anchaj authored and tohsnoom committed Jul 30, 2021
1 parent 4d2d2b8 commit 1469583
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char>& 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)
Expand Down Expand Up @@ -816,23 +794,26 @@ UniValue makeairdropfile(const UniValue& params, bool fHelp)
for (std::vector<std::pair<int64_t, CKeyID> >::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<unsigned char> 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 << ",";
}
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 << "}";
}
Expand Down

0 comments on commit 1469583

Please sign in to comment.