Example #1
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() }
Example #2
0
   private_key_type wallet_db::generate_new_account_child_key( const fc::sha512& password, const string& account_name )
   { try {
       FC_ASSERT( is_open() );

       owallet_account_record account_record = lookup_account( account_name );
       FC_ASSERT( account_record.valid(), "Account not found!" );
       FC_ASSERT( !account_record->is_retracted(), "Account has been retracted!" );
       FC_ASSERT( account_record->is_my_account, "Not my account!" );

       const owallet_key_record key_record = lookup_key( address( account_record->active_key() ) );
       FC_ASSERT( key_record.valid(), "Active key not found!" );
       FC_ASSERT( key_record->has_private_key(), "Active private key not found!" );

       const private_key_type active_private_key = key_record->decrypt_private_key( password );
       uint32_t seq_num = account_record->last_used_gen_sequence;
       private_key_type account_child_private_key;
       public_key_type account_child_public_key;
       address account_child_address;
       while( true )
       {
           ++seq_num;
           FC_ASSERT( seq_num != 0, "Overflow!" );

           account_child_private_key = get_account_child_key( active_private_key, seq_num );
           account_child_public_key = account_child_private_key.get_public_key();
           account_child_address = address( account_child_public_key );

           owallet_key_record key_record = lookup_key( account_child_address );
           if( key_record.valid() && key_record->has_private_key() ) continue;

           break;
       }

       account_record->last_used_gen_sequence = seq_num;

       key_data key;
       key.account_address = account_record->owner_address();
       key.public_key = account_child_public_key;
       key.encrypt_private_key( password, account_child_private_key );
       key.gen_seq_number = seq_num;

       store_account( *account_record );
       store_key( key );

       return account_child_private_key;
   } FC_CAPTURE_AND_RETHROW( (account_name) ) }
Example #3
0
   private_key_type wallet_db::generate_new_account_child_key( const fc::sha512& password, const string& account_name,
                                                               const account_key_type parent_key_type )
   { try {
       FC_ASSERT( is_open() );

       owallet_account_record account_record = lookup_account( account_name );
       FC_ASSERT( account_record.valid(), "Account not found!" );
       FC_ASSERT( !account_record->is_retracted(), "Account has been retracted!" );

       public_key_type parent_public_key;
       switch( parent_key_type )
       {
           case account_key_type::owner_key:
               parent_public_key = account_record->owner_key;
               break;
           case account_key_type::active_key:
               parent_public_key = account_record->active_key();
               break;
           case account_key_type::signing_key:
               FC_ASSERT( account_record->is_delegate() );
               parent_public_key = account_record->signing_key();
               break;
           // No default to force compiler warning
       }

       const owallet_key_record parent_key_record = lookup_key( address( parent_public_key ) );
       FC_ASSERT( parent_key_record.valid(), "Parent key not found!" );
       FC_ASSERT( parent_key_record->has_private_key(), "Parent private key not found!" );

       const private_key_type parent_private_key = parent_key_record->decrypt_private_key( password );
       uint32_t child_key_index = account_record->last_child_key_index;
       private_key_type account_child_private_key;
       public_key_type account_child_public_key;
       address account_child_address;
       while( true )
       {
           ++child_key_index;
           FC_ASSERT( child_key_index != 0, "Overflow!" );

           account_child_private_key = get_account_child_key( parent_private_key, child_key_index );
           account_child_public_key = account_child_private_key.get_public_key();
           account_child_address = address( account_child_public_key );

           owallet_key_record child_key_record = lookup_key( account_child_address );
           if( child_key_record.valid() && child_key_record->has_private_key() ) continue;

           break;
       }

       account_record->last_child_key_index = child_key_index;

       key_data child_key;
       child_key.account_address = account_record->owner_address();
       child_key.child_key_index = child_key_index;
       child_key.public_key = account_child_public_key;
       child_key.encrypt_private_key( password, account_child_private_key );

       store_account( *account_record );
       store_key( child_key );

       return account_child_private_key;
   } FC_CAPTURE_AND_RETHROW( (account_name) ) }