forked from lthn/blockchain
seed phase improvements: 26 words + checksum + auditable wallets support
This commit is contained in:
parent
599558ef9b
commit
1441b5b27f
11 changed files with 168 additions and 122 deletions
|
|
@ -85,34 +85,31 @@ namespace crypto {
|
|||
memcpy(&res, tmp, 32);
|
||||
}
|
||||
|
||||
void crypto_ops::keys_from_default(unsigned char* a_part, public_key &pub, secret_key &sec, size_t brain_wallet_seed_size)
|
||||
{
|
||||
unsigned char tmp[64] = { 0 };
|
||||
|
||||
if (!(sizeof(tmp) >= brain_wallet_seed_size))
|
||||
{
|
||||
throw std::runtime_error("size mismatch");
|
||||
}
|
||||
|
||||
memcpy(tmp, a_part, brain_wallet_seed_size);
|
||||
|
||||
cn_fast_hash(tmp, 32, (char*)&tmp[32]);
|
||||
|
||||
sc_reduce(tmp);
|
||||
memcpy(&sec, tmp, 32);
|
||||
ge_p3 point;
|
||||
ge_scalarmult_base(&point, &sec);
|
||||
ge_p3_tobytes(&pub, &point);
|
||||
}
|
||||
|
||||
void crypto_ops::generate_brain_keys(public_key &pub, secret_key &sec, std::string& seed, size_t brain_wallet_seed_size)
|
||||
void crypto_ops::keys_from_default(const unsigned char* a_part, public_key &pub, secret_key &sec, size_t keys_seed_binary_size)
|
||||
{
|
||||
std::vector<unsigned char> tmp_vector;
|
||||
tmp_vector.resize(brain_wallet_seed_size, 0);
|
||||
unsigned char *tmp = &tmp_vector[0];
|
||||
generate_random_bytes(brain_wallet_seed_size, tmp);
|
||||
seed.assign((const char*)tmp, brain_wallet_seed_size);
|
||||
keys_from_default(tmp, pub, sec, brain_wallet_seed_size);
|
||||
unsigned char tmp[64] = { 0 };
|
||||
|
||||
if (!(sizeof(tmp) >= keys_seed_binary_size))
|
||||
{
|
||||
throw std::runtime_error("size mismatch");
|
||||
}
|
||||
|
||||
memcpy(tmp, a_part, keys_seed_binary_size);
|
||||
|
||||
cn_fast_hash(tmp, 32, (char*)&tmp[32]);
|
||||
|
||||
sc_reduce(tmp);
|
||||
memcpy(&sec, tmp, 32);
|
||||
ge_p3 point;
|
||||
ge_scalarmult_base(&point, &sec);
|
||||
ge_p3_tobytes(&pub, &point);
|
||||
}
|
||||
|
||||
void crypto_ops::generate_seed_keys(public_key &pub, secret_key &sec, std::vector<unsigned char>& keys_seed_binary, size_t keys_seed_binary_size)
|
||||
{
|
||||
keys_seed_binary.resize(keys_seed_binary_size, 0);
|
||||
generate_random_bytes(keys_seed_binary_size, keys_seed_binary.data());
|
||||
keys_from_default(keys_seed_binary.data(), pub, sec, keys_seed_binary_size);
|
||||
}
|
||||
|
||||
static inline void hash_to_scalar(const void *data, size_t length, ec_scalar &res)
|
||||
|
|
|
|||
|
|
@ -74,10 +74,10 @@ namespace crypto {
|
|||
|
||||
static void generate_keys(public_key &, secret_key &);
|
||||
friend void generate_keys(public_key &, secret_key &);
|
||||
static void generate_brain_keys(public_key &, secret_key &, std::string& seed, size_t brain_wallet_seed_size);
|
||||
friend void generate_brain_keys(public_key &, secret_key &, std::string& seed, size_t brain_wallet_seed_size);
|
||||
static void keys_from_default(unsigned char* a_part, public_key &pub, secret_key &sec, size_t brain_wallet_seed_size);
|
||||
friend void keys_from_default(unsigned char* a_part, public_key &pub, secret_key &sec, size_t brain_wallet_seed_size);
|
||||
static void generate_seed_keys(public_key &pub, secret_key &sec, std::vector<unsigned char>& keys_seed_binary, size_t keys_seed_binary_size);
|
||||
friend void generate_seed_keys(public_key &pub, secret_key &sec, std::vector<unsigned char>& keys_seed_binary, size_t keys_seed_binary_size);
|
||||
static void keys_from_default(const unsigned char* a_part, public_key &pub, secret_key &sec, size_t keys_seed_binary_size);
|
||||
friend void keys_from_default(const unsigned char* a_part, public_key &pub, secret_key &sec, size_t keys_seed_binary_size);
|
||||
static void dependent_key(const secret_key& first, secret_key& second);
|
||||
friend void dependent_key(const secret_key& first, secret_key& second);
|
||||
static bool check_key(const public_key &);
|
||||
|
|
@ -136,14 +136,14 @@ namespace crypto {
|
|||
crypto_ops::generate_keys(pub, sec);
|
||||
}
|
||||
|
||||
inline void generate_brain_keys(public_key &pub, secret_key &sec, std::string& seed, size_t brain_wallet_seed_size) {
|
||||
crypto_ops::generate_brain_keys(pub, sec, seed, brain_wallet_seed_size);
|
||||
inline void generate_seed_keys(public_key &pub, secret_key &sec, std::vector<unsigned char>& keys_seed_binary, size_t keys_seed_binary_size)
|
||||
{
|
||||
crypto_ops::generate_seed_keys(pub, sec, keys_seed_binary, keys_seed_binary_size);
|
||||
}
|
||||
|
||||
|
||||
inline void keys_from_default(unsigned char* a_part, public_key &pub, secret_key &sec, size_t brain_wallet_seed_size)
|
||||
inline void keys_from_default(const unsigned char* a_part, public_key &pub, secret_key &sec, size_t keys_seed_binary_size)
|
||||
{
|
||||
crypto_ops::keys_from_default(a_part, pub, sec, brain_wallet_seed_size);
|
||||
crypto_ops::keys_from_default(a_part, pub, sec, keys_seed_binary_size);
|
||||
}
|
||||
|
||||
inline void dependent_key(const secret_key& first, secret_key& second){
|
||||
|
|
@ -290,8 +290,7 @@ namespace crypto {
|
|||
bool m_ready;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} // namespace crypto
|
||||
|
||||
POD_MAKE_HASHABLE(crypto, public_key)
|
||||
POD_MAKE_COMPARABLE(crypto, secret_key)
|
||||
|
|
|
|||
|
|
@ -17,15 +17,10 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
DISABLE_VS_WARNINGS(4244 4345)
|
||||
|
||||
|
||||
//DISABLE_VS_WARNINGS(4244 4345)
|
||||
|
||||
namespace currency
|
||||
{
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
account_base::account_base()
|
||||
{
|
||||
|
|
@ -37,18 +32,22 @@ namespace currency
|
|||
// fill sensitive data with random bytes
|
||||
crypto::generate_random_bytes(sizeof m_keys.spend_secret_key, &m_keys.spend_secret_key);
|
||||
crypto::generate_random_bytes(sizeof m_keys.view_secret_key, &m_keys.view_secret_key);
|
||||
crypto::generate_random_bytes(m_seed.size(), &m_seed[0]);
|
||||
if (m_keys_seed_binary.size())
|
||||
crypto::generate_random_bytes(m_keys_seed_binary.size(), &m_keys_seed_binary[0]);
|
||||
|
||||
// clear
|
||||
m_keys = account_keys();
|
||||
m_creation_timestamp = 0;
|
||||
m_seed.clear();
|
||||
m_keys_seed_binary.clear();
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
void account_base::generate()
|
||||
void account_base::generate(bool auditable /* = false */)
|
||||
{
|
||||
generate_brain_keys(m_keys.account_address.spend_public_key, m_keys.spend_secret_key, m_seed, BRAINWALLET_DEFAULT_SEED_SIZE);
|
||||
dependent_key(m_keys.spend_secret_key, m_keys.view_secret_key);
|
||||
if (auditable)
|
||||
m_keys.account_address.flags = ACCOUNT_PUBLIC_ADDRESS_FLAG_AUDITABLE;
|
||||
|
||||
crypto::generate_seed_keys(m_keys.account_address.spend_public_key, m_keys.spend_secret_key, m_keys_seed_binary, BRAINWALLET_DEFAULT_SEED_SIZE);
|
||||
crypto::dependent_key(m_keys.spend_secret_key, m_keys.view_secret_key);
|
||||
if (!crypto::secret_key_to_public_key(m_keys.view_secret_key, m_keys.account_address.view_public_key))
|
||||
throw std::runtime_error("Failed to create public view key");
|
||||
|
||||
|
|
@ -61,65 +60,108 @@ namespace currency
|
|||
return m_keys;
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
std::string account_base::get_restore_data() const
|
||||
{
|
||||
return m_seed;
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
std::string account_base::get_restore_braindata() const
|
||||
{
|
||||
std::string restore_buff = get_restore_data();
|
||||
if (restore_buff.empty())
|
||||
if (m_keys_seed_binary.empty())
|
||||
return "";
|
||||
std::vector<unsigned char> v;
|
||||
v.assign((unsigned char*)restore_buff.data(), (unsigned char*)restore_buff.data() + restore_buff.size());
|
||||
std::string seed_brain_data = tools::mnemonic_encoding::binary2text(v);
|
||||
std::string keys_seed_text = tools::mnemonic_encoding::binary2text(m_keys_seed_binary);
|
||||
std::string timestamp_word = currency::get_word_from_timstamp(m_creation_timestamp);
|
||||
seed_brain_data = seed_brain_data + timestamp_word;
|
||||
return seed_brain_data;
|
||||
|
||||
// floor creation time to WALLET_BRAIN_DATE_QUANTUM to make checksum calculation stable
|
||||
uint64_t creation_timestamp_rounded = get_timstamp_from_word(timestamp_word);
|
||||
|
||||
constexpr uint16_t checksum_max = tools::mnemonic_encoding::NUMWORDS >> 1; // maximum value of checksum
|
||||
crypto::hash h = crypto::cn_fast_hash(m_keys_seed_binary.data(), m_keys_seed_binary.size());
|
||||
*reinterpret_cast<uint64_t*>(&h) = creation_timestamp_rounded;
|
||||
h = crypto::cn_fast_hash(&h, sizeof h);
|
||||
uint64_t h_64 = *reinterpret_cast<uint64_t*>(&h);
|
||||
uint16_t checksum = h_64 % (checksum_max + 1);
|
||||
|
||||
uint8_t auditable_flag = 0;
|
||||
if (m_keys.account_address.flags & ACCOUNT_PUBLIC_ADDRESS_FLAG_AUDITABLE)
|
||||
auditable_flag = 1;
|
||||
|
||||
uint64_t auditable_flag_and_checksum = (auditable_flag & 1) | (checksum << 1);
|
||||
std::string auditable_flag_and_checksum_word = tools::mnemonic_encoding::word_by_num(auditable_flag_and_checksum);
|
||||
|
||||
return keys_seed_text + " " + timestamp_word + " " + auditable_flag_and_checksum_word;
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
bool account_base::restore_keys(const std::string& restore_data)
|
||||
bool account_base::restore_keys(const std::vector<unsigned char>& keys_seed_binary)
|
||||
{
|
||||
//CHECK_AND_ASSERT_MES(restore_data.size() == ACCOUNT_RESTORE_DATA_SIZE, false, "wrong restore data size");
|
||||
if (restore_data.size() == BRAINWALLET_DEFAULT_SEED_SIZE)
|
||||
{
|
||||
crypto::keys_from_default((unsigned char*)restore_data.data(), m_keys.account_address.spend_public_key, m_keys.spend_secret_key, BRAINWALLET_DEFAULT_SEED_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("wrong restore data size=" << restore_data.size());
|
||||
return false;
|
||||
}
|
||||
m_seed = restore_data;
|
||||
CHECK_AND_ASSERT_MES(keys_seed_binary.size() == BRAINWALLET_DEFAULT_SEED_SIZE, false, "wrong restore data size: " << keys_seed_binary.size());
|
||||
crypto::keys_from_default(keys_seed_binary.data(), m_keys.account_address.spend_public_key, m_keys.spend_secret_key, keys_seed_binary.size());
|
||||
crypto::dependent_key(m_keys.spend_secret_key, m_keys.view_secret_key);
|
||||
bool r = crypto::secret_key_to_public_key(m_keys.view_secret_key, m_keys.account_address.view_public_key);
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to secret_key_to_public_key for view key");
|
||||
set_createtime(0);
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
bool account_base::restore_keys_from_braindata(const std::string& restore_data_)
|
||||
bool account_base::restore_keys_from_braindata(const std::string& seed_phrase)
|
||||
{
|
||||
//cut the last timestamp word from restore_dats
|
||||
std::list<std::string> words;
|
||||
boost::split(words, restore_data_, boost::is_space());
|
||||
CHECK_AND_ASSERT_MES(words.size() == BRAINWALLET_DEFAULT_WORDS_COUNT, false, "Words count missmatch: " << words.size());
|
||||
|
||||
std::string timestamp_word = words.back();
|
||||
words.erase(--words.end());
|
||||
|
||||
std::string restore_data_local = boost::algorithm::join(words, " ");
|
||||
boost::split(words, seed_phrase, boost::is_space());
|
||||
|
||||
std::vector<unsigned char> bin = tools::mnemonic_encoding::text2binary(restore_data_local);
|
||||
if (!bin.size())
|
||||
std::string keys_seed_text, timestamp_word, auditable_flag_and_checksum_word;
|
||||
if (words.size() == SEED_PHRASE_V1_WORDS_COUNT)
|
||||
{
|
||||
// 24 seed words + one timestamp word = 25 total
|
||||
timestamp_word = words.back();
|
||||
words.erase(--words.end());
|
||||
keys_seed_text = boost::algorithm::join(words, " ");
|
||||
}
|
||||
else if (words.size() == SEED_PHRASE_V2_WORDS_COUNT)
|
||||
{
|
||||
// 24 seed words + one timestamp word + one flags & checksum = 26 total
|
||||
auditable_flag_and_checksum_word = words.back();
|
||||
words.erase(--words.end());
|
||||
timestamp_word = words.back();
|
||||
words.erase(--words.end());
|
||||
keys_seed_text = boost::algorithm::join(words, " ");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Invalid seed words count: " << words.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t auditable_flag_and_checksum = 0;
|
||||
try
|
||||
{
|
||||
auditable_flag_and_checksum = tools::mnemonic_encoding::num_by_word(auditable_flag_and_checksum_word);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
LOG_ERROR("cannot convert seed word: " << auditable_flag_and_checksum_word);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool auditable_flag = (auditable_flag_and_checksum & 1) != 0; // auditable flag is the lower 1 bit
|
||||
uint16_t checksum = auditable_flag_and_checksum >> 1; // checksum -- everything else
|
||||
constexpr uint16_t checksum_max = tools::mnemonic_encoding::NUMWORDS >> 1; // maximum value of checksum
|
||||
|
||||
std::vector<unsigned char> keys_seed_binary = tools::mnemonic_encoding::text2binary(keys_seed_text);
|
||||
CHECK_AND_ASSERT_MES(keys_seed_binary.size(), false, "text2binary failed to convert the given text"); // don't prints event incorrect seed into the log for security
|
||||
|
||||
std::string restore_buff((const char*)&bin[0], bin.size());
|
||||
bool r = restore_keys(restore_buff);
|
||||
CHECK_AND_ASSERT_MES(r, false, "restore_keys failed");
|
||||
m_creation_timestamp = get_timstamp_from_word(timestamp_word);
|
||||
|
||||
// check the checksum
|
||||
crypto::hash h = crypto::cn_fast_hash(keys_seed_binary.data(), keys_seed_binary.size());
|
||||
*reinterpret_cast<uint64_t*>(&h) = m_creation_timestamp;
|
||||
h = crypto::cn_fast_hash(&h, sizeof h);
|
||||
uint64_t h_64 = *reinterpret_cast<uint64_t*>(&h);
|
||||
uint16_t checksum_calculated = h_64 % (checksum_max + 1);
|
||||
CHECK_AND_ASSERT_MES(checksum == checksum_calculated, false, "seed phase has invalid checksum: " << checksum_calculated << ", while " << checksum << " is expected, check your words");
|
||||
|
||||
bool r = restore_keys(keys_seed_binary);
|
||||
CHECK_AND_ASSERT_MES(r, false, "restore_keys failed");
|
||||
|
||||
m_keys_seed_binary = keys_seed_binary;
|
||||
|
||||
if (auditable_flag)
|
||||
m_keys.account_address.flags |= ACCOUNT_PUBLIC_ADDRESS_FLAG_AUDITABLE;
|
||||
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@
|
|||
|
||||
#define BRAINWALLET_DEFAULT_SEED_SIZE 32
|
||||
#define ACCOUNT_RESTORE_DATA_SIZE BRAINWALLET_DEFAULT_SEED_SIZE
|
||||
#define BRAINWALLET_DEFAULT_WORDS_COUNT 25
|
||||
#define SEED_PHRASE_V1_WORDS_COUNT 25
|
||||
#define SEED_PHRASE_V2_WORDS_COUNT 26
|
||||
|
||||
|
||||
|
||||
|
|
@ -47,15 +48,13 @@ namespace currency
|
|||
{
|
||||
public:
|
||||
account_base();
|
||||
void generate();
|
||||
void generate(bool auditable = false);
|
||||
const account_keys& get_keys() const;
|
||||
const account_public_address& get_public_address() const { return m_keys.account_address; };
|
||||
std::string get_public_address_str() const;
|
||||
std::string get_restore_data() const;
|
||||
|
||||
std::string get_restore_braindata() const;
|
||||
|
||||
bool restore_keys(const std::string& restore_data);
|
||||
bool restore_keys_from_braindata(const std::string& restore_data);
|
||||
bool restore_keys_from_braindata(const std::string& seed_phrase);
|
||||
|
||||
uint64_t get_createtime() const { return m_creation_timestamp; }
|
||||
void set_createtime(uint64_t val) { m_creation_timestamp = val; }
|
||||
|
|
@ -70,20 +69,23 @@ namespace currency
|
|||
{
|
||||
a & m_keys;
|
||||
a & m_creation_timestamp;
|
||||
a & m_seed;
|
||||
a & m_keys_seed_binary;
|
||||
}
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(m_keys)
|
||||
KV_SERIALIZE(m_creation_timestamp)
|
||||
KV_SERIALIZE(m_seed)
|
||||
KV_SERIALIZE(m_keys_seed_binary)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
||||
private:
|
||||
void set_null();
|
||||
bool restore_keys(const std::vector<unsigned char>& keys_seed_binary);
|
||||
|
||||
account_keys m_keys;
|
||||
uint64_t m_creation_timestamp;
|
||||
std::string m_seed;
|
||||
|
||||
std::vector<unsigned char> m_keys_seed_binary;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -426,7 +426,8 @@ namespace currency
|
|||
extra_alias_entry(const extra_alias_entry_old& old)
|
||||
: extra_alias_entry_base(old)
|
||||
, m_alias(old.m_alias)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
std::string m_alias;
|
||||
|
||||
|
|
|
|||
|
|
@ -1251,7 +1251,7 @@ namespace currency
|
|||
{
|
||||
uint64_t date_offset = timestamp > WALLET_BRAIN_DATE_OFFSET ? timestamp - WALLET_BRAIN_DATE_OFFSET : 0;
|
||||
uint64_t weeks_count = date_offset / WALLET_BRAIN_DATE_QUANTUM;
|
||||
CHECK_AND_ASSERT_THROW_MES(weeks_count < std::numeric_limits<uint32_t>::max(), "internal error: unable to converto to uint32, val = " << weeks_count);
|
||||
CHECK_AND_ASSERT_THROW_MES(weeks_count < std::numeric_limits<uint32_t>::max(), "internal error: unable to convert to uint32, val = " << weeks_count);
|
||||
uint32_t weeks_count_32 = static_cast<uint32_t>(weeks_count);
|
||||
|
||||
return tools::mnemonic_encoding::word_by_num(weeks_count_32);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ namespace
|
|||
{
|
||||
const command_line::arg_descriptor<std::string> arg_wallet_file = {"wallet-file", "Use wallet <arg>", ""};
|
||||
const command_line::arg_descriptor<std::string> arg_generate_new_wallet = {"generate-new-wallet", "Generate new wallet and save it to <arg> or <address>.wallet by default", ""};
|
||||
const command_line::arg_descriptor<std::string> arg_generate_new_auditable_wallet = {"generate-new-auditable-wallet", "Generate new auditable wallet and store it to <arg>", ""};
|
||||
const command_line::arg_descriptor<std::string> arg_daemon_address = {"daemon-address", "Use daemon instance at <host>:<port>", ""};
|
||||
const command_line::arg_descriptor<std::string> arg_daemon_host = {"daemon-host", "Use daemon instance at host <arg> instead of localhost", ""};
|
||||
const command_line::arg_descriptor<std::string> arg_password = {"password", "Wallet password", "", true};
|
||||
|
|
@ -270,9 +271,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (m_wallet_file.empty() && m_generate_new.empty() && m_restore_wallet.empty())
|
||||
if (m_wallet_file.empty() && m_generate_new.empty() && m_restore_wallet.empty() && m_generate_new_aw.empty())
|
||||
{
|
||||
fail_msg_writer() << "you must specify --wallet-file, --generate-new-wallet or --restore-wallet";
|
||||
fail_msg_writer() << "you must specify --wallet-file, --generate-new-wallet, --generate-new-auditable-wallet or --restore-wallet";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -311,9 +312,13 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||
|
||||
if (!m_generate_new.empty())
|
||||
{
|
||||
bool r = new_wallet(m_generate_new, pwd_container.password());
|
||||
CHECK_AND_ASSERT_MES(r, false, "account creation failed");
|
||||
|
||||
bool r = new_wallet(m_generate_new, pwd_container.password(), false);
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to create new wallet");
|
||||
}
|
||||
else if (!m_generate_new_aw.empty())
|
||||
{
|
||||
bool r = new_wallet(m_generate_new_aw, pwd_container.password(), true);
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to create new auditable wallet");
|
||||
}
|
||||
else if (!m_restore_wallet.empty())
|
||||
{
|
||||
|
|
@ -354,6 +359,7 @@ void simple_wallet::handle_command_line(const boost::program_options::variables_
|
|||
{
|
||||
m_wallet_file = command_line::get_arg(vm, arg_wallet_file);
|
||||
m_generate_new = command_line::get_arg(vm, arg_generate_new_wallet);
|
||||
m_generate_new_aw = command_line::get_arg(vm, arg_generate_new_auditable_wallet);
|
||||
m_daemon_address = command_line::get_arg(vm, arg_daemon_address);
|
||||
m_daemon_host = command_line::get_arg(vm, arg_daemon_host);
|
||||
m_daemon_port = command_line::get_arg(vm, arg_daemon_port);
|
||||
|
|
@ -374,7 +380,7 @@ bool simple_wallet::try_connect_to_daemon()
|
|||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool simple_wallet::new_wallet(const string &wallet_file, const std::string& password)
|
||||
bool simple_wallet::new_wallet(const string &wallet_file, const std::string& password, bool create_auditable_wallet)
|
||||
{
|
||||
m_wallet_file = wallet_file;
|
||||
|
||||
|
|
@ -383,10 +389,10 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas
|
|||
m_wallet->set_do_rise_transfer(false);
|
||||
try
|
||||
{
|
||||
m_wallet->generate(epee::string_encoding::utf8_to_wstring(m_wallet_file), password);
|
||||
message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " << m_wallet->get_account().get_public_address_str();
|
||||
m_wallet->generate(epee::string_encoding::utf8_to_wstring(m_wallet_file), password, create_auditable_wallet);
|
||||
message_writer(epee::log_space::console_color_white, true) << "Generated new " << (create_auditable_wallet ? "AUDITABLE" : "") << " wallet: " << m_wallet->get_account().get_public_address_str();
|
||||
std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().view_secret_key) << std::endl << std::flush;
|
||||
if(m_do_not_set_date)
|
||||
if (m_do_not_set_date)
|
||||
m_wallet->reset_creation_time(0);
|
||||
|
||||
if (m_print_brain_wallet)
|
||||
|
|
@ -407,11 +413,6 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas
|
|||
success_msg_writer() <<
|
||||
"**********************************************************************\n" <<
|
||||
"Your wallet has been generated.\n" <<
|
||||
"To start synchronizing with the daemon use \"refresh\" command.\n" <<
|
||||
"Use \"help\" command to see the list of available commands.\n" <<
|
||||
"Always use \"exit\" command when closing simplewallet to save\n" <<
|
||||
"current session's state. Otherwise, you will possibly need to synchronize \n" <<
|
||||
"your wallet again. Your wallet key is NOT under risk anyway.\n" <<
|
||||
"**********************************************************************";
|
||||
return true;
|
||||
}
|
||||
|
|
@ -433,7 +434,7 @@ bool simple_wallet::restore_wallet(const std::string &wallet_file, const std::st
|
|||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
fail_msg_writer() << "failed to restore wallet: " << e.what();
|
||||
fail_msg_writer() << "failed to restore wallet, check your seed phrase!" << ENDL << e.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1322,7 +1323,7 @@ bool simple_wallet::print_address(const std::vector<std::string> &args/* = std::
|
|||
bool simple_wallet::show_seed(const std::vector<std::string> &args)
|
||||
{
|
||||
success_msg_writer() << "Here's your wallet's seed phrase. Write it down and keep in a safe place.";
|
||||
success_msg_writer(true) << "Anyone who knows the following 25 words can access your wallet:";
|
||||
success_msg_writer(true) << "Anyone who knows the following 26 words can access your wallet:";
|
||||
std::cout << m_wallet->get_account().get_restore_braindata() << std::endl << std::flush;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1693,6 +1694,8 @@ int main(int argc, char* argv[])
|
|||
const char* const* argv = argv_vec.data();
|
||||
#endif
|
||||
|
||||
epee::debug::get_set_enable_assert(true, false);
|
||||
|
||||
string_tools::set_module_name_and_folder(argv[0]);
|
||||
|
||||
po::options_description desc_general("General options");
|
||||
|
|
@ -1702,6 +1705,7 @@ int main(int argc, char* argv[])
|
|||
po::options_description desc_params("Wallet options");
|
||||
command_line::add_arg(desc_params, arg_wallet_file);
|
||||
command_line::add_arg(desc_params, arg_generate_new_wallet);
|
||||
command_line::add_arg(desc_params, arg_generate_new_auditable_wallet);
|
||||
command_line::add_arg(desc_params, arg_password);
|
||||
command_line::add_arg(desc_params, arg_daemon_address);
|
||||
command_line::add_arg(desc_params, arg_daemon_host);
|
||||
|
|
@ -1848,7 +1852,7 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
LOG_PRINT_L0("Initializing wallet...");
|
||||
wal.init(daemon_address);
|
||||
if (command_line::get_arg(vm, arg_generate_new_wallet).size())
|
||||
if (command_line::get_arg(vm, arg_generate_new_wallet).size() || command_line::get_arg(vm, arg_generate_new_auditable_wallet).size())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!offline_mode)
|
||||
|
|
@ -1903,7 +1907,7 @@ int main(int argc, char* argv[])
|
|||
sw->set_offline_mode(offline_mode);
|
||||
r = sw->init(vm);
|
||||
CHECK_AND_ASSERT_MES(r, 1, "Failed to initialize wallet");
|
||||
if (command_line::get_arg(vm, arg_generate_new_wallet).size())
|
||||
if (command_line::get_arg(vm, arg_generate_new_wallet).size() || command_line::get_arg(vm, arg_generate_new_auditable_wallet).size())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace currency
|
|||
|
||||
bool run_console_handler();
|
||||
|
||||
bool new_wallet(const std::string &wallet_file, const std::string& password);
|
||||
bool new_wallet(const std::string &wallet_file, const std::string& password, bool create_auditable_wallet);
|
||||
bool open_wallet(const std::string &wallet_file, const std::string& password);
|
||||
bool restore_wallet(const std::string &wallet_file, const std::string &restore_seed, const std::string& password);
|
||||
bool close_wallet();
|
||||
|
|
@ -153,6 +153,7 @@ namespace currency
|
|||
private:
|
||||
std::string m_wallet_file;
|
||||
std::string m_generate_new;
|
||||
std::string m_generate_new_aw;
|
||||
std::string m_import_path;
|
||||
|
||||
std::string m_daemon_address;
|
||||
|
|
|
|||
|
|
@ -1997,7 +1997,7 @@ void wallet2::assign_account(const currency::account_base& acc)
|
|||
init_log_prefix();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::generate(const std::wstring& path, const std::string& pass)
|
||||
void wallet2::generate(const std::wstring& path, const std::string& pass, bool auditable_wallet)
|
||||
{
|
||||
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(validate_password(pass), "new wallet generation failed: password contains forbidden characters")
|
||||
clear();
|
||||
|
|
@ -2006,7 +2006,7 @@ void wallet2::generate(const std::wstring& path, const std::string& pass)
|
|||
check_for_free_space_and_throw_if_it_lacks(m_wallet_file);
|
||||
|
||||
m_password = pass;
|
||||
m_account.generate();
|
||||
m_account.generate(auditable_wallet);
|
||||
init_log_prefix();
|
||||
boost::system::error_code ignored_ec;
|
||||
THROW_IF_TRUE_WALLET_EX(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, epee::string_encoding::convert_to_ansii(m_wallet_file));
|
||||
|
|
|
|||
|
|
@ -449,7 +449,7 @@ namespace tools
|
|||
END_SERIALIZE()
|
||||
};
|
||||
void assign_account(const currency::account_base& acc);
|
||||
void generate(const std::wstring& path, const std::string& password);
|
||||
void generate(const std::wstring& path, const std::string& password, bool auditable_wallet);
|
||||
void restore(const std::wstring& path, const std::string& pass, const std::string& restore_key);
|
||||
void load(const std::wstring& path, const std::string& password);
|
||||
void store();
|
||||
|
|
|
|||
|
|
@ -840,7 +840,7 @@ std::string wallets_manager::generate_wallet(const std::wstring& path, const std
|
|||
|
||||
try
|
||||
{
|
||||
w->generate(path, password);
|
||||
w->generate(path, password, false);
|
||||
owr.seed = w->get_account().get_restore_braindata();
|
||||
}
|
||||
catch (const tools::error::file_exists&)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue