Skip to content

Commit

Permalink
#624: initialize wallet node with owner key provided by HW wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
nesbox committed May 30, 2019
1 parent 76b564f commit e228ba1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
14 changes: 13 additions & 1 deletion node/node_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ void NodeClient::setKdf(beam::Key::IKdf::Ptr kdf)
m_pKdf = kdf;
}

void NodeClient::setOwnerKey(beam::Key::IPKdf::Ptr key)
{
m_ownerKey = key;
}

void NodeClient::startNode()
{
m_shouldStartNode = true;
Expand Down Expand Up @@ -164,7 +169,14 @@ void NodeClient::runLocalNode()
node.m_Cfg.m_MiningThreads = 0;
node.m_Cfg.m_VerificationThreads = kVerificationThreadsMaxAvailable;

node.m_Keys.SetSingleKey(m_pKdf);
if(m_ownerKey)
{
node.m_Keys.m_pOwner = m_ownerKey;
}
else
{
node.m_Keys.SetSingleKey(m_pKdf);
}

node.m_Cfg.m_Horizon.m_Branching = Rules::get().Macroblock.MaxRollback / 4; // inferior branches would be pruned when height difference is this.
node.m_Cfg.m_Horizon.m_SchwarzschildHi = 0; // would be adjusted anyway
Expand Down
2 changes: 2 additions & 0 deletions node/node_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class NodeClient
~NodeClient();

void setKdf(beam::Key::IKdf::Ptr);
void setOwnerKey(beam::Key::IPKdf::Ptr);
void startNode();
void stopNode();

Expand All @@ -68,5 +69,6 @@ class NodeClient
std::atomic<bool> m_isRunning;
std::condition_variable m_waiting;
beam::Key::IKdf::Ptr m_pKdf;
beam::Key::IPKdf::Ptr m_ownerKey;
};
}
4 changes: 4 additions & 0 deletions ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ endif()
add_executable(${TARGET_NAME} ${SYSTEM_TYPE} ${UI_SRC} ${QT_RESOURCES} beam.rc ${MACOSX_BUNDLE_ICON_FILE})
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME})

if(BEAM_HW_WALLET)
target_compile_definitions(${TARGET_NAME} PRIVATE BEAM_HW_WALLET)
endif()

configure_file("${PROJECT_SOURCE_DIR}/version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/version.h")

add_dependencies(${TARGET_NAME} wallet mnemonic qrcode cli)
Expand Down
31 changes: 31 additions & 0 deletions ui/model/app_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <QApplication>
#include <QTranslator>

#if defined(BEAM_HW_WALLET)
#include "wallet/hw_wallet.h"
#endif

using namespace beam;
using namespace beam::wallet;
using namespace ECC;
Expand Down Expand Up @@ -225,7 +229,34 @@ void AppModel::onLocaleChanged()

void AppModel::start()
{
#if defined(BEAM_HW_WALLET)
{
HWWallet hw;
auto key = hw.getOwnerKeySync();

LOG_INFO() << "Owner key" << key;

// TODO: password encryption will be removed
std::string pass = "1";
KeyString ks;
ks.SetPassword(Blob(pass.data(), static_cast<uint32_t>(pass.size())));

ks.m_sRes = key;

std::shared_ptr<ECC::HKdfPub> pKdf = std::make_shared<ECC::HKdfPub>();

if (ks.Import(*pKdf))
{
m_nodeModel.setOwnerKey(pKdf);
}
else
{
LOG_ERROR() << "veiw key import failed";
}
}
#else
m_nodeModel.setKdf(m_db->get_MasterKdf());
#endif

std::string nodeAddrStr;

Expand Down
5 changes: 5 additions & 0 deletions ui/model/node_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void NodeModel::setKdf(beam::Key::IKdf::Ptr kdf)
m_nodeClient.setKdf(kdf);
}

void NodeModel::setOwnerKey(beam::Key::IPKdf::Ptr key)
{
m_nodeClient.setOwnerKey(key);
}

void NodeModel::startNode()
{
m_nodeClient.startNode();
Expand Down
1 change: 1 addition & 0 deletions ui/model/node_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class NodeModel
NodeModel();

void setKdf(beam::Key::IKdf::Ptr);
void setOwnerKey(beam::Key::IPKdf::Ptr);
void startNode();
void stopNode();

Expand Down

0 comments on commit e228ba1

Please sign in to comment.