wallet.cpp: Implement suggest_brain_key
This commit is contained in:
parent
e201e59b3d
commit
38c68e1f5d
4 changed files with 52 additions and 3 deletions
|
|
@ -17,6 +17,10 @@
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
namespace graphene { namespace words {
|
||||||
|
|
||||||
typedef const char* const_char_ptr;
|
typedef const char* const_char_ptr;
|
||||||
extern const const_char_ptr word_list[];
|
extern const const_char_ptr word_list[];
|
||||||
extern const uint32_t word_list_size;
|
extern const uint32_t word_list_size;
|
||||||
|
|
||||||
|
} }
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <graphene/utilities/words.hpp>
|
#include <graphene/utilities/words.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace words {
|
||||||
|
|
||||||
const const_char_ptr word_list[] = {
|
const const_char_ptr word_list[] = {
|
||||||
"a",
|
"a",
|
||||||
"aa",
|
"aa",
|
||||||
|
|
@ -49771,3 +49773,5 @@ void hide_unused_warning() {
|
||||||
(void)word_list_size;
|
(void)word_list_size;
|
||||||
(void)word_list;
|
(void)word_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} } // graphene::words
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,13 @@ struct plain_keys
|
||||||
fc::sha512 checksum;
|
fc::sha512 checksum;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct brain_key_info
|
||||||
|
{
|
||||||
|
string brain_priv_key;
|
||||||
|
string wif_priv_key;
|
||||||
|
public_key_type pub_key;
|
||||||
|
};
|
||||||
|
|
||||||
struct wallet_data
|
struct wallet_data
|
||||||
{
|
{
|
||||||
account_multi_index_type my_accounts;
|
account_multi_index_type my_accounts;
|
||||||
|
|
@ -386,7 +393,7 @@ class wallet_api
|
||||||
* be easy to write down (and, with effort, memorize).
|
* be easy to write down (and, with effort, memorize).
|
||||||
* @returns a suggested brain_key
|
* @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.
|
/** Converts a signed_transaction in JSON form to its binary representation.
|
||||||
*
|
*
|
||||||
|
|
@ -1015,6 +1022,12 @@ FC_REFLECT( graphene::wallet::wallet_data,
|
||||||
(ws_password)
|
(ws_password)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
FC_REFLECT( graphene::wallet::brain_key_info,
|
||||||
|
(brain_priv_key)
|
||||||
|
(wif_priv_key)
|
||||||
|
(pub_key)
|
||||||
|
);
|
||||||
|
|
||||||
FC_API( graphene::wallet::wallet_api,
|
FC_API( graphene::wallet::wallet_api,
|
||||||
(help)
|
(help)
|
||||||
(gethelp)
|
(gethelp)
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@
|
||||||
#include <graphene/app/api.hpp>
|
#include <graphene/app/api.hpp>
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/utilities/key_conversion.hpp>
|
#include <graphene/utilities/key_conversion.hpp>
|
||||||
|
#include <graphene/utilities/words.hpp>
|
||||||
#include <graphene/wallet/wallet.hpp>
|
#include <graphene/wallet/wallet.hpp>
|
||||||
#include <graphene/wallet/api_documentation.hpp>
|
#include <graphene/wallet/api_documentation.hpp>
|
||||||
#include <fc/smart_ref_impl.hpp>
|
#include <fc/smart_ref_impl.hpp>
|
||||||
|
|
@ -52,6 +53,8 @@
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define BRAIN_KEY_WORD_COUNT 16
|
||||||
|
|
||||||
namespace graphene { namespace wallet {
|
namespace graphene { namespace wallet {
|
||||||
|
|
||||||
namespace detail {
|
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);
|
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
|
string wallet_api::serialize_transaction( signed_transaction tx )const
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue