Esempio n. 1
0
   public_key_type wallet_db::generate_new_account( const fc::sha512& password, const string& account_name,
                                                    const private_key_type& owner_private_key )
   { try {
       FC_ASSERT( is_open() );

       owallet_account_record account_record = lookup_account( account_name );
       FC_ASSERT( !account_record.valid(), "Wallet already contains an account with that name!" );

       const public_key_type owner_public_key = owner_private_key.get_public_key();
       const address owner_address = address( owner_public_key );

       const private_key_type active_private_key = get_account_child_key( owner_private_key, 0 );
       const public_key_type active_public_key = active_private_key.get_public_key();
       const address active_address = address( active_public_key );

       account_record = lookup_account( owner_address );
       FC_ASSERT( !account_record.valid(), "Wallet already contains an account with that key!" );

       account_record = lookup_account( active_address );
       FC_ASSERT( !account_record.valid(), "Wallet already contains an account with the new derived active key!" );

       owallet_key_record key_record = lookup_key( owner_address );
       FC_ASSERT( !key_record.valid() || !key_record->has_private_key(), "Wallet already contains that key!" );

       key_record = lookup_key( active_address );
       FC_ASSERT( !key_record.valid() || !key_record->has_private_key(), "Wallet already contains the new derived active key!" );

       key_data active_key;
       active_key.account_address = owner_address;
       active_key.public_key = active_public_key;
       active_key.encrypt_private_key( password, active_private_key );

       key_data owner_key;
       owner_key.account_address = owner_address;
       owner_key.public_key = owner_public_key;
       owner_key.encrypt_private_key( password, owner_private_key );

       account_data account;
       account.name = account_name;
       account.owner_key = owner_public_key;
       account.set_active_key( blockchain::now(), active_public_key );
       account.last_update = blockchain::now();

       store_key( active_key );
       store_key( owner_key );
       store_account( account );

       return owner_public_key;
   } FC_CAPTURE_AND_RETHROW( (account_name) ) }
Esempio n. 2
0
signature_type graphene::chain::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id)const
{
   digest_type::encoder enc;
   fc::raw::pack( enc, chain_id );
   fc::raw::pack( enc, *this );
   return key.sign_compact(enc.result());
}
Esempio n. 3
0
   private_key_type wallet_db::generate_new_one_time_key( const fc::sha512& password )
   { try {
       FC_ASSERT( is_open() );
       const private_key_type one_time_private_key = private_key_type::generate();

       const address one_time_address = address( one_time_private_key.get_public_key() );
       const owallet_key_record key_record = lookup_key( one_time_address );
       FC_ASSERT( !key_record.valid() );

       key_data key;
       key.public_key = one_time_private_key.get_public_key();
       key.encrypt_private_key( password, one_time_private_key );
       store_key( key );

       return one_time_private_key;
   } FC_CAPTURE_AND_RETHROW() }
Esempio n. 4
0
 void wallet_db::cache_memo( const memo_status& memo,
                             const private_key_type& account_key,
                             const fc::sha512& password )
 {
    key_data data;
    data.account_address = address( account_key.get_public_key() );
    data.public_key = memo.owner_private_key.get_public_key();
    data.encrypt_private_key( password, memo.owner_private_key );
    data.valid_from_signature = memo.has_valid_signature;
    //data.memo = memo_data( memo );
    store_key( data );
 }
Esempio n. 5
0
   void wallet_db::import_key( const fc::sha512& password, const string& account_name, const private_key_type& private_key,
                               bool move_existing )
   { try {
       FC_ASSERT( is_open() );

       owallet_account_record account_record = lookup_account( account_name );
       FC_ASSERT( account_record.valid(), "Account name not found!" );

       const public_key_type public_key = private_key.get_public_key();

       owallet_key_record key_record = lookup_key( address( public_key ) );
       if( !key_record.valid() )
           key_record = wallet_key_record();
       else if( !move_existing )
           FC_ASSERT( key_record->account_address == account_record->owner_address() );

       key_record->account_address = account_record->owner_address();
       key_record->public_key = public_key;
       key_record->encrypt_private_key( password, private_key );

       store_key( *key_record );
   } FC_CAPTURE_AND_RETHROW( (account_name)(move_existing) ) }
