Ejemplo n.º 1
0
    void domain_transfer_operation::titan_transfer( 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();
        auto secret = one_time_private_key.get_shared_secret( to_public_key );
        auto ext_to_public_key = extended_public_key(to_public_key);
        auto secret_ext_public_key = ext_to_public_key.child( fc::sha256::hash(secret) );
        auto secret_public_key = secret_ext_public_key.get_pub_key();
        owner = address( secret_public_key );

        auto 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();

        FC_ASSERT( memo.valid() );
        memo->encrypted_memo_data = fc::aes_encrypt( secret, fc::raw::pack( memo_content ) );
    }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
   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;
   }
Ejemplo n.º 4
0
    omemo_status domain_transfer_operation::decrypt_memo_data( const fc::ecc::private_key& receiver_key ) const
    { try {
        FC_ASSERT( memo.valid() );
//      ilog( "receiver_key: ${r}", ("r",receiver_key) );
        auto secret = receiver_key.get_shared_secret( memo->one_time_key );
//      ilog( "secret: ${secret}", ("secret",secret) );
        extended_private_key ext_receiver_key(receiver_key);
 //     ilog( "ext_receiver_key: ${key}",("key",ext_receiver_key) );
      
        fc::ecc::private_key secret_private_key = ext_receiver_key.child( fc::sha256::hash(secret), 
                                                                          extended_private_key::public_derivation );
   //   ilog( "secret_private_key: ${k}", ("k",secret_private_key)  );
        auto secret_public_key = secret_private_key.get_public_key();
    //  ilog( "secret_public_key: ${k}", ("k",secret_public_key)  );

        if( owner != address(secret_public_key) )
            return omemo_status();

     // ilog( "owner: ${o} == ${address}", ("o",owner)("address",address(secret_public_key)) );
        auto memo = decrypt_memo_data( secret );

        bool has_valid_signature = false;
        if( memo.memo_flags == from_memo )
        {
            auto check_secret = secret_private_key.get_shared_secret( memo.from );
            has_valid_signature = check_secret._hash[0] == memo.from_signature;
        }
        else
        {
            has_valid_signature = true;
        }

        return memo_status( memo, has_valid_signature, secret_private_key );
   } FC_RETHROW_EXCEPTIONS( warn, "" ) }
Ejemplo n.º 5
0
   omemo_status withdraw_with_signature::decrypt_memo_data( const fc::ecc::private_key& receiver_key, bool ignore_owner )const
   { try {
      try {
         FC_ASSERT( memo.valid() );
         auto secret = receiver_key.get_shared_secret( memo->one_time_key );
         extended_private_key ext_receiver_key(receiver_key);

         fc::ecc::private_key secret_private_key = ext_receiver_key.child( fc::sha256::hash(secret),
                                                                           extended_private_key::public_derivation );
         auto secret_public_key = secret_private_key.get_public_key();

         if( !ignore_owner && owner != address( secret_public_key ) )
            return omemo_status();

         auto memo = decrypt_memo_data( secret );

         bool has_valid_signature = false;
         if( memo.memo_flags == from_memo && !( memo.from == public_key_type() && memo.from_signature == 0 ) )
         {
            auto check_secret = secret_private_key.get_shared_secret( memo.from );
            has_valid_signature = check_secret._hash[0] == memo.from_signature;
         }
         else
         {
            has_valid_signature = true;
         }

         return memo_status( memo, has_valid_signature, secret_private_key );
      }
      catch ( const fc::aes_exception& e )
      {
         return omemo_status();
      }
   } FC_CAPTURE_AND_RETHROW( (ignore_owner) ) }
Ejemplo n.º 6
0
 encrypted_message message::encrypt( const fc::ecc::private_key& onetimekey,
                                     const fc::ecc::public_key&  receiver_public_key )const
 {
    auto shared_secret = onetimekey.get_shared_secret( receiver_public_key );
    encrypted_message result;
    result.onetimekey = onetimekey.get_public_key();
    result.data = fc::aes_encrypt( shared_secret, fc::raw::pack( *this ) );
    return  result;
 }
Ejemplo n.º 7
0
 message encrypted_message::decrypt( const fc::ecc::private_key& e )const
 {
    auto shared_secret = e.get_shared_secret(onetimekey);
    return decrypt(shared_secret);
 }