PublicKeyType withdraw_with_escrow::encrypt_memo_data( const fc::ecc::private_key& one_time_private_key, const fc::ecc::public_key& to_public_key, const fc::ecc::private_key& from_private_key, const std::string& memo_message, const fc::ecc::public_key& memo_pub_key, MemoFlagsEnum memo_type) { memo = TransferMemo(); const auto secret = one_time_private_key.get_shared_secret(to_public_key); const auto ext_to_public_key = ExtendedPublicKey(to_public_key); const auto secret_ext_public_key = ext_to_public_key.child(fc::sha256::hash(secret)); const auto secret_public_key = secret_ext_public_key.get_pub_key(); sender = Address(one_time_private_key.get_public_key()); receiver = Address(secret_public_key); fc::sha512 check_secret; if (from_private_key.get_secret() != fc::ecc::private_key().get_secret()) check_secret = from_private_key.get_shared_secret(secret_public_key); MemoData memo_content; memo_content.set_message(memo_message); memo_content.from = memo_pub_key; memo_content.from_signature = check_secret._hash[0]; memo_content.memo_flags = memo_type; memo->one_time_key = one_time_private_key.get_public_key(); encrypt_memo_data(secret, memo_content); return secret_public_key; }
public_key_type withdraw_with_signature::encrypt_memo_data( const fc::ecc::private_key& one_time_private_key, const fc::ecc::public_key& to_public_key, const fc::ecc::private_key& from_private_key, const std::string& memo_message, const fc::ecc::public_key& memo_pub_key, memo_flags_enum memo_type ) { memo = titan_memo(); const auto secret = one_time_private_key.get_shared_secret( to_public_key ); const auto ext_to_public_key = extended_public_key( to_public_key ); const auto secret_ext_public_key = ext_to_public_key.child( fc::sha256::hash( secret ) ); const auto secret_public_key = secret_ext_public_key.get_pub_key(); owner = address( secret_public_key ); fc::sha512 check_secret; if( from_private_key.get_secret() != fc::ecc::private_key().get_secret() ) check_secret = from_private_key.get_shared_secret( secret_public_key ); memo_data memo_content; memo_content.set_message( memo_message ); memo_content.from = memo_pub_key; memo_content.from_signature = check_secret._hash[0]; memo_content.memo_flags = memo_type; memo->one_time_key = one_time_private_key.get_public_key(); encrypt_memo_data( secret, memo_content ); return secret_public_key; }
std::string key_to_wif(const fc::ecc::private_key& key) { fc::sha256 secret = key.get_secret(); const size_t size_of_data_to_hash = sizeof(secret) + 1; const size_t size_of_hash_bytes = 4; char data[size_of_data_to_hash + size_of_hash_bytes]; data[0] = (char)0x80; memcpy(&data[1], (char*)&secret, sizeof(secret)); fc::sha256 digest = fc::sha256::hash(data, size_of_data_to_hash); digest = fc::sha256::hash(digest); memcpy(data + size_of_data_to_hash, (char*)&digest, size_of_hash_bytes); return fc::to_base58(data, sizeof(data)); }
void pack( Stream& s, const fc::ecc::private_key& pk) { fc::raw::pack( s, pk.get_secret() ); }
extended_private_key( const fc::ecc::private_key& k ):priv_key(k.get_secret()){}
void pack( Stream& s, const fc::ecc::private_key& pk, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); fc::raw::pack( s, pk.get_secret(), _max_depth - 1 ); }
std::string key_to_wif(const fc::ecc::private_key& key) { return key_to_wif( key.get_secret() ); }
fc::process_ptr launch_bts_client_process(uint32_t process_number, uint16_t rpc_port, const fc::ecc::private_key& trustee_key, bool act_as_trustee) { fc::process_ptr bts_client_process(std::make_shared<fc::process>()); std::vector<std::string> options; std::ostringstream numbered_config_dir_name; numbered_config_dir_name << "BitSharesX_" << std::setw(3) << std::setfill('0') << process_number; fc::path numbered_config_dir = bts_xt_client_test_config::config_directory / numbered_config_dir_name.str(); fc::remove_all(numbered_config_dir); fc::create_directories(numbered_config_dir); // create a wallet in that directory // we could (and probably should) make bts_xt_client create the wallet, // but if we ask it to create the wallet // it will interactively prompt for passwords which is a big hassle. // here we explicitly create one with a blank password { bts::wallet::wallet_ptr wallet = std::make_shared<bts::wallet::wallet>(); wallet->set_data_directory(numbered_config_dir); fc::path wallet_data_filename = wallet->get_wallet_file(); wallet->create(wallet_data_filename, "", WALLET_PASPHRASE); } options.push_back("--data-dir"); options.push_back(numbered_config_dir.string()); options.push_back("--server"); options.push_back("--rpcuser="******"--rpcpassword="******"--rpcport"); options.push_back(boost::lexical_cast<std::string>(rpc_port)); options.push_back("--trustee-address"); options.push_back(bts::blockchain::address(trustee_key.get_public_key())); if (act_as_trustee) { options.push_back("--trustee-private-key"); options.push_back(trustee_key.get_secret()); } bts_client_process->exec(bts_xt_client_test_config::bts_client_exe, options, numbered_config_dir); #if 0 std::shared_ptr<std::ofstream> stdouterrfile = std::make_shared<std::ofstream>((numbered_config_dir / "stdouterr.txt").string().c_str()); fc::buffered_istream_ptr out_stream = bts_client_process->out_stream(); fc::buffered_istream_ptr err_stream = bts_client_process->err_stream(); server_process_info->stdout_reader_done = fc::async([out_stream,stdouterrfile]() { char buf[1024]; for (;;) { size_t bytes_read = out_stream->readsome(buf, sizeof(buf)); if (!bytes_read) break; stdouterrfile->write(buf, bytes_read); } }); server_process_info->stderr_reader_done = fc::async([err_stream,stdouterrfile]() { char buf[1024]; for (;;) { size_t bytes_read = err_stream->readsome(buf, sizeof(buf)); if (!bytes_read) break; stdouterrfile->write(buf, bytes_read); } }); #endif return bts_client_process; }