Esempio n. 6
0
signature_type signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id)const {
   return key.sign(sig_digest(chain_id, context_free_data));
}
Esempio n. 7
0
   void wallet_db::repair_records( const fc::sha512& password )
   { try {
       FC_ASSERT( is_open() );

       vector<generic_wallet_record> records;
       for( auto iter = my->_records.begin(); iter.valid(); ++iter )
           records.push_back( iter.value() );

       // Repair key_data.account_address when possible
       uint32_t count = 0;
       for( generic_wallet_record& record : records )
       {
           try
           {
               if( wallet_record_type_enum( record.type ) == account_record_type )
               {
                   std::cout << "\rRepairing account record " << std::to_string( ++count ) << std::flush;
                   wallet_account_record account_record = record.as<wallet_account_record>();
                   store_account( account_record );
               }
           }
           catch( const fc::exception& )
           {
           }
       }

       // Repair key_data.public_key when I have the private key and remove if I don't have the private key
       count = 0;
       for( generic_wallet_record& record : records )
       {
           try
           {
               if( wallet_record_type_enum( record.type ) == key_record_type )
               {
                   std::cout << "\rRepairing key record     " << std::to_string( ++count ) << std::flush;
                   wallet_key_record key_record = record.as<wallet_key_record>();
                   const address key_address = key_record.get_address();
                   if( key_record.has_private_key() )
                   {
                       const private_key_type private_key = key_record.decrypt_private_key( password );
                       const public_key_type public_key = private_key.get_public_key();
                       if( key_record.public_key != public_key )
                       {
                           keys.erase( key_address );
                           btc_to_bts_address.erase( key_address );
                           btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 0  ) ) );
                           btc_to_bts_address.erase( address( pts_address( key_record.public_key, true,  0  ) ) );
                           btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 56 ) ) );
                           btc_to_bts_address.erase( address( pts_address( key_record.public_key, true,  56 ) ) );

                           key_record.public_key = public_key;
                           my->load_key_record( key_record );
                       }
                   }
                   else
                   {
                       keys.erase( key_address );
                       btc_to_bts_address.erase( key_address );
                       btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 0  ) ) );
                       btc_to_bts_address.erase( address( pts_address( key_record.public_key, true,  0  ) ) );
                       btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 56 ) ) );
                       btc_to_bts_address.erase( address( pts_address( key_record.public_key, true,  56 ) ) );
                       remove_item( key_record.wallet_record_index );
                       continue;
                   }
                   store_key( key_record );
               }
           }
           catch( const fc::exception& )
           {
           }
       }

       // Repair transaction_data.record_id
       count = 0;
       for( generic_wallet_record& record : records )
       {
           try
           {
               if( wallet_record_type_enum( record.type ) == transaction_record_type )
               {
                   std::cout << "\rRepairing transaction record     " << std::to_string( ++count ) << std::flush;
                   wallet_transaction_record transaction_record = record.as<wallet_transaction_record>();
                   if( transaction_record.trx.id() != signed_transaction().id()  )
                   {
                       const transaction_id_type record_id = transaction_record.trx.id();
                       if( transaction_record.record_id != record_id )
                       {
                           transactions.erase( transaction_record.record_id );
                           id_to_transaction_record_index.erase( transaction_record.record_id );

                           transaction_record.record_id = record_id;
                           my->load_transaction_record( transaction_record );
                       }
                   }
                   store_transaction( transaction_record );
               }
           }
           catch( const fc::exception& )
           {
           }
       }
       std::cout << "\rWallet records repaired.                                  " << std::flush << "\n";
   } FC_CAPTURE_AND_RETHROW() }
Esempio n. 8
0
   void wallet_db::repair_records( const fc::sha512& password )
   { try {
       FC_ASSERT( is_open() );

       vector<generic_wallet_record> records;
       for( auto iter = my->_records.begin(); iter.valid(); ++iter )
           records.push_back( iter.value() );

       // Repair account_data.is_my_account and key_data.account_address
       for( generic_wallet_record& record : records )
       {
           try
           {
               if( wallet_record_type_enum( record.type ) == account_record_type )
               {
                   wallet_account_record account_record = record.as<wallet_account_record>();
                   store_account( account_record );
               }
           }
           catch( ... )
           {
           }
       }

       // Repair key_data.public_key when I have the private key and
       // repair key_data.account_address and account_data.is_my_account
       for( generic_wallet_record& record : records )
       {
           try
           {
               if( wallet_record_type_enum( record.type ) == key_record_type )
               {
                   wallet_key_record key_record = record.as<wallet_key_record>();
                   if( key_record.has_private_key() )
                   {
                       const private_key_type private_key = key_record.decrypt_private_key( password );
                       const public_key_type public_key = private_key.get_public_key();
                       if( key_record.public_key != public_key )
                       {
                           const address key_address = key_record.get_address();
                           keys.erase( key_address );
                           btc_to_bts_address.erase( key_address );
                           btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 0  ) ) );
                           btc_to_bts_address.erase( address( pts_address( key_record.public_key, true,  0  ) ) );
                           btc_to_bts_address.erase( address( pts_address( key_record.public_key, false, 56 ) ) );
                           btc_to_bts_address.erase( address( pts_address( key_record.public_key, true,  56 ) ) );

                           key_record.public_key = public_key;
                           my->load_key_record( key_record );
                       }
                   }
                   store_key( key_record );
               }
           }
           catch( ... )
           {
           }
       }

       // Repair transaction_data.record_id
       for( generic_wallet_record& record : records )
       {
           try
           {
               if( wallet_record_type_enum( record.type ) == transaction_record_type )
               {
                   wallet_transaction_record transaction_record = record.as<wallet_transaction_record>();
                   if( transaction_record.trx.id() != signed_transaction().id()  )
                   {
                       const transaction_id_type record_id = transaction_record.trx.permanent_id();
                       if( transaction_record.record_id != record_id )
                       {
                           transactions.erase( transaction_record.record_id );
                           id_to_transaction_record_index.erase( transaction_record.record_id );

                           transaction_record.record_id = record_id;
                           my->load_transaction_record( transaction_record );
                       }
                   }
                   store_transaction( transaction_record );
               }
           }
           catch( ... )
           {
           }
       }
   } FC_CAPTURE_AND_RETHROW() }