Here is some code I wrote - AND TESTED =) - that enables full support for mini private key imports, including proper rejection of codes failing the typo check. Regular 51-character private keys still work like normal. Simply replace, removing 5 lines starting from “string strLabel = “”;” thru “bool fGood = vchSecret…” and inserting the following. Sorry I am new to developing with git, learning fast, but am unfamiliar with whether there is a way I can submit a “pull on a pull”, and sorry if there is a much better way to submit this.
Edit: updated it to make sure removeprivkey benefited from the change as well, as the initial post had the new code right inside importprivkey and only benefited that command.
Add the following function to rpcdump.cpp:
0// Sets the private key of a CBitcoinSecret, detecting whether it's a mini or full private key
1bool SetSecretDetect(string &strSecret, CBitcoinSecret &secret) {
2 int nSecretLength = strSecret.size();
3 if (nSecretLength == 22 || nSecretLength == 26)
4 {
5 if (strSecret[0] == 'S')
6 {
7 int i;
8 bool fMini = false;
9 for (i = 0; i < nSecretLength; i++)
10 {
11 char c = strSecret[i];
12 if (c < '1' || c > 'z') break;
13 if (c > '9' && c < 'A') break;
14 if (c > 'Z' && c < 'a') break;
15 if (c == 'I' || c == 'l' || c == 'O') break;
16 }
17 if (i==nSecretLength)
18 {
19 string strKeycheck(strSecret);
20 strKeycheck += "?";
21 uint256 hash;
22 SHA256((unsigned char*)strKeycheck.c_str(), strKeycheck.size(), (unsigned char*)&hash);
23 if (*(hash.begin()) == 0)
24 fMini=true;
25 else
26 {
27 uint256 hash2;
28 for (i=0; i<358; i++) // 358*2=716 +1=717
29 {
30 SHA256((unsigned char*)BEGIN(hash), sizeof(hash), (unsigned char*)&hash2);
31 SHA256((unsigned char*)BEGIN(hash2), sizeof(hash2), (unsigned char*)&hash);
32 }
33 if (*(hash.begin()) == 0) fMini = true;
34 }
35 if (fMini)
36 {
37 uint256 hash;
38 SHA256((unsigned char*)strSecret.c_str(), nSecretLength, (unsigned char*)&hash);
39 secret.SetHash256(hash);
40 return true;
41 }
42 }
43 }
44 }
45 return secret.SetString(strSecret);
46}
….. then in importprivkey() and removeprivkey() find the following line: …..
0bool fGood = vchSecret.SetString(strSecret);
….. and replace it with …..
0bool fGood = SetSecretDetect(strSecret, vchSecret);
….. and then in base58.h in class CBitcoinSecret (public), I added, just after SetSecret(): ……
0void SetHash256(const uint256& hash256)
1{
2 SetData(fTestNet ? 239 : 128, &hash256, 32);
3}