add additional param to importprivkey for other WIF formats

This commit is contained in:
Alrighttt
2019-07-01 19:03:52 +02:00
parent 896b6fee53
commit 5e6737fc38
4 changed files with 28 additions and 2 deletions

View File

@@ -207,6 +207,22 @@ CKey DecodeSecret(const std::string& str)
return key;
}
CKey DecodeCustomSecret(const std::string& str, uint8_t secret_key)
{
CKey key;
std::vector<unsigned char> data;
if (DecodeBase58Check(str, data)) {
const std::vector<unsigned char>& privkey_prefix = std::vector<unsigned char>(1, secret_key);
if ((data.size() == 32 + privkey_prefix.size() || (data.size() == 33 + privkey_prefix.size() && data.back() == 1)) &&
std::equal(privkey_prefix.begin(), privkey_prefix.end(), data.begin())) {
bool compressed = data.size() == 33 + privkey_prefix.size();
key.Set(data.begin() + privkey_prefix.size(), data.begin() + privkey_prefix.size() + 32, compressed);
}
}
memory_cleanse(data.data(), data.size());
return key;
}
std::string EncodeSecret(const CKey& key)
{
assert(key.IsValid());