Skip to content

Commit

Permalink
Improved rpc makeairdropfile
Browse files Browse the repository at this point in the history
  • Loading branch information
wqking authored and tohsnoom committed Jul 29, 2021
1 parent 14e430f commit 4d2d2b8
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "utilstrencodings.h"
#include "utiltime.h"
#include "wallet/wallet.h"
#include "crypto/rfc6979_hmac_sha256.h"

#include <fstream>
#include <regex>
Expand Down Expand Up @@ -736,6 +737,28 @@ 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 @@ -800,15 +823,16 @@ UniValue makeairdropfile(const UniValue& params, bool fHelp)
ss << strAddr;

std::vector<unsigned char> vchSig;
if(key.SignCompact(Hash(ss.begin(), ss.end()), vchSig)) {
//if(key.SignCompact(Hash(ss.begin(), ss.end()), vchSig)) {
if(signCompactMessage(key, (const unsigned char *)(keyid.begin()), keyid.size(), 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\",\n", strAddr);
file << indent << indent << indent << strprintf("\"phrAddress\": \"%s-%s\",\n", bscAddress, strAddr);
file << indent << indent << indent << strprintf("\"signature\": \"%s\"\n", signature);
file << indent << indent << "}";
}
Expand Down

0 comments on commit 4d2d2b8

Please sign in to comment.