From dcf1b0adae95a0f92eae728f61e334e6eefdd016 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 3 Apr 2023 20:32:18 +0200 Subject: [PATCH] basic crypto functions exported from wallet --- src/wallet/wallet2.cpp | 29 +++++++++++++++++++++++++++++ src/wallet/wallet2.h | 7 +++++++ 2 files changed, 36 insertions(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index f6429fde..59930bf4 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5081,6 +5081,35 @@ bool wallet2::accept_ionic_swap_proposal(const currency::transaction& tx_templat return true; } //---------------------------------------------------------------------------------------------------- + +// Signing and auth +bool wallet2::sign_buffer(const std::string& buff, crypto::signature& sig) +{ + crypto::hash h = crypto::cn_fast_hash(buff.data(), buff.size()); + crypto::generate_signature(h, m_account.get_public_address().spend_public_key, m_account.get_keys().spend_secret_key, sig); + return true; +} +//---------------------------------------------------------------------------------------------------- +bool wallet2::validate_sign(const std::string& buff, const crypto::signature& sig, const crypto::public_key& pkey) +{ + crypto::hash h = crypto::cn_fast_hash(buff.data(), buff.size()); + return crypto::check_signature(h, sig, pkey); +} +//---------------------------------------------------------------------------------------------------- +bool wallet2::encrypt_buffer(const std::string& buff, std::string& res_buff) +{ + res_buff = buff; + crypto::chacha_crypt(res_buff, m_account.get_keys().view_secret_key); + return true; +} +//---------------------------------------------------------------------------------------------------- +bool wallet2::decrypt_buffer(const std::string& buff, std::string& res_buff) +{ + res_buff = buff; + crypto::chacha_crypt(res_buff, m_account.get_keys().view_secret_key); + return true; +} +//---------------------------------------------------------------------------------------------------- bool wallet2::prepare_tx_sources_for_packing(uint64_t items_to_pack, size_t fake_outputs_count, std::vector& sources, std::vector& selected_indicies, uint64_t& found_money) { prepare_free_transfers_cache(fake_outputs_count); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 5fdd93f4..430d66de 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -937,6 +937,13 @@ namespace tools bool get_ionic_swap_proposal_info(const currency::transaction tx, view::ionic_swap_proposal_info& proposal); bool accept_ionic_swap_proposal(const std::string&raw_tx_template, currency::transaction& result_tx); bool accept_ionic_swap_proposal(const currency::transaction& tx_template, currency::transaction& result_tx); + + // Signing and auth + bool sign_buffer(const std::string& buff, crypto::signature& sig); + bool validate_sign(const std::string& buff, const crypto::signature& sig, const crypto::public_key& pkey); + bool encrypt_buffer(const std::string& buff, std::string& res_buff); + bool decrypt_buffer(const std::string& buff, std::string& res_buff); + private: // -------- t_transport_state_notifier ------------------------------------------------