forked from lthn/blockchain
minor changes relatd to secp256k1_ecdsa integration
This commit is contained in:
parent
2badfead11
commit
744522f3ca
6 changed files with 70 additions and 6 deletions
|
|
@ -25,6 +25,8 @@
|
|||
//
|
||||
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
#include <optional>
|
||||
#include "misc_language.h"
|
||||
namespace epee
|
||||
{
|
||||
|
|
@ -51,24 +53,73 @@ namespace epee
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_std_optional : std::false_type {};
|
||||
|
||||
template<typename T>
|
||||
struct is_std_optional<std::optional<T>> : std::true_type {};
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct is_std_optional<boost::optional<T>> : std::true_type {};
|
||||
|
||||
|
||||
//basic helpers for pod-to-hex serialization
|
||||
template<class t_pod_type>
|
||||
std::string transform_t_pod_to_str_internal(const t_pod_type& a)
|
||||
{
|
||||
return epee::string_tools::pod_to_hex(a);
|
||||
}
|
||||
|
||||
template<class t_pod_type>
|
||||
std::string transform_t_pod_to_str_internal(const std::optional<t_pod_type>& a)
|
||||
{
|
||||
if (a.has_value())
|
||||
return epee::string_tools::pod_to_hex(*a);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
template<class t_pod_type>
|
||||
std::string transform_t_pod_to_str_internal(const boost::optional<t_pod_type>& a)
|
||||
{
|
||||
if (a.has_value())
|
||||
return epee::string_tools::pod_to_hex(*a);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
//basic helpers for pod-to-hex serialization
|
||||
template<class t_pod_type>
|
||||
std::string transform_t_pod_to_str(const t_pod_type & a)
|
||||
{
|
||||
return epee::string_tools::pod_to_hex(a);
|
||||
return transform_t_pod_to_str_internal(a);
|
||||
}
|
||||
template<class t_pod_type>
|
||||
|
||||
|
||||
|
||||
template<class t_pod_type>
|
||||
t_pod_type transform_str_to_t_pod(const std::string& a)
|
||||
{
|
||||
t_pod_type res = AUTO_VAL_INIT(res);
|
||||
t_pod_type res = AUTO_VAL_INIT(res);
|
||||
if (a.empty())
|
||||
return res;
|
||||
if constexpr (is_std_optional<t_pod_type>::value)
|
||||
{
|
||||
t_pod_type::value_type v = AUTO_VAL_INIT(v);
|
||||
if (!epee::string_tools::hex_to_pod(a, v))
|
||||
throw std::runtime_error(std::string("Unable to transform \"") + a + "\" to pod type " + typeid(t_pod_type::value_type).name());
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
if (!epee::string_tools::hex_to_pod(a, res))
|
||||
throw std::runtime_error(std::string("Unable to transform \"") + a + "\" to pod type " + typeid(t_pod_type).name());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//basic helpers for blob-to-hex serialization
|
||||
|
||||
inline std::string transform_binbuf_to_hexstr(const std::string& a)
|
||||
|
|
|
|||
|
|
@ -157,6 +157,10 @@ namespace crypto
|
|||
{
|
||||
return o << epee::string_tools::pod_to_hex(v);
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& o, const eth_signature& v)
|
||||
{
|
||||
return o << epee::string_tools::pod_to_hex(v);
|
||||
}
|
||||
|
||||
|
||||
} // namespace crypto
|
||||
|
|
|
|||
|
|
@ -62,5 +62,6 @@ namespace crypto
|
|||
|
||||
std::ostream& operator<<(std::ostream& o, const eth_secret_key& v);
|
||||
std::ostream& operator<<(std::ostream& o, const eth_public_key& v);
|
||||
std::ostream& operator<<(std::ostream& o, const eth_signature& v);
|
||||
|
||||
} // namespace crypto
|
||||
|
|
|
|||
|
|
@ -4116,7 +4116,15 @@ bool blockchain_storage::validate_ado_ownership(asset_op_verification_context& a
|
|||
asset_operation_ownership_proof_eth aoop_eth{};
|
||||
r = get_type_in_variant_container(avc.tx.proofs, aoop_eth);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Ownership validation failed: asset_operation_ownership_proof_eth is missing");
|
||||
return crypto::verify_eth_signature(avc.tx_id, last_ado.descriptor.owner_eth_pub_key.value(), aoop_eth.eth_sig);
|
||||
if (!crypto::verify_eth_signature(avc.tx_id, last_ado.descriptor.owner_eth_pub_key.value(), aoop_eth.eth_sig))
|
||||
{
|
||||
LOG_ERROR("Failed to validate secp256k1 signature for hash: " << avc.tx_id << ", signature: " << aoop_eth.eth_sig);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// owner_eth_pub_key has no value -- fallback to default
|
||||
}
|
||||
|
|
|
|||
|
|
@ -749,7 +749,7 @@ namespace currency
|
|||
KV_SERIALIZE(meta_info) DOC_DSCR("Any other information associated with the asset in free form.") DOC_EXMP("Stable and private") DOC_END
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(owner) DOC_DSCR("Owner's key, used only for EMIT and UPDATE validation, can be changed by transferring asset ownership.") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
|
||||
KV_SERIALIZE(hidden_supply) DOC_DSCR("This field is reserved for future use and will be documented later.") DOC_END
|
||||
KV_SERIALIZE(owner_eth_pub_key) DOC_DSCR("[Optional] Owner's key in the case when ETH signature is used.") DOC_END
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(owner_eth_pub_key) DOC_DSCR("[Optional] Owner's key in the case when ETH signature is used.") DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -395,7 +395,7 @@ const crypto::public_key& wallet2::out_get_pub_key(const currency::tx_out_v& out
|
|||
void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_operation& ado, process_transaction_context& ptc)
|
||||
{
|
||||
auto print_ado_owner = [ado](std::ostream& o){
|
||||
ado.descriptor.owner_eth_pub_key.has_value() ? o << ado.descriptor.owner_eth_pub_key.get() << " (ETH)" : o << ado.descriptor.owner;
|
||||
ado.descriptor.owner_eth_pub_key.has_value() ? o << ado.descriptor.owner_eth_pub_key.value() << " (ETH)" : o << ado.descriptor.owner;
|
||||
};
|
||||
|
||||
do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue