diff --git a/src/daemon/monero_daemon.cpp b/src/daemon/monero_daemon.cpp index 55fb478..38feaaa 100644 --- a/src/daemon/monero_daemon.cpp +++ b/src/daemon/monero_daemon.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/daemon/monero_daemon.h b/src/daemon/monero_daemon.h index e7034e8..7dbcb4a 100644 --- a/src/daemon/monero_daemon.h +++ b/src/daemon/monero_daemon.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/daemon/monero_daemon_model.cpp b/src/daemon/monero_daemon_model.cpp index 0a5861d..a1eff37 100644 --- a/src/daemon/monero_daemon_model.cpp +++ b/src/daemon/monero_daemon_model.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/daemon/monero_daemon_model.h b/src/daemon/monero_daemon_model.h index f1b9f96..8c890cd 100644 --- a/src/daemon/monero_daemon_model.h +++ b/src/daemon/monero_daemon_model.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/utils/gen_utils.cpp b/src/utils/gen_utils.cpp index 6e5aba1..d85c72b 100644 --- a/src/utils/gen_utils.cpp +++ b/src/utils/gen_utils.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/utils/gen_utils.h b/src/utils/gen_utils.h index d91305f..07499c4 100644 --- a/src/utils/gen_utils.h +++ b/src/utils/gen_utils.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/utils/monero_utils.cpp b/src/utils/monero_utils.cpp index d98eba7..f31e21f 100644 --- a/src/utils/monero_utils.cpp +++ b/src/utils/monero_utils.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -54,6 +54,8 @@ #include "rpc/core_rpc_server_commands_defs.h" #include "storages/portable_storage_template_helper.h" #include "cryptonote_basic/cryptonote_format_utils.h" +#include "mnemonics/electrum-words.h" +#include "mnemonics/english.h" #include "string_tools.h" using namespace cryptonote; @@ -230,8 +232,19 @@ void monero_utils::deserialize(const std::string& json, boost::property_tree::pt // ---------------------------------------------------------------------------- -// TODO: this is unused +bool monero_utils::is_valid_language(const std::string& language) { + std::vector languages; + crypto::ElectrumWords::get_language_list(languages, false); + std::vector::iterator it = std::find(languages.begin(), languages.end(), language); + if (it == languages.end()) { + crypto::ElectrumWords::get_language_list(languages, true); + it = std::find(languages.begin(), languages.end(), language); + } + if (it == languages.end()) return false; + return true; +} +// TODO: this is unused std::shared_ptr monero_utils::cn_block_to_block(const cryptonote::block& cn_block) { cryptonote::block temp = cn_block; std::cout << cryptonote::obj_to_json_str(temp) << std::endl; diff --git a/src/utils/monero_utils.h b/src/utils/monero_utils.h index 5658a5a..d52f737 100644 --- a/src/utils/monero_utils.h +++ b/src/utils/monero_utils.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -119,7 +119,13 @@ namespace monero_utils // -------------------------------------------------------------------------- - void deserialize(const std::string& json, boost::property_tree::ptree& root); + /** + * Indicates if the given language is valid. + * + * @param language is the language to validate + * @return true if the language is valid, false otherwise + */ + bool is_valid_language(const std::string& language); /** * Convert a Monero Core cryptonote::block to a block in this library's native model. diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index 682dd2a..85f36c4 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index d3c4222..46ebe5e 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -853,6 +853,7 @@ namespace monero { monero_wallet_core* monero_wallet_core::create_wallet_random(const std::string& path, const std::string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const std::string& language, std::unique_ptr http_client_factory) { MTRACE("create_wallet_random(...)"); + if (!monero_utils::is_valid_language(language)) throw std::runtime_error("Unknown language: " + language); monero_wallet_core* wallet = new monero_wallet_core(); if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); else wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); @@ -936,6 +937,9 @@ namespace monero { if (info.address.m_view_public_key != pkey) throw std::runtime_error("view key does not match address"); } + // validate language + if (!monero_utils::is_valid_language(language)) throw std::runtime_error("Unknown language: " + language); + // initialize wallet if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); else wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, std::move(http_client_factory))); diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index ce9f6a1..41477ec 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/wallet/monero_wallet_keys.cpp b/src/wallet/monero_wallet_keys.cpp index 3708175..2f76e68 100644 --- a/src/wallet/monero_wallet_keys.cpp +++ b/src/wallet/monero_wallet_keys.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -75,6 +75,9 @@ namespace monero { monero_wallet_keys* monero_wallet_keys::create_wallet_random(const monero_network_type network_type, const std::string& language) { + // validate language + if (!monero_utils::is_valid_language(language)) throw std::runtime_error("Unknown language: " + language); + // initialize random wallet account monero_wallet_keys* wallet = new monero_wallet_keys(); crypto::secret_key spend_key_sk = wallet->m_account.generate(); @@ -166,6 +169,9 @@ namespace monero { if (info.address.m_view_public_key != pkey) throw std::runtime_error("view key does not match address"); } + // validate language + if (!monero_utils::is_valid_language(language)) throw std::runtime_error("Unknown language: " + language); + // initialize wallet account monero_wallet_keys* wallet = new monero_wallet_keys(); if (has_spend_key && has_view_key) { @@ -194,7 +200,7 @@ namespace monero { std::vector monero_wallet_keys::get_mnemonic_languages() { std::vector languages; - crypto::ElectrumWords::get_language_list(languages, true); + crypto::ElectrumWords::get_language_list(languages, true); // TODO: support getting names in language return languages; } diff --git a/src/wallet/monero_wallet_keys.h b/src/wallet/monero_wallet_keys.h index 8094d8d..52d3167 100644 --- a/src/wallet/monero_wallet_keys.h +++ b/src/wallet/monero_wallet_keys.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -77,7 +77,7 @@ namespace monero { * @param network_type is the wallet's network type (default = monero_network_type.MAINNET) * @param language is the wallet and mnemonic's language (default = "English") */ - static monero_wallet_keys* create_wallet_random(const monero_network_type network_type, const std::string& language); + static monero_wallet_keys* create_wallet_random(const monero_network_type network_type, const std::string& language = "English"); /** * Create a wallet from an existing mnemonic phrase. diff --git a/src/wallet/monero_wallet_model.cpp b/src/wallet/monero_wallet_model.cpp index 64bf422..0ea82c5 100644 --- a/src/wallet/monero_wallet_model.cpp +++ b/src/wallet/monero_wallet_model.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/wallet/monero_wallet_model.h b/src/wallet/monero_wallet_model.h index 0b2af44..f8c43e8 100644 --- a/src/wallet/monero_wallet_model.h +++ b/src/wallet/monero_wallet_model.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2019 woodser + * Copyright (c) woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal