mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-18 07:41:32 +02:00
define keys wallet static creation methods
This commit is contained in:
@@ -71,212 +71,118 @@ namespace monero {
|
||||
|
||||
// ---------------------------- WALLET MANAGEMENT ---------------------------
|
||||
|
||||
monero_wallet_key* monero_wallet_key::create_wallet_random(const string& path, const string& password) {
|
||||
MTRACE("create_wallet_random(path, password)");
|
||||
throw runtime_error("Not implemented");
|
||||
monero_wallet_keys* monero_wallet_keys::create_wallet_random() {
|
||||
cout << "monero_wallet_keys::create_wallet_random()" << endl;
|
||||
throw runtime_error("create_wallet_random() not implemented");
|
||||
}
|
||||
|
||||
// TODO: ensure that wallet does not already exist
|
||||
monero_wallet_key* monero_wallet_key::create_wallet_random(const string& path, const string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const string& language) {
|
||||
MTRACE("create_wallet_random(path, password, network_type, daemon_connection, language)");
|
||||
monero_wallet_key* wallet = new monero_wallet_key();
|
||||
wallet->m_w2 = unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true));
|
||||
wallet->set_daemon_connection(daemon_connection);
|
||||
wallet->m_w2->set_seed_language(language);
|
||||
crypto::secret_key secret_key;
|
||||
wallet->m_w2->generate(path, password, secret_key, false, false);
|
||||
wallet->init_common();
|
||||
if (wallet->is_connected()) wallet->m_w2->set_refresh_from_block_height(wallet->get_daemon_height());
|
||||
return wallet;
|
||||
monero_wallet_keys* monero_wallet_keys::create_wallet_random(const monero_network_type network_type, const string& language) {
|
||||
cout << "monero_wallet_keys::create_wallet_random(...)" << endl;
|
||||
throw runtime_error("create_wallet_random(...) not implemented");
|
||||
}
|
||||
|
||||
monero_wallet_key* monero_wallet_key::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic) {
|
||||
MTRACE("create_wallet_from_mnemonic(path, password, network_type, mnemonic)");
|
||||
throw runtime_error("Not implemented");
|
||||
monero_wallet_keys* monero_wallet_keys::create_wallet_from_mnemonic(const monero_network_type network_type, const string& mnemonic) {
|
||||
cout << "monero_wallet_keys::create_wallet_from_mnemonic()" << endl;
|
||||
throw runtime_error("create_wallet_from_mnemonic() not implemented");
|
||||
}
|
||||
|
||||
monero_wallet_key* monero_wallet_key::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height) {
|
||||
MTRACE("create_wallet_from_mnemonic(path, password, mnemonic, network_type, daemon_connection, restore_height)");
|
||||
monero_wallet_key* wallet = new monero_wallet_key();
|
||||
|
||||
// validate mnemonic and get recovery key and language
|
||||
crypto::secret_key recoveryKey;
|
||||
std::string language;
|
||||
bool is_valid = crypto::ElectrumWords::words_to_bytes(mnemonic, recoveryKey, language);
|
||||
if (!is_valid) throw runtime_error("Invalid mnemonic");
|
||||
if (language == crypto::ElectrumWords::old_language_name) language = Language::English().get_language_name();
|
||||
|
||||
// initialize wallet
|
||||
wallet->m_w2 = unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true));
|
||||
wallet->set_daemon_connection(daemon_connection);
|
||||
wallet->m_w2->set_seed_language(language);
|
||||
wallet->m_w2->generate(path, password, recoveryKey, true, false);
|
||||
wallet->m_w2->set_refresh_from_block_height(restore_height);
|
||||
wallet->init_common();
|
||||
return wallet;
|
||||
monero_wallet_keys* monero_wallet_keys::create_wallet_from_keys(const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key) {
|
||||
cout << "monero_wallet_keys::create_wallet_from_keys()" << endl;
|
||||
throw runtime_error("create_wallet_from_keys() not implemented");
|
||||
}
|
||||
|
||||
monero_wallet_key* monero_wallet_key::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key) {
|
||||
MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type)");
|
||||
throw runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
monero_wallet_key* monero_wallet_key::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height) {
|
||||
MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type, daemon_connection, restore_height)");
|
||||
throw runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
monero_wallet_key* monero_wallet_key::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language) {
|
||||
MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type, daemon_connection, restore_height, language)");
|
||||
monero_wallet_key* wallet = new monero_wallet_key();
|
||||
|
||||
// validate and parse address
|
||||
cryptonote::address_parse_info info;
|
||||
if (!get_account_address_from_str(info, static_cast<cryptonote::network_type>(network_type), address)) throw runtime_error("failed to parse address");
|
||||
|
||||
// validate and parse optional private spend key
|
||||
crypto::secret_key spend_key_sk;
|
||||
bool has_spend_key = false;
|
||||
if (!spend_key.empty()) {
|
||||
cryptonote::blobdata spend_key_data;
|
||||
if (!epee::string_tools::parse_hexstr_to_binbuff(spend_key, spend_key_data) || spend_key_data.size() != sizeof(crypto::secret_key)) {
|
||||
throw runtime_error("failed to parse secret spend key");
|
||||
}
|
||||
has_spend_key = true;
|
||||
spend_key_sk = *reinterpret_cast<const crypto::secret_key*>(spend_key_data.data());
|
||||
}
|
||||
|
||||
// validate and parse private view key
|
||||
bool has_view_key = true;
|
||||
crypto::secret_key view_key_sk;
|
||||
if (view_key.empty()) {
|
||||
if (has_spend_key) has_view_key = false;
|
||||
else throw runtime_error("Neither view key nor spend key supplied, cancelled");
|
||||
}
|
||||
if (has_view_key) {
|
||||
cryptonote::blobdata view_key_data;
|
||||
if (!epee::string_tools::parse_hexstr_to_binbuff(view_key, view_key_data) || view_key_data.size() != sizeof(crypto::secret_key)) {
|
||||
throw runtime_error("failed to parse secret view key");
|
||||
}
|
||||
view_key_sk = *reinterpret_cast<const crypto::secret_key*>(view_key_data.data());
|
||||
}
|
||||
|
||||
// check the spend and view keys match the given address
|
||||
crypto::public_key pkey;
|
||||
if (has_spend_key) {
|
||||
if (!crypto::secret_key_to_public_key(spend_key_sk, pkey)) throw runtime_error("failed to verify secret spend key");
|
||||
if (info.address.m_spend_public_key != pkey) throw runtime_error("spend key does not match address");
|
||||
}
|
||||
if (has_view_key) {
|
||||
if (!crypto::secret_key_to_public_key(view_key_sk, pkey)) throw runtime_error("failed to verify secret view key");
|
||||
if (info.address.m_view_public_key != pkey) throw runtime_error("view key does not match address");
|
||||
}
|
||||
|
||||
// initialize wallet
|
||||
wallet->m_w2 = unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true));
|
||||
if (has_spend_key && has_view_key) wallet->m_w2->generate(path, password, info.address, spend_key_sk, view_key_sk);
|
||||
if (!has_spend_key && has_view_key) wallet->m_w2->generate(path, password, info.address, view_key_sk);
|
||||
if (has_spend_key && !has_view_key) wallet->m_w2->generate(path, password, spend_key_sk, true, false);
|
||||
wallet->set_daemon_connection(daemon_connection);
|
||||
wallet->m_w2->set_refresh_from_block_height(restore_height);
|
||||
wallet->m_w2->set_seed_language(language);
|
||||
wallet->init_common();
|
||||
return wallet;
|
||||
}
|
||||
|
||||
monero_wallet_key::~monero_wallet_key() {
|
||||
MTRACE("~monero_wallet_key()");
|
||||
close(false);
|
||||
monero_wallet_keys* monero_wallet_keys::create_wallet_from_keys(const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const string& language) {
|
||||
cout << "monero_wallet_keys::create_wallet_from_keys(...)" << endl;
|
||||
throw runtime_error("create_wallet_from_keys() not implemented");
|
||||
}
|
||||
|
||||
// ----------------------------- WALLET METHODS -----------------------------
|
||||
|
||||
monero_version monero_wallet_key::get_version() const {
|
||||
monero_wallet_keys::~monero_wallet_keys() {
|
||||
MTRACE("~monero_wallet_keys()");
|
||||
close();
|
||||
}
|
||||
|
||||
monero_version monero_wallet_keys::get_version() const {
|
||||
monero_version version;
|
||||
version.m_number = 65552; // same as monero-wallet-rpc v0.15.0.1 release
|
||||
version.m_is_release = false; // TODO: could pull from MONERO_VERSION_IS_RELEASE in version.cpp
|
||||
return version;
|
||||
}
|
||||
|
||||
monero_network_type monero_wallet_key::get_network_type() const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
monero_network_type monero_wallet_keys::get_network_type() const {
|
||||
throw runtime_error("monero_wallet_keys::get_network_type() not implemented");
|
||||
}
|
||||
|
||||
string monero_wallet_key::get_language() const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
string monero_wallet_keys::get_language() const {
|
||||
throw runtime_error("monero_wallet_keys::get_subaddresses() not implemented");
|
||||
}
|
||||
|
||||
vector<string> monero_wallet_key::get_languages() const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
vector<string> monero_wallet_keys::get_languages() const {
|
||||
throw runtime_error("monero_wallet_keys::get_languages() not implemented");
|
||||
}
|
||||
|
||||
string monero_wallet_key::get_mnemonic() const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
string monero_wallet_keys::get_mnemonic() const {
|
||||
throw runtime_error("monero_wallet_keys::get_mnemonic() not implemented");
|
||||
}
|
||||
|
||||
string monero_wallet_key::get_public_view_key() const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
string monero_wallet_keys::get_public_view_key() const {
|
||||
throw runtime_error("monero_wallet_keys::get_public_view_key() not implemented");
|
||||
}
|
||||
|
||||
string monero_wallet_key::get_private_view_key() const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
string monero_wallet_keys::get_private_view_key() const {
|
||||
throw runtime_error("monero_wallet_keys::get_private_view_key() not implemented");
|
||||
}
|
||||
|
||||
string monero_wallet_key::get_public_spend_key() const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
string monero_wallet_keys::get_public_spend_key() const {
|
||||
throw runtime_error("monero_wallet_keys::get_public_spend_key() not implemented");
|
||||
}
|
||||
|
||||
string monero_wallet_key::get_private_spend_key() const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
string monero_wallet_keys::get_private_spend_key() const {
|
||||
throw runtime_error("monero_wallet_keys::get_private_spend_key() not implemented");
|
||||
}
|
||||
|
||||
string monero_wallet_key::get_address(uint32_t account_idx, uint32_t subaddress_idx) const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
string monero_wallet_keys::get_address(uint32_t account_idx, uint32_t subaddress_idx) const {
|
||||
throw runtime_error("monero_wallet_keys::get_address() not implemented");
|
||||
}
|
||||
|
||||
monero_subaddress monero_wallet_key::get_address_index(const string& address) const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
monero_subaddress monero_wallet_keys::get_address_index(const string& address) const {
|
||||
throw runtime_error("monero_wallet_keys::get_address_index() not implemented");
|
||||
}
|
||||
|
||||
monero_integrated_address monero_wallet_key::get_integrated_address(const string& standard_address, const string& payment_id) const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
monero_integrated_address monero_wallet_keys::get_integrated_address(const string& standard_address, const string& payment_id) const {
|
||||
throw runtime_error("monero_wallet_keys::get_integrated_address() not implemented");
|
||||
}
|
||||
|
||||
monero_integrated_address monero_wallet_key::decode_integrated_address(const string& integrated_address) const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
monero_integrated_address monero_wallet_keys::decode_integrated_address(const string& integrated_address) const {
|
||||
throw runtime_error("monero_wallet_keys::decode_integrated_address() not implemented");
|
||||
}
|
||||
|
||||
vector<monero_account> monero_wallet_key::get_accounts(bool include_subaddresses, const string& tag) const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
vector<monero_account> monero_wallet_keys::get_accounts(bool include_subaddresses, const string& tag) const {
|
||||
throw runtime_error("monero_wallet_keys::get_accounts() not implemented");
|
||||
}
|
||||
|
||||
monero_account monero_wallet_key::get_account(uint32_t account_idx, bool include_subaddresses) const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
monero_account monero_wallet_keys::get_account(uint32_t account_idx, bool include_subaddresses) const {
|
||||
throw runtime_error("monero_wallet_keys::get_subaddresses() not implemented");
|
||||
}
|
||||
|
||||
monero_account monero_wallet_key::create_account(const string& label) {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
monero_account monero_wallet_keys::create_account(const string& label) {
|
||||
throw runtime_error("monero_wallet_keys::get_account() not implemented");
|
||||
}
|
||||
|
||||
vector<monero_subaddress> monero_wallet_key::get_subaddresses(const uint32_t account_idx) const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
vector<monero_subaddress> monero_wallet_keys::get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& subaddress_indices) const {
|
||||
throw runtime_error("monero_wallet_keys::get_subaddresses() not implemented");
|
||||
}
|
||||
|
||||
vector<monero_subaddress> monero_wallet_key::get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& subaddress_indices) const {
|
||||
throw runtime_error("monero_wallet_key::get_subaddresses() not implemented");
|
||||
monero_subaddress monero_wallet_keys::get_subaddress(const uint32_t account_idx, const uint32_t subaddress_idx) const {
|
||||
throw runtime_error("monero_wallet_keys::get_subaddress() not implemented");
|
||||
}
|
||||
|
||||
monero_subaddress monero_wallet_key::get_subaddress(const uint32_t account_idx, const uint32_t subaddress_idx) const {
|
||||
throw runtime_error("monero_wallet_key::getSubaddress() not implemented");
|
||||
monero_subaddress monero_wallet_keys::create_subaddress(const uint32_t account_idx, const string& label) {
|
||||
throw runtime_error("monero_wallet_keys::create_subaddress() not implemented");
|
||||
}
|
||||
|
||||
// get_subaddresses
|
||||
|
||||
monero_subaddress monero_wallet_key::create_subaddress(const uint32_t account_idx, const string& label) {
|
||||
throw runtime_error("monero_wallet_key::getSubaddress() not implemented");
|
||||
}
|
||||
void monero_wallet_key::close() {
|
||||
throw runtime_error("monero_wallet_key::getSubaddress() not implemented");
|
||||
void monero_wallet_keys::close() {
|
||||
throw runtime_error("monero_wallet_keys::close() not implemented");
|
||||
}
|
||||
|
||||
// ------------------------------- PRIVATE HELPERS ----------------------------
|
||||
|
||||
@@ -72,44 +72,31 @@ namespace monero {
|
||||
/**
|
||||
* Create a new wallet with a randomly generated seed.
|
||||
*
|
||||
* @param path is the path to create the wallet
|
||||
* @param password is the password encrypt the wallet
|
||||
* @param network_type is the wallet's network type (default = monero_network_type.MAINNET)
|
||||
* @param daemon_connection is connection information to a daemon (default = an unconnected wallet)
|
||||
* @param language is the wallet and mnemonic's language (default = "English")
|
||||
*/
|
||||
static monero_wallet_keys* create_wallet_random(const string& path, const string& password);
|
||||
static monero_wallet_keys* create_wallet_random(const string& path, const string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const string& language);
|
||||
static monero_wallet_keys* create_wallet_random();
|
||||
static monero_wallet_keys* create_wallet_random(const monero_network_type network_type, const string& language);
|
||||
|
||||
/**
|
||||
* Create a wallet from an existing mnemonic phrase.
|
||||
*
|
||||
* @param path is the path to create the wallet
|
||||
* @param password is the password encrypt the wallet
|
||||
* @param network_type is the wallet's network type
|
||||
* @param mnemonic is the mnemonic of the wallet to construct
|
||||
* @param daemon_connection is connection information to a daemon (default = an unconnected wallet)
|
||||
* @param restore_height is the block height to restore (i.e. scan the chain) from (default = 0)
|
||||
*/
|
||||
static monero_wallet_keys* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic);
|
||||
static monero_wallet_keys* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height);
|
||||
static monero_wallet_keys* create_wallet_from_mnemonic(const monero_network_type network_type, const string& mnemonic);
|
||||
|
||||
/**
|
||||
* Create a wallet from an address, view key, and spend key.
|
||||
*
|
||||
* @param path is the path to create the wallet
|
||||
* @param password is the password encrypt the wallet
|
||||
* @param network_type is the wallet's network type
|
||||
* @param address is the address of the wallet to construct
|
||||
* @param view_key is the view key of the wallet to construct
|
||||
* @param spend_key is the spend key of the wallet to construct
|
||||
* @param daemon_connection is connection information to a daemon (default = an unconnected wallet)
|
||||
* @param restore_height is the block height to restore (i.e. scan the chain) from (default = 0)
|
||||
* @param language is the wallet and mnemonic's language (default = "English")
|
||||
*/
|
||||
static monero_wallet_keys* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key);
|
||||
static monero_wallet_keys* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height);
|
||||
static monero_wallet_keys* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language);
|
||||
static monero_wallet_keys* create_wallet_from_keys(const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key);
|
||||
static monero_wallet_keys* create_wallet_from_keys(const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const string& language);
|
||||
|
||||
/**
|
||||
* Destruct the wallet.
|
||||
@@ -136,7 +123,7 @@ namespace monero {
|
||||
monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const;
|
||||
monero_account create_account(const string& label = "");
|
||||
vector<monero_subaddress> get_subaddresses(const uint32_t account_idx, const vector<uint32_t>& subaddress_indices) const;
|
||||
monero_subaddress getSubaddress(const uint32_t account_idx, const uint32_t subaddress_idx) const;
|
||||
monero_subaddress get_subaddress(const uint32_t account_idx, const uint32_t subaddress_idx) const;
|
||||
monero_subaddress create_subaddress(uint32_t account_idx, const string& label = "");
|
||||
string sign(const string& msg) const;
|
||||
bool verify(const string& msg, const string& address, const string& signature) const;
|
||||
|
||||
Reference in New Issue
Block a user