[Dev] Documenting Feathercoin Specific Software settings - Part 8
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/base58.cpp
+/* void CBitcoinSecret::SetKey(const CKey& vchSecret) { assert(vchSecret.IsValid()); SetData(Params().Base58Prefix(CChainParams::SECRET_KEY), vchSecret.begin(), vchSecret.size()); if (vchSecret.IsCompressed()) vchData.push_back(1); -} +}*/
Code commented out
+ void CBitcoinSecret::SetSecret(const CSecret& vchSecret, bool fCompressed) + { + assert(vchSecret.size() == 32); + SetData(Params().Base58Prefix(CChainParams::SECRET_KEY), &vchSecret[0], vchSecret.size()); + if (fCompressed) + vchData.push_back(1); + } + /*
Code added
+ }*/ + + CSecret CBitcoinSecret::GetSecret(bool &fCompressedOut) + { + CSecret vchSecret; + vchSecret.resize(32); + memcpy(&vchSecret[0], &vchData[0], 32); + fCompressedOut = vchData.size() == 33; + return vchSecret;
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/base58.h
+ //void SetKey(const CKey& vchSecret); + void SetSecret(const CSecret& vchSecret, bool fCompressed); + //CKey GetKey(); + CSecret GetSecret(bool &fCompressedOut);
Code replaced
+ //CBitcoinSecret(const CKey& vchSecret) { SetKey(vchSecret); } + CBitcoinSecret(const CSecret& vchSecret, bool fCompressed) + { + SetSecret(vchSecret, fCompressed); + }
Code replaced
+ //typedef CBitcoinExtKeyBase<CExtKey, 74, CChainParams::EXT_SECRET_KEY> CBitcoinExtKey; -typedef CBitcoinExtKeyBase<CExtPubKey, 74, CChainParams::EXT_PUBLIC_KEY> CBitcoinExtPubKey; + //typedef CBitcoinExtKeyBase<CExtPubKey, 74, CChainParams::EXT_PUBLIC_KEY> CBitcoinExtPubKey;
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/checkpointsync.cpp
+ //CKey key = vchSecret.GetKey(); // if key is not correct openssl may crash + CKey key; + bool fCompressed; + CSecret secret = vchSecret.GetSecret(fCompressed); + key.SetSecret(secret, fCompressed); // if key is not correct openssl may crash
Code replaced
+ //CKey key = vchSecret.GetKey(); // if key is not correct openssl may crash + CKey key; + bool fCompressed; + CSecret secret = vchSecret.GetSecret(fCompressed); + key.SetSecret(secret, fCompressed); // if key is not correct openssl may crash
Code added
+ CKey key;
Code added
+ //CPubKey key(ParseHex(strMasterPubKey)); + if (!key.SetPubKey(ParseHex(strMasterPubKey))) + return error("CSyncCheckpoint::CheckSignature() : SetPubKey failed");
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/crypter.cpp
+//bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext) +bool EncryptSecret(CKeyingMaterial& vMasterKey, const CSecret &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext)
Code replaced
+ //return cKeyCrypter.Encrypt(*((const CKeyingMaterial*)&vchPlaintext), vchCiphertext); + return cKeyCrypter.Encrypt((CKeyingMaterial)vchPlaintext, vchCiphertext);
Code replaced
+//bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext) +bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CSecret& vchPlaintext)
Code replaced
+ { + LOCK(cs_KeyStore); + if (fUseCrypto) + return true; + if (!mapKeys.empty()) + return false; + fUseCrypto = true; + }
Code replace
+ //CKeyingMaterial vchSecret; + CSecret vchSecret;
Code replaced
+ //key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed()); + key.SetPubKey(vchPubKey); + key.SetSecret(vchSecret);
Code replaced
+//bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) +bool CCryptoKeyStore::AddKey(const CKey& key)
Code replaced
+ //return CBasicKeyStore::AddKeyPubKey(key, pubkey); + return CBasicKeyStore::AddKey(key);
Code replaced
+ //CKeyingMaterial vchSecret(key.begin(), key.end()); + CPubKey vchPubKey = key.GetPubKey(); + bool fCompressed; + //if (!EncryptSecret(vMasterKey, vchSecret, pubkey.GetHash(), vchCryptedSecret)) + if (!EncryptSecret(vMasterKey, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret))
Code replaced
+ //if (!AddCryptedKey(pubkey, vchCryptedSecret)) + if (!AddCryptedKey(key.GetPubKey(), vchCryptedSecret))
Code replaced
+ //CKeyingMaterial vchSecret; + CSecret vchSecret;
Copde replaced
+ //keyOut.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed()); + keyOut.SetPubKey(vchPubKey); + keyOut.SetSecret(vchSecret);
Code replaced
+ //const CKey &key = mKey.second; + //CPubKey vchPubKey = key.GetPubKey(); + //CKeyingMaterial vchSecret(key.begin(), key.end()); + CKey key; + if (!key.SetSecret(mKey.second.first, mKey.second.second)) + return false; + const CPubKey vchPubKey = key.GetPubKey();
Code replaced
+ //if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret)) + bool fCompressed; + if (!EncryptSecret(vMasterKeyIn, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret))
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/crypter.h
+//bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext); +//bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext); +bool EncryptSecret(CKeyingMaterial& vMasterKey, const CSecret &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext); +bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char> &vchCiphertext, const uint256& nIV, CSecret &vchPlaintext);
Code replaced
+ //bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey); + bool AddKey(const CKey& key);
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/key.cpp
Large amount of code added and removed. Examples of code replaced.
+#include <map>
Code replaced
-#include <openssl/bn.h> -#include <openssl/rand.h>
Code removed
+void CKey::SetCompressedPubKey(bool fCompressed) + EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED); + fCompressedPubKey = true;
Complete functions replaced
+void CKey::Reset() +CKey::CKey(const CKey& b) +bool CKey::SetPrivKey(const CPrivKey& vchPrivKey) + const unsigned char* pbegin = &vchPrivKey[0]; +bool CKey::SetSecret(const CSecret& vchSecret, bool fCompressed +CSecret CKey::GetSecret(bool &fCompressed) const +CPrivKey CKey::GetPrivKey() const +CPubKey CKey::GetPubKey() const
Various functions replaced
+// create a compact signature (65 bytes), which allows reconstructing the used public key +// The format is one header byte, followed by two times 32 bytes for the serialized r and s values. +// The header byte: 0x1B = first key with even y, 0x1C = first key with odd y, +// 0x1D = second key with even y, 0x1E = second key with o +bool CKey::SignCompact(uint256 hash, std::vector<unsigned char>& vchSig)
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/key.h
+#include <stdexcept> +#include <vector> +#include "hash.h" +#include <openssl/ec.h> // for EC_KEY definition
Code added
+ // secp160k1 + // const unsigned int PRIVATE_KEY_SIZE = 192; + // const unsigned int PUBLIC_KEY_SIZE = 41; + // const unsigned int SIGNATURE_SIZE = 48; + // + // secp192k1 + // const unsigned int PRIVATE_KEY_SIZE = 222; + // const unsigned int PUBLIC_KEY_SIZE = 49; + // const unsigned int SIGNATURE_SIZE = 57; + // + // secp224k1 + // const unsigned int PRIVATE_KEY_SIZE = 250; + // const unsigned int PUBLIC_KEY_SIZE = 57; + // const unsigned int SIGNATURE_SIZE = 66; + //
Code added
+ class key_error : public std::runtime_error + { + public: + explicit key_error(const std::string& str) : std::runtime_error(str) {} + }; +
Code added
+ unsigned char *begin() { + return vch; Code replaced + friend class CKey; + public: + CPubKey() { vch[0] = 0xFF; }
Code added
+ CPubKey(const std::vector<unsigned char> &vchPubKeyIn) { + int len = vchPubKeyIn.empty() ? 0 : GetLen(vchPubKeyIn[0]); + if (len) { + memcpy(vch, &vchPubKeyIn[0], len); + } else { + vch[0] = 0xFF; + }
Code replaced
+ unsigned int size() const { + return GetLen(vch[0]);
Code replaced
+ const unsigned char *begin() const { + return vch;
Code replaced
+ const unsigned char *end() const { + return vch+size();
Code replaced
+ + friend bool operator==(const CPubKey &a, const CPubKey &b) { return memcmp(a.vch, b.vch, a.size()) == 0; } + friend bool operator!=(const CPubKey &a, const CPubKey &b) { return memcmp(a.vch, b.vch, a.size()) != 0; }
Code added
+ (a.vch[0] == b.vch[0] && memcmp(a.vch+1, b.vch+1, a.size() - 1) < 0);
Code replaced
+ // invalid pubkey + vch[0] = 0xFF;
Code added
+ //bool IsFullyValid() const;
Code commented out
+ return std::vector<unsigned char>(vch, vch+size());
Code replaced
+/** An encapsulated OpenSSL Elliptic Curve key (public and/or private) */ +class CKey +{ +protected: + EC_KEY* pkey; + bool fSet; + bool fCompressedPubKey;
Code replaced
+ void SetCompressedPubKey(bool fCompressed = true); + void Reset();
Code replaced
+ CKey(); + CKey(const CKey& b); + CKey& operator=(const CKey& b); + ~CKey(); + bool IsNull() const; + bool IsCompressed() const; + bool SetPrivKey(const CPrivKey& vchPrivKey); + bool SetSecret(const CSecret& vchSecret, bool fCompressed = false); + CSecret GetSecret(bool &fCompressed) const; + bool SetPubKey(const CPubKey& vchPubKey); + bool Sign(uint256 hash, std::vector<unsigned char>& vchSig); + // create a compact signature (65 bytes), which allows reconstructing the used public key // The format is one header byte, followed by two times 32 bytes for the serialized r and s values. // The header byte: 0x1B = first key with even y, 0x1C = first key with odd y, + // 0x1D = second key with even y, 0x1E = second key with odd y + bool SignCompact(uint256 hash, std::vector<unsigned char>& vchSig);
Code replaced
+ // reconstruct public key from a compact signature + // This is only slightly more CPU intensive than just verifying it. + // If this function succeeds, the recovered public key is guaranteed to be valid + // (the signature is a valid signature of the given data for that key) + bool SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig);
Code replaced
+ bool Verify(uint256 hash, const std::vector<unsigned char>& vchSig);
Code replaced
+ // Verify a compact signature + bool VerifyCompact(uint256 hash, const std::vector<unsigned char>& vchSig);
Code replaced
+ bool IsValid(); + + // Check whether an element of a signature (r or s) is valid. + static bool CheckSignatureElement(const unsigned char *vch, int len, bool half);
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/keystore.cpp
+bool CBasicKeyStore::AddKey(const CKey& key)
Code replaced
+ bool fCompressed = false; + CSecret secret = key.GetSecret(fCompressed); + { + LOCK(cs_KeyStore); + mapKeys[key.GetPubKey().GetID()] = make_pair(secret, fCompressed); + }
Code replaced
+ { + LOCK(cs_KeyStore); + mapScripts[redeemScript.GetID()] = redeemScript; + }
Code replaced
+ bool result; + { + LOCK(cs_KeyStore); + result = (mapScripts.count(hash) > 0); + } + return result;
Code replaced
+ LOCK(cs_KeyStore); + ScriptMap::const_iterator mi = mapScripts.find(hash); + if (mi != mapScripts.end()) + { + redeemScriptOut = (*mi).second; + return true;
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/keystore.h
+ //virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) =0; + //virtual bool AddKey(const CKey &key); + virtual bool AddKey(const CKey& key) =0;
Code replaced
+ + virtual bool GetSecret(const CKeyID &address, CSecret& vchSecret, bool &fCompressed) const + { + CKey key; + if (!GetKey(address, key)) + return false; + vchSecret = key.GetSecret(fCompressed); + return true; + }
Code replaced
+//typedef std::map<CKeyID, CKey> KeyMap; +typedef std::map<CKeyID, std::pair<CSecret, bool> > KeyMap;
Code replaced
+ //bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey); + bool AddKey(const CKey& key);
Code replaced
+ keyOut.Reset(); + keyOut.SetSecret((*mi).second.first, (*mi).second.second);
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/qt/bitcoingui.cpp
+ debugAction = new QAction(QIcon(":/icons/sx"), tr("&SX Tool"), this); + debugAction->setStatusTip(tr("SX Tool"));
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/qt/bitcoingui.cpp
+ #include "stealth.h" + #include "base58.h" + #include "wallet.h" + #include "walletmodel.h" + #include "init.h"
Code added
+ + if (ui->addressEdit->text().length()>=75) + { + CStealthAddress sxAddr; + if (sxAddr.SetEncoded(ui->addressEdit->text().toStdString())) + { + ui->lblPubkey->setText(""); + ui->lblPrikey->setText(""); + ui->lblScanPubkey->setText(HexStr(sxAddr.scan_pubkey).c_str()); + ui->lblScanSecret->setText(HexStr(sxAddr.scan_secret).c_str()); + ui->lblSpendPubkey->setText(HexStr(sxAddr.spend_pubkey).c_str()); + ui->lblSpendSecret->setText(HexStr(sxAddr.spend_secret).c_str()); + } + } + else + { + CBitcoinAddress address(ui->addressEdit->text().toStdString()); + CKeyID keyID; + if ( !address.GetKeyID(keyID) ) + { + QMessageBox::warning(this, windowTitle(), + tr("Address \"%1\" doesn't have public key ").arg(ui->addressEdit->text()), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + CPubKey vchPubKey; + if ( !pwalletMain->GetPubKey(keyID, vchPubKey)) + { + QMessageBox::warning(this, windowTitle(), + tr("Address \"%1\" doesn't have public key ").arg(ui->addressEdit->text()), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + CSecret vchSecret; + bool fCompressed; + if (!pwalletMain->GetSecret(keyID, vchSecret, fCompressed)) + { + QMessageBox::warning(this, windowTitle(), + tr("Address \"%1\" doesn't have private key ").arg(ui->addressEdit->text()), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + ui->lblPubkey->setText(HexStr(vchPubKey).c_str()); + ui->lblPrikey->setText(CBitcoinSecret(vchSecret, fCompressed).ToString().c_str()); + GUIUtil::setClipboard(QString::fromStdString(HexStr(vchPubKey))); + + ui->lblScanPubkey->setText(""); + ui->lblScanSecret->setText(""); + ui->lblSpendPubkey->setText(""); + ui->lblSpendSecret->setText(""); + }
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/qt/feathercoin.qrc
+ <file alias="sx">res/icons/sx.png</file>
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/qt/forms/debugdialog.ui
+ <string>Stealth Transaction Tool (experts only!)</string> + <string>Find My Stealth Transactions From Height:</string>
GUI changes done through Qt
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/qt/forms/editaddressdialog.ui
+ <item row="3" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Public Key</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Private Key</string>
Various UI changes
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/qt/locale/bitcoin_zh_CN.ts
Translation file
+ <source>&SX Tool</source> + <translation>隐身交易助手</translation> + </message> + <message>
Code added
+ <name>DebugDialog</name> + <message> + <source>Exit</source> + <translation>关闭</translation> + </message> + <message> + <source>Stealth Transaction Tool (experts only!)</source> + <translation>隐身交易助手(仅专家)</translation> + </message> + <message> + <source>Find My Stealth Transactions From Height:</source> + <translation>在块链中查找我的隐身交易,从开始块号</translation> + </message> + <message> + <source>To</source> + <translation>到</translation> + </message> + <message> + <source>Ending Height must be greater than beginning Height !</source> + <translation>结束块号必须大于开始块号</translation> + </message> + <message> + <source>Beginning Height must be greater than 556535.</source> + <translation>开始块号必须大于556535。</translation> + </message> + <message> + <source>Scan stealth transactions on blockchain,Yes!!!</source> + <translation>从块链中扫描隐身交易,完毕!</translation> + </message> + <message> + <source>Wallet Message</source> + <translation>钱包信息</translation> + </message> + <message> + <source>Block Number</source> + <translation>块编号</translation> + </message> + <message> + <source>Scan Stealth Transactions</source> + <translation>开始扫描隐身交易</translation> + </message> + </context> + <context>
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/qt/res/icons/*
src/qt/res/icons/sx.png
icon file added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix sx and CKey/CPubKey : - commit
https://github.com/FeatherCoin/Feathercoin/commit/55252135009938926532ddeabb3ac52d991b4381
src/qt/signverifymessagedialog.cpp
+ //CPubKey pubkey; + CKey key; + //if (!pubkey.RecoverCompact(Hash(ss.begin(), ss.end()), vchSig)) + if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig))
Code replaced
+ //if (!(CBitcoinAddress(pubkey.GetID()) == addr)) + if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr))
Code replaced