{ "adjustmalleablepubkey", &adjustmalleablepubkey, false, false},
{ "listmalleableviews", &listmalleableviews, false, false},
{ "dumpmalleablekey", &dumpmalleablekey, false, false},
+ { "validatemalleablepubkey",&validatemalleablepubkey,true, false },
+ { "importmalleablekey", &importmalleablekey, true, false },
{ "encryptdata", &encryptdata, false, false },
{ "decryptdata", &decryptdata, false, false },
{ "encryptmessage", &encryptmessage, false, false },
extern json_spirit::Value adjustmalleablepubkey(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value listmalleableviews(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dumpmalleablekey(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value validatemalleablepubkey(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value importmalleablekey(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value encryptdata(const json_spirit::Array& params, bool fHelp); // in rpccrypt.cpp
extern json_spirit::Value decryptdata(const json_spirit::Array& params, bool fHelp);
SetSecrets(L, H);
}
-/*
-CMalleableKey& CMalleableKey::operator=(const CMalleableKey &b)
-{
- SetSecrets(b.vchSecretL, b.vchSecretH);
-
- return (*this);
-}
-*/
-
CMalleableKey::~CMalleableKey()
{
}
return true;
}
-void CMalleableKey::GetSecrets(CSecret &pvchSecretL, CSecret &pvchSecretH) const
-{
- pvchSecretL = vchSecretL;
- pvchSecretH = vchSecretH;
-}
-
CMalleablePubKey CMalleableKey::GetMalleablePubKey() const
{
CKey L, H;
CDataStream ssKey(vchTemp, SER_NETWORK, PROTOCOL_VERSION);
ssKey >> *this;
- return IsNull();
+ return IsValid();
}
// CMalleableKeyView
nVersion = CURRENT_VERSION;
}
-CMalleableKeyView::CMalleableKeyView(const CSecret &L, const CPubKey &pvchPubKeyH)
-{
- vchSecretL = L;
- vchPubKeyH = pvchPubKeyH.Raw();
- nVersion = CURRENT_VERSION;
-}
-
CMalleableKeyView& CMalleableKeyView::operator=(const CMalleableKey &b)
{
vchSecretL = b.vchSecretL;
CDataStream ssKey(vchTemp, SER_NETWORK, PROTOCOL_VERSION);
ssKey >> *this;
- return IsNull();
+ return IsValid();
}
std::vector<unsigned char> CMalleableKeyView::Raw() const
}
CMalleablePubKey(const std::string& strMalleablePubKey) { SetString(strMalleablePubKey); }
CMalleablePubKey(const CPubKey &pubKeyInL, const CPubKey &pubKeyInH) : pubKeyL(pubKeyInL), pubKeyH(pubKeyInH) { nVersion = CMalleablePubKey::CURRENT_VERSION; }
- CMalleablePubKey(const std::vector<unsigned char> &pubKeyInL, const std::vector<unsigned char> &pubKeyInH) : pubKeyL(pubKeyInL), pubKeyH(pubKeyInH) { nVersion = CMalleablePubKey::CURRENT_VERSION; }
IMPLEMENT_SERIALIZE(
READWRITE(this->nVersion);
void Reset();
void MakeNewKeys();
bool IsNull() const;
+ bool IsValid() const { return !IsNull() && GetMalleablePubKey().IsValid(); }
bool SetSecrets(const CSecret &pvchSecretL, const CSecret &pvchSecretH);
- void GetSecrets(CSecret &pvchSecretL, CSecret &pvchSecretH) const;
+
+ CSecret GetSecretL() const { return vchSecretL; }
+ CSecret GetSecretH() const { return vchSecretH; }
CKeyID GetID() const {
return GetMalleablePubKey().GetID();
public:
CMalleableKeyView() { nVersion = 0; };
CMalleableKeyView(const CMalleableKey &b);
- CMalleableKeyView(const CSecret &L, const CPubKey &pvchPubKeyH);
CMalleableKeyView(const CMalleableKeyView &b);
CMalleableKeyView& operator=(const CMalleableKey &b);
~CMalleableKeyView();
-
IMPLEMENT_SERIALIZE(
READWRITE(this->nVersion);
nVersion = this->nVersion;
)
bool IsNull() const;
+ bool IsValid() const { return !IsNull() && GetMalleablePubKey().IsValid(); }
std::string ToString() const;
bool SetString(const std::string& strMalleablePubKey);
std::vector<unsigned char> Raw() const;
return GetMalleablePubKey().GetID();
}
CMalleablePubKey GetMalleablePubKey() const;
+ CMalleableKey GetMalleableKey(const CSecret &vchSecretH) const { return CMalleableKey(vchSecretL, vchSecretH); }
bool CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVariant) const;
bool operator <(const CMalleableKeyView& kv) const { return vchPubKeyH.GetID() < kv.vchPubKeyH.GetID(); }
malleableViewList.push_back(CMalleableKeyView(mi->first));
}
}
+
+ bool GetMalleableView(const CMalleablePubKey &mpk, CMalleableKeyView &view)
+ {
+ const CKeyID &mpkID = mpk.GetID();
+ {
+ LOCK(cs_KeyStore);
+ for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++)
+ if (mi->first.GetID() == mpkID)
+ {
+ view = CMalleableKeyView(mi->first);
+ return true;
+ }
+ }
+
+ return false;
+ }
};
typedef std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char> > > CryptedKeyMap;
return Value::null;
}
+
+Value dumpmalleablekey(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 1)
+ throw runtime_error (
+ "dumpmalleablekey <Key view>\n"
+ "Dump the private and public key pairs, which correspond to provided key view.\n");
+
+ CMalleableKey mKey;
+ CMalleableKeyView keyView;
+ keyView.SetString(params[0].get_str());
+
+ if (!pwalletMain->GetMalleableKey(keyView, mKey))
+ throw runtime_error("There is no such item in the wallet");
+
+ Object result;
+ result.push_back(Pair("PrivatePair", mKey.ToString()));
+ result.push_back(Pair("PublicPair", mKey.GetMalleablePubKey().ToString()));
+
+ return result;
+}
+
+Value importmalleablekey(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 1)
+ throw runtime_error (
+ "importmalleablekey <Key data>\n"
+ "Imports the private key pair into your wallet.\n");
+
+ CMalleableKey mKey;
+ bool fSuccess = mKey.SetString(params[0].get_str());
+
+ Object result;
+
+ if (fSuccess)
+ {
+ fSuccess = pwalletMain->AddMalleableKey(mKey);
+ result.push_back(Pair("Successful", fSuccess));
+ result.push_back(Pair("PublicPair", mKey.GetMalleablePubKey().ToString()));
+ result.push_back(Pair("KeyView", CMalleableKeyView(mKey).ToString()));
+ }
+ else
+ result.push_back(Pair("Successful", false));
+
+ return result;
+}
return result;
}
-Value dumpmalleablekey(const Array& params, bool fHelp)
+Value validatemalleablepubkey(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
- throw runtime_error (
- "dumpmalleablekey <Key view>\n"
- "Dump the private and public key pairs, which correspond to provided key view.\n");
+ throw runtime_error(
+ "validatemalleablekey <Malleable public key data>\n"
+ "Check the validity and ownership for priovided malleable public key.\n");
- CMalleableKey mKey;
- CMalleableKeyView keyView;
- keyView.SetString(params[0].get_str());
-
- if (!pwalletMain->GetMalleableKey(keyView, mKey))
- throw runtime_error("There is no such item in the wallet");
+ CMalleablePubKey mpk;
+ bool isValid = mpk.SetString(params[0].get_str());
Object result;
- result.push_back(Pair("PrivatePair", mKey.ToString()));
- result.push_back(Pair("PublicPair", mKey.GetMalleablePubKey().ToString()));
+ result.push_back(Pair("isvalid", isValid));
+
+ if (isValid)
+ {
+ CMalleableKeyView view;
+ bool isMine = pwalletMain->GetMalleableView(mpk, view);
+ result.push_back(Pair("ismine", isMine));
+
+ if (isMine)
+ result.push_back(Pair("KeyView", view.ToString()));
+ }
return result;
}