aboutsummaryrefslogtreecommitdiff
path: root/src/device_trezor/device_trezor_base.cpp
diff options
context:
space:
mode:
authorDusan Klinec <dusan.klinec@gmail.com>2018-11-12 00:07:25 +0100
committerDusan Klinec <dusan.klinec@gmail.com>2018-12-04 18:38:16 +0100
commitd21dad70ddda771bf33a19f9a53c48cc91d8464f (patch)
tree381a34cb060174556bbd156b94d014cc87524889 /src/device_trezor/device_trezor_base.cpp
parentdevice/trezor: passphrase entry on host (diff)
downloadmonero-d21dad70ddda771bf33a19f9a53c48cc91d8464f.tar.xz
device: enable to use multiple independent device wallets
- adds a new option `--hw-device-deriv-path` to the simple wallet. Enables to specify wallet derivation path / wallet code (path avoided so it can be misinterpreted as a file path). - devices can use different derivation mechanisms. Trezor uses standard SLIP-10 mechanism with fixed SLIP-44 prefix for Monero - Trezor: when empty, the default derivation mechanism is used with 44'/128'/0'. When entered the derivation path is 44'/128'/PATH. - Trezor: the path is always taken as elements are hardened (1<<31 bit turned on)
Diffstat (limited to 'src/device_trezor/device_trezor_base.cpp')
-rw-r--r--src/device_trezor/device_trezor_base.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/device_trezor/device_trezor_base.cpp b/src/device_trezor/device_trezor_base.cpp
index dcfc9cb67..fddc6082c 100644
--- a/src/device_trezor/device_trezor_base.cpp
+++ b/src/device_trezor/device_trezor_base.cpp
@@ -28,6 +28,9 @@
//
#include "device_trezor_base.hpp"
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/regex.hpp>
namespace hw {
namespace trezor {
@@ -36,8 +39,9 @@ namespace trezor {
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "device.trezor"
+#define TREZOR_BIP44_HARDENED_ZERO 0x80000000
- const uint32_t device_trezor_base::DEFAULT_BIP44_PATH[] = {0x8000002c, 0x80000080, 0x80000000};
+ const uint32_t device_trezor_base::DEFAULT_BIP44_PATH[] = {0x8000002c, 0x80000080};
device_trezor_base::device_trezor_base(): m_callback(nullptr) {
@@ -252,6 +256,39 @@ namespace trezor {
}
}
+ void device_trezor_base::ensure_derivation_path() noexcept {
+ if (m_wallet_deriv_path.empty()){
+ m_wallet_deriv_path.push_back(TREZOR_BIP44_HARDENED_ZERO); // default 0'
+ }
+ }
+
+ void device_trezor_base::set_derivation_path(const std::string &deriv_path){
+ this->m_wallet_deriv_path.clear();
+
+ if (deriv_path.empty() || deriv_path == "-"){
+ ensure_derivation_path();
+ return;
+ }
+
+ CHECK_AND_ASSERT_THROW_MES(deriv_path.size() <= 255, "Derivation path is too long");
+
+ std::vector<std::string> fields;
+ boost::split(fields, deriv_path, boost::is_any_of("/"));
+ CHECK_AND_ASSERT_THROW_MES(fields.size() <= 10, "Derivation path is too long");
+
+ boost::regex rgx("^([0-9]+)'?$");
+ boost::cmatch match;
+
+ this->m_wallet_deriv_path.reserve(fields.size());
+ for(const std::string & cur : fields){
+ const bool ok = boost::regex_match(cur.c_str(), match, rgx);
+ CHECK_AND_ASSERT_THROW_MES(ok, "Invalid wallet code: " << deriv_path << ". Invalid path element: " << cur);
+ CHECK_AND_ASSERT_THROW_MES(match[0].length() > 0, "Invalid wallet code: " << deriv_path << ". Invalid path element: " << cur);
+
+ const unsigned long cidx = std::stoul(match[0].str()) | TREZOR_BIP44_HARDENED_ZERO;
+ this->m_wallet_deriv_path.push_back((unsigned int)cidx);
+ }
+ }
/* ======================================================================= */
/* TREZOR PROTOCOL */