wallet.cpp: Implement suggest_brain_key

This commit is contained in:
theoreticalbts 2015-07-10 16:59:08 -04:00
parent e201e59b3d
commit 38c68e1f5d
4 changed files with 52 additions and 3 deletions

View file

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

View file

@ -18,6 +18,8 @@
#include <stdint.h>
#include <graphene/utilities/words.hpp>
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

View file

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

View file

@ -43,6 +43,7 @@
#include <graphene/app/api.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/utilities/key_conversion.hpp>
#include <graphene/utilities/words.hpp>
#include <graphene/wallet/wallet.hpp>
#include <graphene/wallet/api_documentation.hpp>
#include <fc/smart_ref_impl.hpp>
@ -52,6 +53,8 @@
# include <sys/stat.h>
#endif
#define BRAIN_KEY_WORD_COUNT 16
namespace graphene { namespace wallet {
namespace detail {
@ -1833,9 +1836,34 @@ vector<force_settlement_object> 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<BRAIN_KEY_WORD_COUNT; i++ )
{
fc::bigint choice = entropy % graphene::words::word_list_size;
entropy /= graphene::words::word_list_size;
if( 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