1
0
Fork 0
forked from lthn/blockchain

basic crypto functions exported from wallet

This commit is contained in:
cryptozoidberg 2023-04-03 20:32:18 +02:00
parent ca7d50d9ff
commit dcf1b0adae
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
2 changed files with 36 additions and 0 deletions

View file

@ -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<currency::tx_source_entry>& sources, std::vector<uint64_t>& selected_indicies, uint64_t& found_money)
{
prepare_free_transfers_cache(fake_outputs_count);

View file

@ -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 ------------------------------------------------