void NewIdentityDialog::onUserNameChanged( const QString& name ) { if( name != QString() ) { auto pro = bts::application::instance()->get_profile(); auto keys = pro->get_keychain(); auto trim_name = fc::trim(name.toUtf8().constData()); auto ident_key = keys.get_identity_key( trim_name ); auto key_addr = /*bts::*/public_key_address( ident_key.get_public_key() ); ui->publickey->setText( std::string(key_addr).c_str() ); // make sure the key is unique.. try { bts::addressbook::wallet_identity cur_ident = pro->get_identity( trim_name ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); ui->status_label->setText( tr( "Status: You have already created this identity." ) ); } catch ( fc::key_not_found_exception& e ) { ui->status_label->setText( tr( "Status: Unknown" ) ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(true); } } else { ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); } }
void ContactView::refreshDialog(const Contact &contact) { /** TODO... restore this kind of check if( _current_contact.bit_id_public_key != _current_contact.public_key ) { ui->id_status->setText( tr( "Warning! Keyhotee ID %1 no longer matches known public key!" ).arg(_current_contact.bit_id) ); } */ ui->firstname->setText( contact.first_name.c_str() ); ui->lastname->setText( contact.last_name.c_str() ); //set public key from contact record initially std::string public_key_string = public_key_address( contact.public_key ); ui->khid_pubkey->setPublicKey( public_key_string.c_str() ); //set keyhoteeID from contact record, this may override public key from contact record //if mining is enabled and ID is registered in blockchain ui->khid_pubkey->setKeyhoteeID(contact.dac_id_string.c_str()); ui->icon_view->setIcon( contact.getIcon() ); ui->notes->setPlainText( contact.notes.c_str() ); //ui->email->setText( _current_contact.email_address ); //ui->phone->setText( _current_contact.phone_number ); //privacy_comboBox //DLNFIX TODO: add check to see if we are synced on blockchain. If not synched, // display "Keyhotee ledger not accessible" checkKeyhoteeIdStatus(); }
void ContactView::ToDialog() { if (isAddingNewContact ()) { setValid(false); ui->firstname->setText(""); ui->lastname->setText(""); ui->khid_pubkey->setKeyhoteeID(""); ui->icon_view->setIcon( QIcon(":/images/user.png") ); ui->notes->setPlainText(""); ui->email->setText(""); ui->phone->setText(""); ui->khid_pubkey->setPublicKey(""); ui->privacy_comboBox->setCurrentIndex (0); ui->contact_pages->setCurrentIndex(info); } else { setValid(true); /** TODO... restore this kind of check if( _current_contact.bit_id_public_key != _current_contact.public_key ) { ui->id_status->setText( tr( "Warning! Keyhotee ID %1 no longer matches known public key!" ).arg(_current_contact.bit_id) ); } */ ui->firstname->setText( _current_contact.first_name.c_str() ); ui->lastname->setText( _current_contact.last_name.c_str() ); //set public key from contact record initially std::string public_key_string = public_key_address( _current_contact.public_key ); ui->khid_pubkey->setPublicKey( public_key_string.c_str() ); //set keyhoteeID from contact record, this may override public key from contact record //if mining is enabled and ID is registered in blockchain ui->khid_pubkey->setKeyhoteeID(_current_contact.dac_id_string.c_str()); ui->icon_view->setIcon( _current_contact.getIcon() ); ui->notes->setPlainText( _current_contact.notes.c_str() ); //ui->email->setText( _current_contact.email_address ); //ui->phone->setText( _current_contact.phone_number ); //privacy_comboBox //DLNFIX TODO: add check to see if we are synced on blockchain. If not synched, // display "Keyhotee ledger not accessible" checkKeyhoteeIdStatus(); bool is_owner = _current_contact.isOwn(); ui->keyhoteeID_status->setVisible(!_editing && is_owner); ui->authorization_status->setVisible(!_editing && !is_owner); ui->mining_effort->setVisible(is_owner); ui->mining_effort_slider->setVisible(is_owner); ui->mining_effort_slider->setDisabled(!_editing); ui->mining_effort_label->setVisible(is_owner); ui->mining_effort_label_2->setVisible(is_owner); } setEnabledSaveContact(); }
void ContactView::onRequestContact() { RequestAuthorization *request = new RequestAuthorization(this, *getKeyhoteeWindow()->getConnectionProcessor()); if(!ui->khid_pubkey->getKeyhoteeID().isEmpty() && gMiningIsPossible) request->setKeyhoteeID(_current_contact.dac_id_string.c_str()); else { std::string public_key_string = public_key_address(_current_contact.public_key.serialize()); request->setPublicKey(public_key_string.c_str()); } request->enableAddContact(false); request->setAddressBook(_address_book); request->show(); }
void NewIdentityDialog::onUserNameChanged( const QString& name ) { if( name.trimmed() != QString() ) { auto pro = bts::application::instance()->get_profile(); auto keys = pro->get_keychain(); auto trim_name = fc::trim(name.toUtf8().constData()); auto ident_key = keys.get_identity_key( trim_name ); auto key_addr = /*bts::*/public_key_address( ident_key.get_public_key() ); ui->publickey->setText( std::string(key_addr).c_str() ); // make sure the key is unique.. try { bts::addressbook::wallet_identity cur_ident = pro->get_identity( trim_name ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); ui->status_label->setStyleSheet("QLabel { color : red; }"); if (cur_ident.dac_id_string == trim_name) ui->status_label->setText( tr( "Status: You have already created this identity." ) ); else ui->status_label->setText( tr( "Status: You have already created a similar id." ) ); } catch ( fc::key_not_found_exception& ) { fc::optional<bts::bitname::name_record> current_record = bts::application::instance()->lookup_name(trim_name); if(current_record) { ui->status_label->setStyleSheet("QLabel { color : red; }"); ui->status_label->setText(tr("Status: This Keyhotee ID was already registered by someone else.")); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); } else { ui->status_label->setStyleSheet("QLabel { color : black; }"); ui->status_label->setText( tr( "Status: Unknown" ) ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(true); } } catch ( fc::assert_exception& ) { ui->status_label->setStyleSheet("QLabel { color : red; }"); ui->status_label->setText(tr("Status: Invalid ID. This ID cannot be registered.")); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); } } else { ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); } }
/** Allows to validate given keyStr before creating a public key object. \param keyStr - public key textual representation to be validated Returns true if given key is ok, false otherwise. */ static bool is_valid(const std::string& inputKeyStr, bool* keySemanticallyValid = nullptr) { /// \warning public key checker/decoder asserts if input string contains national characters std::string keyStr; Utils::convertToASCII(inputKeyStr, &keyStr); bool status = false; if(keySemanticallyValid != nullptr) *keySemanticallyValid = false; try { std::vector<char> bin = fc::from_base58(keyStr); status = bin.size() == 37; if(status) { /** Looks like fc::from_base58 is insufficient - it can accept invalid key values. To be sure just try to construct actual public_key object. */ fc::ecc::public_key_data rawData; memcpy( (char*)&rawData, bin.data(), 33); fc::ecc::public_key checker(rawData); if (checker.valid() && keySemanticallyValid) { std::string public_key_string_check = public_key_address(rawData); if (public_key_string_check == inputKeyStr) { *keySemanticallyValid = true; } } return checker.valid(); } } catch (const fc::exception&) { status = false; } return status; }
bool ContactView::existContactWithPublicKey (const std::string& public_key_string) { std::string my_public_key = public_key_address( _current_contact.public_key ); if (public_key_string != my_public_key) { auto addressbook = bts::get_profile()->get_addressbook(); if(! public_key_string.size()==0) { public_key_address key_address(public_key_string); auto findContact = addressbook->get_contact_by_public_key( key_address.key ); if (findContact) { ui->id_status->setText( tr("This contact is already added to the list") ); ui->id_status->setStyleSheet("QLabel { color : red; }"); return true; } } } return false; }
fc::string register_key_on_server(const QString& keyhotee_id, const QString& key) { fc::string trimmed_keyhotee_id = keyhotee_id.trimmed().toStdString(); fc::string trimmed_key = key.trimmed().toStdString(); auto pro = bts::application::instance()->get_profile(); auto keys = pro->get_keychain(); auto ident_key = keys.get_identity_key( trimmed_keyhotee_id ); std::string key_addr = public_key_address( ident_key.get_public_key() ); fc::tcp_socket_ptr sock = std::make_shared<fc::tcp_socket>(); sock->connect_to( fc::ip::endpoint( fc::ip::address("162.243.67.4"), 3879 ) ); fc::buffered_istream_ptr isock = std::make_shared<fc::buffered_istream>(sock); fc::buffered_ostream_ptr osock = std::make_shared<fc::buffered_ostream>(sock); fc::rpc::json_connection_ptr con = std::make_shared<fc::rpc::json_connection>( isock, osock ); con->exec(); auto result = con->async_call( "register_key", trimmed_keyhotee_id, trimmed_key, key_addr ).wait(); auto points = result.get_object()["points"].as_string(); auto pub = result.get_object()["pub_key"].as_string(); return points; }
void ContactvCard::convert(const Contact& contact, QByteArray* vCardData) { vCard vcard; vCardProperty name_prop = vCardProperty::createName(contact.first_name.c_str(), contact.last_name.c_str()); vcard.addProperty(name_prop); QString formattedName = contact.first_name.c_str() + QString(" ") + contact.last_name.c_str(); name_prop = vCardProperty::createdFormattedName(formattedName); vcard.addProperty(name_prop); name_prop = vCardProperty::createKHID(contact.dac_id_string.c_str()); vcard.addProperty(name_prop); std::string public_key_string = public_key_address(contact.public_key); name_prop = vCardProperty::createPublicKey(public_key_string.c_str()); vcard.addProperty(name_prop); name_prop = vCardProperty::createNotes(contact.getNotes()); vcard.addProperty(name_prop); *vCardData = vcard.toByteArray(); }
void NewIdentityDialog::onKey( const QString& key ) { try { auto pro = bts::application::instance()->get_profile(); auto keys = pro->get_keychain(); auto trim_name = fc::trim(ui->username->text().toStdString()); auto ident_key = keys.get_identity_key( trim_name ); std::string key_addr = public_key_address( ident_key.get_public_key() ); fc::tcp_socket_ptr sock = std::make_shared<fc::tcp_socket>(); sock->connect_to( fc::ip::endpoint( fc::ip::address("162.243.67.4"), 3879 ) ); fc::buffered_istream_ptr isock = std::make_shared<fc::buffered_istream>(sock); fc::buffered_ostream_ptr osock = std::make_shared<fc::buffered_ostream>(sock); fc::rpc::json_connection_ptr con = std::make_shared<fc::rpc::json_connection>( isock, osock ); con->exec(); auto trim_key = key.trimmed(); auto result = con->async_call( "register_key", trim_name, trim_key.toStdString(), key_addr ).wait(); auto points = result.get_object()["points"].as_string(); auto pub = result.get_object()["pub_key"].as_string(); fc::usleep(fc::seconds(1)); ui->status_label->setText( ("Status: Registered with " + points + " points").c_str() ); } catch ( fc::eof_exception& ) { } catch ( fc::exception& e ) { ui->status_label->setText( ("Status: Error Registering Founder ID: " + e.to_detail_string()).c_str() ); } catch ( ... ) { ui->status_label->setText( "Status: Error Registering Founder ID" ); } }
void ContactView::lookupId() { try { std::string current_id = ui->id_edit->text().toUtf8().constData(); setValid (false); if (current_id.empty() ) { ui->id_status->setText(QString() ); return; } _current_record = bts::application::instance()->lookup_name(current_id); if (_current_record) { ui->id_status->setStyleSheet("QLabel { color : green; }"); ui->id_status->setText(tr("Registered") ); std::string public_key_string = public_key_address(_current_record->active_key); ui->public_key->setText(public_key_string.c_str() ); if (_address_book != nullptr) { if (! existContactWithPublicKey (public_key_string)) setValid (true); } } else { ui->id_status->setStyleSheet("QLabel { color : red; }"); ui->id_status->setText(tr("Unable to find ID") ); ui->public_key->setText(QString()); } } catch (const fc::exception& e) { ui->id_status->setText(e.to_string().c_str() ); } }
void KeyhoteeMainWindow::addToContacts(const bts::addressbook::wallet_contact& wallet_contact) { addContact(); std::string public_key_string = public_key_address(wallet_contact.public_key); ui->new_contact->setPublicKey(public_key_string.c_str()); }
QString toString(const fc::ecc::public_key& pk, TContactTextFormatting contactFormatting, bts::addressbook::contact* matchingContact /*= 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; 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; switch(contactFormatting) { case KEYHOTEE_IDENTIFIER: return QString(identity.dac_id_string.c_str()); case CONTACT_ALIAS_FULL_NAME: return QString(std::string(identity.first_name + " " + identity.last_name).c_str()); case FULL_CONTACT_DETAILS: return QString(identity.get_display_name().c_str()); default: assert(false); return QString(); } break; } } if(matchingContact != nullptr) { *matchingContact = bts::addressbook::wallet_contact(); matchingContact->public_key = pk; } /// If code reached this point the publick key is unknown - lets display it as base58 std::string public_key_string = public_key_address(pk); return QString(public_key_string.c_str()); } }
bool ContactView::doDataExchange (bool valid) { if (! valid) { if (isAddingNewContact ()) { setValid(false); ui->firstname->setText(""); ui->lastname->setText(""); ui->id_edit->setText(""); ui->icon_view->setIcon( QIcon(":/images/user.png") ); ui->notes->setPlainText(""); ui->email->setText(""); ui->phone->setText(""); ui->public_key->setText (""); ui->privacy_comboBox->setCurrentIndex (0); ui->contact_pages->setCurrentIndex(info); if (gMiningIsPossible) ui->id_status->setText(tr("Please provide a valid ID or public key") ); else ui->id_status->setText(tr("Public Key Only Mode") ); } else { setValid(true); /** TODO... restore this kind of check if( _current_contact.bit_id_public_key != _current_contact.public_key ) { ui->id_status->setText( tr( "Warning! Keyhotee ID %1 no longer matches known public key!" ).arg(_current_contact.bit_id) ); } */ ui->firstname->setText( _current_contact.first_name.c_str() ); ui->lastname->setText( _current_contact.last_name.c_str() ); ui->id_edit->setText( _current_contact.dac_id_string.c_str() ); ui->icon_view->setIcon( _current_contact.getIcon() ); ui->notes->setPlainText( _current_contact.notes.c_str() ); //ui->email->setText( _current_contact.email_address ); //ui->phone->setText( _current_contact.phone_number ); //privacy_comboBox std::string public_key_string = public_key_address( _current_contact.public_key ); ui->public_key->setText( public_key_string.c_str() ); ui->keyhotee_founder->setVisible(!_editing && _current_contact.isKeyhoteeFounder()); //DLNFIX TODO: add check to see if we are synced on blockchain. If not synched, // display "Keyhotee ledger not accessible" bool is_owner = _current_contact.isOwn(); if(is_owner) { ui->mining_effort_slider->setValue( static_cast<int>(_current_contact.getMiningEffort())); //if registered keyhoteeId auto name_record = bts::application::instance()->lookup_name(_current_contact.dac_id_string); if (name_record) { // if keyhoteeId's public key matches ours. if (name_record->active_key == _current_contact.public_key) { //Registered to us ui->keyhoteeID_status->setStyleSheet("QLabel { background-color : green; color : black; }"); ui->keyhoteeID_status->setText(tr("Registered")); } else //Not Available (someone else owns it) { ui->keyhoteeID_status->setStyleSheet("QLabel { background-color : red; color : black; }"); ui->keyhoteeID_status->setText(tr("Not Available")); } } else //Unregistered (no one has it yet) { ui->keyhoteeID_status->setStyleSheet("QLabel { background-color : yellow; color : black; }"); ui->keyhoteeID_status->setText(tr("Unregistered")); } } ui->keyhoteeID_status->setVisible(!_editing && is_owner); ui->mining_effort->setVisible(is_owner); ui->mining_effort_slider->setVisible(is_owner); ui->mining_effort_slider->setDisabled(!_editing); ui->mining_effort_label->setVisible(is_owner); ui->mining_effort_label_2->setVisible(is_owner); ui->id_status->setText(QString()); } } else { _current_contact.first_name = ui->firstname->text().toUtf8().constData(); _current_contact.last_name = ui->lastname->text().toUtf8().constData(); _current_contact.dac_id_string = ui->id_edit->text().toUtf8().constData(); _current_contact.setIcon (ui->icon_view->icon()); _current_contact.notes = ui->notes->toPlainText().toUtf8().constData(); //_current_contact.email_address = ui->email->text().toStdString(); //_current_contact.phone_number = ui->phone->text().toStdString(); //privacy_comboBox } setEnabledSaveContact (); return true; }
bool ContactView::doDataExchange (bool valid) { if (! valid) { if (isAddingNewContact ()) { setValid(false); ui->firstname->setText(""); ui->lastname->setText(""); ui->id_edit->setText(""); ui->icon_view->setIcon( QIcon(":/images/user.png") ); ui->notes->setPlainText(""); ui->email->setText(""); ui->phone->setText(""); ui->public_key->setText (""); ui->privacy_comboBox->setCurrentIndex (0); ui->contact_pages->setCurrentIndex(info); if (gMiningIsPossible) ui->id_status->setText(tr("Please provide a valid ID or public key") ); else ui->id_status->setText(tr("Public Key Only Mode") ); } else { setValid(true); /** TODO... restore this kind of check if( _current_contact.bit_id_public_key != _current_contact.public_key ) { ui->id_status->setText( tr( "Warning! Keyhotee ID %1 no longer matches known public key!" ).arg(_current_contact.bit_id) ); } */ ui->firstname->setText( _current_contact.first_name.c_str() ); ui->lastname->setText( _current_contact.last_name.c_str() ); ui->id_edit->setText( _current_contact.dac_id_string.c_str() ); ui->icon_view->setIcon( _current_contact.getIcon() ); ui->notes->setPlainText( _current_contact.notes.c_str() ); //ui->email->setText( _current_contact.email_address ); //ui->phone->setText( _current_contact.phone_number ); //privacy_comboBox std::string public_key_string = public_key_address( _current_contact.public_key ); ui->public_key->setText( public_key_string.c_str() ); ui->keyhotee_founder->setVisible(!_editing && _current_contact.isKeyhoteeFounder()); ui->id_status->setText(QString()); } } else { _current_contact.first_name = ui->firstname->text().toUtf8().constData(); _current_contact.last_name = ui->lastname->text().toUtf8().constData(); _current_contact.dac_id_string = ui->id_edit->text().toUtf8().constData(); _current_contact.setIcon (ui->icon_view->icon()); _current_contact.notes = ui->notes->toPlainText().toUtf8().constData(); //_current_contact.email_address = ui->email->text().toStdString(); //_current_contact.phone_number = ui->phone->text().toStdString(); //privacy_comboBox } setEnabledSaveContact (); return true; }