diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c5a51fda86..d666b91a56 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -406,12 +406,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : MIDIManager& midiManagerInstance = MIDIManager::getInstance(); midiManagerInstance.openDefaultPort(); #endif - - - QUuid destinationWallet = QUuid::createUuid(); - - SignedWalletTransaction testTransaction(destinationWallet, 1000, QDateTime::currentDateTime().toTime_t(), 3600); - qDebug() << "Message digest is" << testTransaction.hexMessage(); } Application::~Application() { diff --git a/interface/src/SignedWalletTransaction.cpp b/interface/src/SignedWalletTransaction.cpp index e3a8cbaa5c..4d81835e3c 100644 --- a/interface/src/SignedWalletTransaction.cpp +++ b/interface/src/SignedWalletTransaction.cpp @@ -13,6 +13,12 @@ #include #include +#include +#include +#include + +#include + #include "SignedWalletTransaction.h" SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, @@ -35,9 +41,7 @@ QByteArray SignedWalletTransaction::hexMessage() { messageBinary.append(reinterpret_cast(&_messageTimestamp), sizeof(_messageTimestamp)); messageBinary.append(reinterpret_cast(&_expiryDelta), sizeof(_expiryDelta)); - QUuid sourceUUID = QUuid::createUuid(); - qDebug() << "The faked source UUID is" << sourceUUID; - messageBinary.append(sourceUUID.toRfc4122()); + messageBinary.append(AccountManager::getInstance().getAccountInfo().getWalletID().toRfc4122()); messageBinary.append(_destinationUUID.toRfc4122()); @@ -47,5 +51,29 @@ QByteArray SignedWalletTransaction::hexMessage() { } QByteArray SignedWalletTransaction::messageDigest() { - return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256); + return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256).toHex(); +} + +QByteArray SignedWalletTransaction::signedMessageDigest() { + // read the private key from file into memory + QFile privateKeyFile("/Users/birarda/Desktop/generated-private.pem"); + privateKeyFile.open(QIODevice::ReadOnly); + QByteArray privateKeyData = privateKeyFile.readAll(); + + BIO* privateKeyBIO = NULL; + RSA* rsaPrivateKey = NULL; + + privateKeyBIO = BIO_new_mem_buf(privateKeyData.data(), privateKeyData.size()); + PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL); + + QByteArray digestToEncrypt = messageDigest(); + qDebug() << "encrypting the following digest" << digestToEncrypt; + QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0); + + int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(), + reinterpret_cast(digestToEncrypt.constData()), + reinterpret_cast(encryptedDigest.data()), + rsaPrivateKey, RSA_PKCS1_PADDING); + + return encryptedDigest; } \ No newline at end of file diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp index 507c085d26..376aa274c7 100644 --- a/libraries/networking/src/DataServerAccountInfo.cpp +++ b/libraries/networking/src/DataServerAccountInfo.cpp @@ -18,6 +18,7 @@ DataServerAccountInfo::DataServerAccountInfo() : _username(), _xmppPassword(), _discourseApiKey(), + _walletID(), _balance(0), _hasBalance(false) { @@ -29,6 +30,7 @@ DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherI _username = otherInfo._username; _xmppPassword = otherInfo._xmppPassword; _discourseApiKey = otherInfo._discourseApiKey; + _walletID = otherInfo._walletID; _balance = otherInfo._balance; _hasBalance = otherInfo._hasBalance; } @@ -46,6 +48,7 @@ void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) { swap(_username, otherInfo._username); swap(_xmppPassword, otherInfo._xmppPassword); swap(_discourseApiKey, otherInfo._discourseApiKey); + swap(_walletID, otherInfo._walletID); swap(_balance, otherInfo._balance); swap(_hasBalance, otherInfo._hasBalance); } @@ -74,6 +77,12 @@ void DataServerAccountInfo::setDiscourseApiKey(const QString& discourseApiKey) { } } +void DataServerAccountInfo::setWalletID(const QUuid& walletID) { + if (_walletID != walletID) { + _walletID = walletID; + } +} + void DataServerAccountInfo::setBalance(qint64 balance) { if (!_hasBalance || _balance != balance) { _balance = balance; @@ -99,14 +108,17 @@ void DataServerAccountInfo::setProfileInfoFromJSON(const QJsonObject& jsonObject setUsername(user["username"].toString()); setXMPPPassword(user["xmpp_password"].toString()); setDiscourseApiKey(user["discourse_api_key"].toString()); + setWalletID(QUuid(user["wallet_id"].toString())); + + qDebug() << "Wallet is" << _walletID; } QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info) { - out << info._accessToken << info._username << info._xmppPassword << info._discourseApiKey; + out << info._accessToken << info._username << info._xmppPassword << info._discourseApiKey << info._walletID; return out; } QDataStream& operator>>(QDataStream &in, DataServerAccountInfo& info) { - in >> info._accessToken >> info._username >> info._xmppPassword >> info._discourseApiKey; + in >> info._accessToken >> info._username >> info._xmppPassword >> info._discourseApiKey >> info._walletID; return in; } diff --git a/libraries/networking/src/DataServerAccountInfo.h b/libraries/networking/src/DataServerAccountInfo.h index 27b776e3ff..dd9540718e 100644 --- a/libraries/networking/src/DataServerAccountInfo.h +++ b/libraries/networking/src/DataServerAccountInfo.h @@ -13,6 +13,7 @@ #define hifi_DataServerAccountInfo_h #include +#include #include "OAuthAccessToken.h" @@ -36,6 +37,9 @@ public: const QString& getDiscourseApiKey() const { return _discourseApiKey; } void setDiscourseApiKey(const QString& discourseApiKey); + + const QUuid& getWalletID() const { return _walletID; } + void setWalletID(const QUuid& walletID); qint64 getBalance() const { return _balance; } float getBalanceInSatoshis() const { return _balance / SATOSHIS_PER_CREDIT; } @@ -59,6 +63,7 @@ private: QString _username; QString _xmppPassword; QString _discourseApiKey; + QUuid _walletID; qint64 _balance; bool _hasBalance; };