Skip to content

Commit

Permalink
RPC: In addition to public key pairs, adjustmalleablepubkey method no…
Browse files Browse the repository at this point in the history
…w understands malleable addresses and key views.
  • Loading branch information
CryptoManiac committed Apr 1, 2016
1 parent 27e35b8 commit d2a1ea2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ bool CMalleablePubKey::SetString(const std::string& strMalleablePubKey)
if (!DecodeBase58Check(strMalleablePubKey, vchTemp)) {
throw key_error("CMalleablePubKey::SetString() : Provided key data seems corrupted.");
}
if (vchTemp.size() != 68)
return false;

CDataStream ssKey(vchTemp, SER_NETWORK, PROTOCOL_VERSION);
ssKey >> *this;
Expand Down Expand Up @@ -1028,7 +1030,8 @@ bool CMalleableKey::SetString(const std::string& strMutableKey)
if (!DecodeBase58Check(strMutableKey, vchTemp)) {
throw key_error("CMalleableKey::SetString() : Provided key data seems corrupted.");
}

if (vchTemp.size() != 66)
return false;
CDataStream ssKey(vchTemp, SER_NETWORK, PROTOCOL_VERSION);
ssKey >> *this;

Expand Down Expand Up @@ -1172,6 +1175,9 @@ bool CMalleableKeyView::SetString(const std::string& strMutableKey)
throw key_error("CMalleableKeyView::SetString() : Provided key data seems corrupted.");
}

if (vchTemp.size() != 67)
return false;

CDataStream ssKey(vchTemp, SER_NETWORK, PROTOCOL_VERSION);
ssKey >> *this;

Expand Down
33 changes: 26 additions & 7 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,7 @@ Value validateaddress(const Array& params, bool fHelp)
CMalleableKeyView view;
bool isMine = pwalletMain->GetMalleableView(mpk, view);
ret.push_back(Pair("ismine", isMine));
ret.push_back(Pair("PubkeyPair", mpk.ToString()));

if (isMine)
ret.push_back(Pair("KeyView", view.ToString()));
Expand Down Expand Up @@ -1981,16 +1982,34 @@ Value adjustmalleablepubkey(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2 || params.size() == 0)
throw runtime_error(
"adjustmalleablepubkey <Malleable public key data>\n"
"Calculate new public key using provided malleable public key data.\n");
"adjustmalleablepubkey <Malleable address, key view or public key pair>\n"
"Calculate new public key using provided data.\n");

string pubKeyPair = params[0].get_str();
string strData = params[0].get_str();
CMalleablePubKey malleablePubKey;

if (pubKeyPair.size() == 136) {
malleablePubKey.setvch(ParseHex(pubKeyPair));
} else
malleablePubKey.SetString(pubKeyPair);
do
{
CBitcoinAddress addr(strData);
if (addr.IsValid() && addr.IsPair())
{
// Initialize malleable pubkey with address data
malleablePubKey = CMalleablePubKey(addr.GetData());
break;
}
CMalleableKeyView viewTmp(strData);
if (viewTmp.IsValid())
{
// Shazaam, we have a valid key view here.
malleablePubKey = viewTmp.GetMalleablePubKey();
break;
}
if (malleablePubKey.SetString(strData))
break; // A valid public key pair

throw runtime_error("Though your data seems a valid Base58 string, we were unable to recognize it.");
}
while(false);

CPubKey R, vchPubKeyVariant;
malleablePubKey.GetVariant(R, vchPubKeyVariant);
Expand Down

0 comments on commit d2a1ea2

Please sign in to comment.