ProofSystem/include/ProofSystem/EthereumKeyGenerator.hpp¶
Ethereum address generator header file. More...
Namespaces¶
| Name |
|---|
| ethereum |
Classes¶
| Name | |
|---|---|
| class | ethereum::EthereumKeyGenerator Creates a pair of ECDSA keys and a ethereum address. |
Detailed Description¶
Ethereum address generator header file.
Date: 2023-12-08 Super Genius ([email protected]) Henrique A. Klein ([email protected])
Source code¶
#ifndef ETHEREUM_KEY_GENERATOR_HPP
#define ETHEREUM_KEY_GENERATOR_HPP
#include <string>
#include <ProofSystem/EthereumKeyPairParams.hpp>
#include <ProofSystem/ext_private_key.hpp>
#include <ProofSystem/ECDSAPublicKey.hpp>
namespace ethereum
{
class EthereumKeyGenerator
{
public:
using PubKeyPair_t = std::pair<std::vector<std::uint8_t>, std::vector<std::uint8_t>>;
EthereumKeyGenerator();
EthereumKeyGenerator( std::string_view private_key );
EthereumKeyGenerator( const ethereum::scalar_field_value_type &private_key );
[[nodiscard]] pubkey::ext_private_key<ethereum::policy_type> get_private_key() const
{
return *privkey;
}
[[nodiscard]] pubkey::public_key<ethereum::policy_type> get_public_key() const
{
return *pubkey;
}
[[nodiscard]] const std::string &get_address() const
{
return address;
}
[[nodiscard]] const std::string &GetUsedPubKeyValue() const
{
return *pubkey_info;
}
[[nodiscard]] std::string GetEntirePubValue() const
{
return pubkey_info->GetEntireKey();
}
template <typename T>
static T ExtractPubKeyFromField( const pubkey::public_key<ethereum::policy_type> &pub_key );
static std::string DeriveAddress( const std::vector<std::uint8_t> &pub_key_vect );
static std::shared_ptr<pubkey::ext_private_key<ethereum::policy_type>> CreateKeys();
static pubkey::public_key<ethereum::policy_type> BuildPublicKey( const std::string &pubkey_data );
private:
static ethereum::random_generator_type key_gen;
std::shared_ptr<pubkey::ext_private_key<ethereum::policy_type>> privkey;
std::shared_ptr<pubkey::public_key<ethereum::policy_type>> pubkey;
class EthereumECDSAPublicKey : public ECDSAPublicKey
{
using ECDSAPublicKey::ECDSAPublicKey;
[[nodiscard]] std::string CalcPubkeyUsedValue() const override
{
return ( X + Y );
}
};
std::shared_ptr<EthereumECDSAPublicKey> pubkey_info;
std::string address;
static constexpr std::string_view ADDRESS_HEADER = "0x";
static constexpr std::size_t KECCAK_RES_VALID_POS = 24;
static constexpr std::size_t ADDRESS_VALID_POS = KECCAK_RES_VALID_POS - 2;
static constexpr std::size_t ADDRESS_SIZE_CHARS = 42;
std::string DeriveAddress();
};
} // namespace ethereum
#endif // ETHEREUM_KEY_GENERATOR_HPP
Updated on 2026-03-04 at 13:10:44 -0800