From 14a6c6b8efa9ebfd13a693b66b4d6561c3eca291 Mon Sep 17 00:00:00 2001 From: akildemir Date: Tue, 24 Jun 2025 13:19:42 +0300 Subject: [PATCH] generate & scan correct carrot pubkeys --- src/carrot_impl/account.cpp | 5 ++--- src/carrot_impl/account.h | 4 ++-- src/simplewallet/simplewallet.cpp | 18 ++++++++++++++++-- src/wallet/scanning_tools.cpp | 6 ++---- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/carrot_impl/account.cpp b/src/carrot_impl/account.cpp index 866f8a1..8a3dd99 100644 --- a/src/carrot_impl/account.cpp +++ b/src/carrot_impl/account.cpp @@ -302,12 +302,12 @@ crypto::secret_key carrot_and_legacy_account::generate( crypto::secret_key retval = cryptonote::account_base::generate(recovery_key, recover, two_random); // generate carrot keys - set_carrot_keys(); + set_carrot_keys(default_derive_type); return retval; } //---------------------------------------------------------------------------------------------------------------------- -void carrot_and_legacy_account::set_carrot_keys() +void carrot_and_legacy_account::set_carrot_keys(const AddressDeriveType default_derive_type) { // top level keys m_keys.s_master = m_keys.m_spend_secret_key; @@ -315,7 +315,6 @@ void carrot_and_legacy_account::set_carrot_keys() make_carrot_viewbalance_secret(m_keys.s_master, m_keys.s_view_balance); // view balance keys - make_carrot_viewincoming_key(m_keys.s_view_balance, m_keys.k_view_incoming); make_carrot_generateimage_key(m_keys.s_view_balance, m_keys.k_generate_image); make_carrot_generateaddress_secret(m_keys.s_view_balance, m_keys.s_generate_address); diff --git a/src/carrot_impl/account.h b/src/carrot_impl/account.h index 9431be2..ac16572 100644 --- a/src/carrot_impl/account.h +++ b/src/carrot_impl/account.h @@ -53,7 +53,7 @@ namespace carrot std::unordered_map subaddress_map; AddressDeriveType default_derive_type; - carrot_and_legacy_account(): k_view_incoming_dev(get_keys().k_view_incoming), + carrot_and_legacy_account(): k_view_incoming_dev(get_keys().m_view_secret_key), s_view_balance_dev(get_keys().s_view_balance), s_generate_address_dev(get_keys().s_generate_address) {} @@ -106,7 +106,7 @@ namespace carrot const AddressDeriveType default_derive_type = AddressDeriveType::Carrot ); - void set_carrot_keys(); + void set_carrot_keys(const AddressDeriveType default_derive_type = AddressDeriveType::Carrot); AddressDeriveType resolve_derive_type(const AddressDeriveType derive_type) const; }; diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 209cae0..da79f1d 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -79,6 +79,9 @@ #include "wallet/message_store.h" #include "QrCode.hpp" +#include "carrot_impl/subaddress_index.h" +#include "carrot_core/core_types.h" + #ifdef WIN32 #include #include @@ -5226,8 +5229,14 @@ boost::optional simple_wallet::new_wallet(const boost::pr recovery_val = m_wallet->generate(m_wallet_file, std::move(rc.second).password(), recovery_key, recover, two_random, create_address_file); message_writer(console_color_white, true) << tr("Generated new legacy wallet: ") << m_wallet->get_account().get_public_address_str(m_wallet->nettype()); + + const auto addr = m_wallet->get_account().cryptonote_address(carrot::null_payment_id, carrot::AddressDeriveType::Carrot); + cryptonote::account_public_address carrot_address { + .m_spend_public_key = addr.address_spend_pubkey, + .m_view_public_key = addr.address_view_pubkey + }; message_writer(console_color_white, true) << tr("Generated new carrot wallet: ") - << cryptonote::get_account_address_as_str(m_wallet->nettype(), false, m_wallet->get_account().get_keys().m_carrot_account_address); + << cryptonote::get_account_address_as_str(m_wallet->nettype(), false, carrot_address); PAUSE_READLINE(); std::cout << tr("View key: "); print_secret_key(m_wallet->get_account().get_keys().m_view_secret_key); @@ -5469,9 +5478,14 @@ boost::optional simple_wallet::open_wallet(const boost::p message_writer(console_color_white, true) << prefix << ": " << m_wallet->get_account().get_public_address_str(m_wallet->nettype()); + const auto addr = m_wallet->get_account().cryptonote_address(carrot::null_payment_id, carrot::AddressDeriveType::Carrot); + cryptonote::account_public_address carrot_address { + .m_spend_public_key = addr.address_spend_pubkey, + .m_view_public_key = addr.address_view_pubkey + }; prefix = tr("Opened carrot wallet"); message_writer(console_color_white, true) << - prefix << ": " << cryptonote::get_account_address_as_str(m_wallet->nettype(), false, m_wallet->get_account().get_keys().m_carrot_account_address); + prefix << ": " << cryptonote::get_account_address_as_str(m_wallet->nettype(), false, carrot_address); if (m_wallet->get_account().get_device()) { message_writer(console_color_white, true) << "Wallet is on device: " << m_wallet->get_account().get_device().get_name(); } diff --git a/src/wallet/scanning_tools.cpp b/src/wallet/scanning_tools.cpp index a79ab1a..1d97752 100644 --- a/src/wallet/scanning_tools.cpp +++ b/src/wallet/scanning_tools.cpp @@ -726,9 +726,7 @@ void view_incoming_scan_transaction( //! @TODO: HW device const bool is_carrot = carrot::is_carrot_transaction_v1(tx); - carrot::view_incoming_key_ram_borrowed_device k_view_dev( - is_carrot ? acc.k_view_incoming : acc.m_view_secret_key - ); + carrot::view_incoming_key_ram_borrowed_device k_view_dev(acc.m_view_secret_key); // do view-incoming scan for each output enotes for (size_t local_output_index = 0; local_output_index < n_outputs; ++local_output_index) @@ -775,7 +773,7 @@ void view_incoming_scan_transaction( const bool is_carrot = carrot::is_carrot_transaction_v1(tx); perform_ecdh_derivations(epee::to_span(main_tx_ephemeral_pubkeys), epee::to_span(additional_tx_ephemeral_pubkeys), - is_carrot ? acc.k_view_incoming : acc.m_view_secret_key, + acc.m_view_secret_key, acc.get_device(), is_carrot, main_derivations,