Beispiel #1
0
bool matchContact(const fc::ecc::public_key& pk, bts::addressbook::wallet_contact* matchedContact)
{
  assert(pk.valid());

  auto address_book = bts::get_profile()->get_addressbook();
  try
  {
    auto c = address_book->get_contact_by_public_key(pk);
    if(c)
    {
      *matchedContact = *c;
      return true;
    }
    else
    {
      *matchedContact = bts::addressbook::wallet_contact();
      matchedContact->public_key = pk;
      return false;
    }
  }
  catch (const fc::exception&)
  {
    *matchedContact = bts::addressbook::wallet_contact();
    matchedContact->public_key = pk;
    return false;
  }
}
Beispiel #2
0
 address::address( const fc::ecc::public_key& pub )
 {
     auto dat      = pub.serialize();
     auto dat_hash = small_hash(dat.data, sizeof(dat) );
     auto check = fc::ripemd160::hash( (char*)&dat_hash, 16 );
     memcpy( addr.data, (char*)&dat_hash, sizeof(addr) );
     memcpy( &addr.data[16], (char*)&check, 4 );
 }
Beispiel #3
0
 pts_address::pts_address( const fc::ecc::public_key& pub, bool compressed, uint8_t version )
 {
     fc::sha256 sha2;
     if( compressed )
     {
         auto dat = pub.serialize();
         sha2     = fc::sha256::hash(dat.data, sizeof(dat) );
     }
     else
     {
         auto dat = pub.serialize_ecc_point();
         sha2     = fc::sha256::hash(dat.data, sizeof(dat) );
     }
     auto rep      = fc::ripemd160::hash((char*)&sha2,sizeof(sha2));
     addr.data[0]  = version;
     memcpy( addr.data+1, (char*)&rep, sizeof(rep) );
     auto check    = fc::sha256::hash( addr.data, sizeof(rep)+1 );
     check = fc::sha256::hash(check); // double
     memcpy( addr.data+1+sizeof(rep), (char*)&check, 4 );
 }
Beispiel #4
0
 bool operator == ( const public_key_type& p1, const fc::ecc::public_key& p2)
 {
    return p1.key_data == p2.serialize();
 }
Beispiel #5
0
 address::address( const fc::ecc::public_key& pub )
 {
     auto dat = pub.serialize();
     addr = fc::ripemd160::hash( fc::sha512::hash( dat.data, sizeof( dat ) ) );
 }
Beispiel #6
0
 void pack( Stream& s, const fc::ecc::public_key& pk)
 {
     fc::raw::pack( s, pk.serialize() );
 }
Beispiel #7
0
QString toString(const fc::ecc::public_key& pk, TContactTextFormatting contactFormatting,
  bts::addressbook::contact* matchingContact /*= nullptr*/, bool* isKnownContact /*= nullptr*/)
  {
  assert(pk.valid());

  auto address_book = bts::get_profile()->get_addressbook();
  auto c = address_book->get_contact_by_public_key(pk);
  if (c)
    {
    if(matchingContact != nullptr)
      *matchingContact = *c;
    if(isKnownContact != nullptr)
      *isKnownContact = true;

    switch(contactFormatting)
      {
      case KEYHOTEE_IDENTIFIER:
        return QString(c->dac_id_string.c_str());
      case CONTACT_ALIAS_FULL_NAME:
        return QString(std::string(c->first_name + " " + c->last_name).c_str());
      case FULL_CONTACT_DETAILS:
        return QString(c->get_display_name().c_str());
      default:
        assert(false);
        return QString();
      }
    }
  else
    {
    auto profile = bts::get_profile();
    /// If no contact found try one of registered identities.
    std::vector<bts::addressbook::wallet_identity> identities = profile->identities();
    for(const auto& identity : identities)
      {
      assert(identity.public_key.valid());

      if(identity.public_key == pk)
        {
        if(matchingContact != nullptr)
          *matchingContact = identity;
        if(isKnownContact != nullptr)
          *isKnownContact = true;

        switch(contactFormatting)
          {
          case KEYHOTEE_IDENTIFIER:
            return QString::fromStdString(identity.dac_id_string);
          case CONTACT_ALIAS_FULL_NAME:
            return QString::fromStdString(std::string(identity.first_name + " " + identity.last_name));
          case FULL_CONTACT_DETAILS:
            return QString::fromStdString(identity.get_display_name());
          default:
            assert(false);
            return QString();
          }
        break;
        }
      }

    if(matchingContact != nullptr)
      {
      *matchingContact = bts::addressbook::wallet_contact();
      matchingContact->public_key = pk;
      }

    if(isKnownContact != nullptr)
      *isKnownContact = false;

    /// If code reached this point the publick key is unknown - lets display it as base58
    return QString::fromStdString(pk.to_base58());
    }
  }
Beispiel #8
0
 void pack( Stream& s, const fc::ecc::public_key& pk, uint32_t _max_depth )
 {
     FC_ASSERT( _max_depth > 0 );
     fc::raw::pack( s, pk.serialize(), _max_depth - 1 );
 }