diff --git a/libraries/utilities/include/graphene/utilities/words.hpp b/libraries/utilities/include/graphene/utilities/words.hpp index aced2379..cf2feb08 100644 --- a/libraries/utilities/include/graphene/utilities/words.hpp +++ b/libraries/utilities/include/graphene/utilities/words.hpp @@ -17,6 +17,10 @@ */ #pragma once +namespace graphene { namespace words { + typedef const char* const_char_ptr; extern const const_char_ptr word_list[]; extern const uint32_t word_list_size; + +} } diff --git a/libraries/utilities/words.cpp b/libraries/utilities/words.cpp index 64f699ff..abc74a4e 100644 --- a/libraries/utilities/words.cpp +++ b/libraries/utilities/words.cpp @@ -18,6 +18,8 @@ #include #include +namespace graphene { namespace words { + const const_char_ptr word_list[] = { "a", "aa", @@ -49771,3 +49773,5 @@ void hide_unused_warning() { (void)word_list_size; (void)word_list; } + +} } // graphene::words diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 52f79647..253cfb88 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -48,6 +48,13 @@ struct plain_keys fc::sha512 checksum; }; +struct brain_key_info +{ + string brain_priv_key; + string wif_priv_key; + public_key_type pub_key; +}; + struct wallet_data { account_multi_index_type my_accounts; @@ -386,7 +393,7 @@ class wallet_api * be easy to write down (and, with effort, memorize). * @returns a suggested brain_key */ - string suggest_brain_key()const; + brain_key_info suggest_brain_key()const; /** Converts a signed_transaction in JSON form to its binary representation. * @@ -1015,6 +1022,12 @@ FC_REFLECT( graphene::wallet::wallet_data, (ws_password) ) +FC_REFLECT( graphene::wallet::brain_key_info, + (brain_priv_key) + (wif_priv_key) + (pub_key) + ); + FC_API( graphene::wallet::wallet_api, (help) (gethelp) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 0f082dbe..0fbd8be4 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,8 @@ # include #endif +#define BRAIN_KEY_WORD_COUNT 16 + namespace graphene { namespace wallet { namespace detail { @@ -1833,9 +1836,34 @@ vector wallet_api::get_settle_orders(string a, uint32_t return my->_remote_db->get_settle_orders(get_asset(a).id, limit); } -string wallet_api::suggest_brain_key()const +brain_key_info wallet_api::suggest_brain_key()const { - return string("dummy"); + brain_key_info result; + // create a private key for secure entropy + fc::sha256 sha_entropy1 = fc::ecc::private_key::generate().get_secret(); + fc::sha256 sha_entropy2 = fc::ecc::private_key::generate().get_secret(); + fc::bigint entropy1( sha_entropy1.data(), sha_entropy1.data_size() ); + fc::bigint entropy2( sha_entropy2.data(), sha_entropy2.data_size() ); + fc::bigint entropy(entropy1); + entropy <<= 8*sha_entropy1.data_size(); + entropy += entropy2; + string brain_key = ""; + + for( int i=0; i 0 ) + brain_key += " "; + brain_key += graphene::words::word_list[ choice.to_int64() ]; + } + + brain_key = normalize_brain_key(brain_key); + fc::ecc::private_key priv_key = derive_private_key( brain_key, 0 ); + result.brain_priv_key = brain_key; + result.wif_priv_key = key_to_wif( priv_key ); + result.pub_key = priv_key.get_public_key(); + return result; } string wallet_api::serialize_transaction( signed_transaction tx )const