Old daemon and wallet version 0.17.0.1
Import private key
It seems like it would be a really good idea to incorporate re-versioning of private keys via the importprivkey directly into the client.
I’ve written this code in python, but it should be pretty straight forward for someone to reproduce it in C++ and the QT client.
The problem is the private key format has the wrong version. But this can be fixed.
The code in python is here:
And the relevant steps in plain English are as follows:
Goal: Turn the privkey import format back into the private key.
Step 1: b58decode(wifpriv)
Step 2: strip the last 4 characters off the end of step 1 (checksum).
Step 3: strip the first character off the end of step 2 (version).
Goal: Turn the private key back into an importable private key format with correct version
Step 1: Concatenate version and private key. (0x8E for FTC). (version)
Step 2: sha256(step1)
Step 3: sha256(step2)
Step 4: Concatenate step 1 and the last 4 characters of step 3. (checksum)
Step 5: b58encode(step4)
Since this code is all already in the C++ QT client, it should be pretty easy to adopt it while removing the check on the version. Or maybe just do that: remove the check on the version, since that would accomplish the same thing.
kris_davison last edited by | Tip kris_davison
yes good idea I guess if the first pass at importprivkey fails with a code 5 (Invalid KEY) then you could give it another go after passing through your code.
Sounds great, I’d like to look into that, once I get my head round it.
The code that’s throwing the error is here:
There’s an enum of version numbers there, and when CBase58Data::SetString is called the version gets coppied…
bool SetString(const char* pszSecret)
return CBase58Data::SetString(pszSecret) && IsValid();
and because the version is wrong IsValid returns false.
But I think it should be handled at a higher level, namely in src/rpcdump.cpp, line 35, importprivkey(…).
Am I close?
I’d go for a simple warning, when the version isn’t correct and give the user a selection whether to import or not.
Another possibility could be to validate against a list of valid versions?
This would have the advantage, that in future times, privated keys with very old versions could be rejected, e.g. if they are known to be vulnerable.
I’m not deep into the code, so I’m not sure if this can be implemented easy
Bitcoin Worth Â£4.6 Million Is Buried Under A Landfill In South Wales