Browse Source
Introduce wrappers around CZCViewingKey
pull/4/head
Jack Grigg
6 years ago
No known key found for this signature in database
GPG Key ID: 665DBCD284F7DAFF
4 changed files with
25 additions and
7 deletions
-
src/base58.cpp
-
src/base58.h
-
src/wallet/rpcdump.cpp
-
src/wallet/rpcwallet.cpp
|
|
@ -379,6 +379,21 @@ boost::optional<libzcash::PaymentAddress> DecodePaymentAddress(const std::string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
std::string EncodeViewingKey(const libzcash::ViewingKey& vk) |
|
|
|
{ |
|
|
|
return CZCViewingKey(vk).ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
boost::optional<libzcash::ViewingKey> DecodeViewingKey(const std::string& str) |
|
|
|
{ |
|
|
|
CZCViewingKey vk(str); |
|
|
|
try { |
|
|
|
return vk.Get(); |
|
|
|
} catch (const std::runtime_error&) { |
|
|
|
return boost::none; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
std::string EncodeSpendingKey(const libzcash::SpendingKey& zkey) |
|
|
|
{ |
|
|
|
return CZCSpendingKey(zkey).ToString(); |
|
|
|
|
|
@ -182,6 +182,9 @@ bool IsValidDestinationString(const std::string& str, const CChainParams& params |
|
|
|
std::string EncodePaymentAddress(const libzcash::PaymentAddress& zaddr); |
|
|
|
boost::optional<libzcash::PaymentAddress> DecodePaymentAddress(const std::string& str); |
|
|
|
|
|
|
|
std::string EncodeViewingKey(const libzcash::ViewingKey& vk); |
|
|
|
boost::optional<libzcash::ViewingKey> DecodeViewingKey(const std::string& str); |
|
|
|
|
|
|
|
std::string EncodeSpendingKey(const libzcash::SpendingKey& zkey); |
|
|
|
boost::optional<libzcash::SpendingKey> DecodeSpendingKey(const std::string& str); |
|
|
|
|
|
|
|
|
|
@ -705,8 +705,11 @@ UniValue z_importviewingkey(const UniValue& params, bool fHelp) |
|
|
|
} |
|
|
|
|
|
|
|
string strVKey = params[0].get_str(); |
|
|
|
CZCViewingKey viewingkey(strVKey); |
|
|
|
auto vkey = viewingkey.Get(); |
|
|
|
auto viewingkey = DecodeViewingKey(strVKey); |
|
|
|
if (!viewingkey) { |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid viewing key"); |
|
|
|
} |
|
|
|
auto vkey = *viewingkey; |
|
|
|
auto addr = vkey.address(); |
|
|
|
|
|
|
|
{ |
|
|
@ -815,6 +818,5 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) |
|
|
|
vk = k.viewing_key(); |
|
|
|
} |
|
|
|
|
|
|
|
CZCViewingKey viewingkey(vk); |
|
|
|
return viewingkey.ToString(); |
|
|
|
return EncodeViewingKey(vk); |
|
|
|
} |
|
|
|
|
|
@ -3067,12 +3067,10 @@ UniValue zc_raw_keygen(const UniValue& params, bool fHelp) |
|
|
|
auto addr = k.address(); |
|
|
|
auto viewing_key = k.viewing_key(); |
|
|
|
|
|
|
|
CZCViewingKey viewingkey(viewing_key); |
|
|
|
|
|
|
|
UniValue result(UniValue::VOBJ); |
|
|
|
result.push_back(Pair("zcaddress", EncodePaymentAddress(addr))); |
|
|
|
result.push_back(Pair("zcsecretkey", EncodeSpendingKey(k))); |
|
|
|
result.push_back(Pair("zcviewingkey", viewingkey.ToString())); |
|
|
|
result.push_back(Pair("zcviewingkey", EncodeViewingKey(viewing_key))); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|