From 74a107f9f403c2327bda92cd04ad1b6454d7974a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 16 Jul 2014 12:26:24 -0700 Subject: [PATCH] initial rev of SignedWalletTransaction that creates a message --- interface/src/Application.cpp | 7 +++ interface/src/SignedWalletTransaction.cpp | 51 +++++++++++++++++++ interface/src/SignedWalletTransaction.h | 31 +++++++++++ .../networking}/src/WalletTransaction.cpp | 0 .../networking}/src/WalletTransaction.h | 2 +- 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 interface/src/SignedWalletTransaction.cpp create mode 100644 interface/src/SignedWalletTransaction.h rename {domain-server => libraries/networking}/src/WalletTransaction.cpp (100%) rename {domain-server => libraries/networking}/src/WalletTransaction.h (99%) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bc6db5d7b6..c5a51fda86 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -74,6 +74,7 @@ #include "devices/OculusManager.h" #include "devices/TV3DManager.h" #include "renderer/ProgramObject.h" +#include "SignedWalletTransaction.h" #include "scripting/AccountScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" @@ -405,6 +406,12 @@ 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 new file mode 100644 index 0000000000..e3a8cbaa5c --- /dev/null +++ b/interface/src/SignedWalletTransaction.cpp @@ -0,0 +1,51 @@ +// +// SignedWalletTransaction.cpp +// interface/src +// +// Created by Stephen Birarda on 2014-07-11. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include + +#include "SignedWalletTransaction.h" + +SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, + qint64 messageTimestamp, qint64 expiryDelta) : + WalletTransaction(destinationUUID, amount), + _messageTimestamp(messageTimestamp), + _expiryDelta(expiryDelta) +{ + +} + +QByteArray SignedWalletTransaction::hexMessage() { + // build the message using the components of this transaction + + // UUID, source UUID, destination UUID, message timestamp, expiry delta, amount + QByteArray messageBinary; + + messageBinary.append(_uuid.toRfc4122()); + + 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(_destinationUUID.toRfc4122()); + + messageBinary.append(reinterpret_cast(&_amount), sizeof(_amount)); + + return messageBinary.toHex(); +} + +QByteArray SignedWalletTransaction::messageDigest() { + return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256); +} \ No newline at end of file diff --git a/interface/src/SignedWalletTransaction.h b/interface/src/SignedWalletTransaction.h new file mode 100644 index 0000000000..3b13f73335 --- /dev/null +++ b/interface/src/SignedWalletTransaction.h @@ -0,0 +1,31 @@ +// +// SignedWalletTransaction.h +// interfac/src +// +// Created by Stephen Birarda on 2014-07-11. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_SignedWalletTransaction_h +#define hifi_SignedWalletTransaction_h + +#include + +class SignedWalletTransaction : public WalletTransaction { + Q_OBJECT +public: + SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, qint64 messageTimestamp, qint64 expiryDelta); + + QByteArray hexMessage(); + QByteArray messageDigest(); + QByteArray signedMessageDigest(); + +private: + qint64 _messageTimestamp; + qint64 _expiryDelta; +}; + +#endif // hifi_SignedWalletTransaction_h \ No newline at end of file diff --git a/domain-server/src/WalletTransaction.cpp b/libraries/networking/src/WalletTransaction.cpp similarity index 100% rename from domain-server/src/WalletTransaction.cpp rename to libraries/networking/src/WalletTransaction.cpp diff --git a/domain-server/src/WalletTransaction.h b/libraries/networking/src/WalletTransaction.h similarity index 99% rename from domain-server/src/WalletTransaction.h rename to libraries/networking/src/WalletTransaction.h index 5e05f9f549..7728eb0f1b 100644 --- a/domain-server/src/WalletTransaction.h +++ b/libraries/networking/src/WalletTransaction.h @@ -36,7 +36,7 @@ public: QJsonDocument postJson(); QJsonObject toJson(); void loadFromJson(const QJsonObject& jsonObject); -private: +protected: QUuid _uuid; QUuid _destinationUUID; qint64 _amount;