Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue1011, Add CLI startup option to only generate keys #1039

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libraries/wallet/include/graphene/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ class utility {
* @return A list of keys that are deterministically derived from the brainkey
*/
static vector<brain_key_info> derive_owner_keys_from_brain_key(string brain_key, int number_of_desired_keys = 1);

/** Suggests a safe brain key to use for creating your account.
* \c create_account_with_brain_key() requires you to specify a 'brain key',
* a long passphrase that provides enough entropy to generate cyrptographic
* keys. This function will suggest a suitably random string that should
* be easy to write down (and, with effort, memorize).
* @returns a suggested brain_key
*/
static brain_key_info suggest_brain_key();
};

struct operation_detail {
Expand Down
57 changes: 31 additions & 26 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,36 @@ namespace graphene { namespace wallet {

return results;
}

brain_key_info utility::suggest_brain_key()
{
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 = detail::normalize_brain_key(brain_key);
fc::ecc::private_key priv_key = detail::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;
}
}}

namespace graphene { namespace wallet {
Expand Down Expand Up @@ -2957,32 +2987,7 @@ vector<collateral_bid_object> wallet_api::get_collateral_bids(string asset, uint

brain_key_info wallet_api::suggest_brain_key()const
{
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;
return graphene::wallet::utility::suggest_brain_key();
}

vector<brain_key_info> wallet_api::derive_owner_keys_from_brain_key(string brain_key, int number_of_desired_keys) const
Expand Down
8 changes: 8 additions & 0 deletions programs/cli_wallet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ int main( int argc, char** argv )
("daemon,d", "Run the wallet in daemon mode" )
("wallet-file,w", bpo::value<string>()->implicit_value("wallet.json"), "wallet to load")
("chain-id", bpo::value<string>(), "chain ID to connect to")
("suggest-brain-key", "Suggest a safe brain key to use for craeting your account")
Copy link
Contributor

@pmconrad pmconrad Jun 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: craeting

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah oh.. thanks~ fixed

("version,v", "Display version information");


Expand All @@ -108,6 +109,13 @@ int main( int argc, char** argv )
std::cout << "Websocket++: " << websocketpp::major_version << "." << websocketpp::minor_version << "." << websocketpp::patch_version << "\n";
return 0;
}
if( options.count("suggest-brain-key") )
{
auto keyinfo = graphene::wallet::utility::suggest_brain_key();
string data = fc::json::to_pretty_string( keyinfo );
std::cout << data.c_str() << std::endl;
return 0;
}

fc::path data_dir;
fc::logging_config cfg;
Expand Down