diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index 426ce09f7093ec6fc5cc33d5771fad7223022b13..b81f1c5ed2ee3807e9b9b8090632e1dc63a7e3ec 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -8,12 +8,13 @@ from ucoinpy import PROTOCOL_VERSION from ucoinpy.api import bma from ucoinpy.api.bma import ConnectionHandler from ucoinpy.documents.peer import Peer -from ucoinpy.documents.certification import Certification +from ucoinpy.documents.certification import SelfCertification, Certification from ucoinpy.key import SigningKey +from ..tools.exceptions import PersonNotFoundError import logging import hashlib -import base64 +import time from .wallet import Wallet from .community import Community @@ -162,8 +163,19 @@ class Account(object): return False return True - def send_pubkey(self, community): - return community.send_pubkey(self) + def send_pubkey(self, password, community): + selfcert = SelfCertification(PROTOCOL_VERSION, + community.currency, + self.pubkey, + int(time.time()), + self.name, + None) + key = SigningKey(self.salt, password) + selfcert.sign([key]) + logging.debug("Key publish : {0}".format(selfcert.signed_raw())) + community.post(bma.wot.Add, {}, {'pubkey': self.pubkey, + 'self_': selfcert.signed_raw(), + 'other': []}) def send_membership_in(self, community): return community.send_membership(self, "IN") diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index 7c9caddb45b546e8d3e9558c4618ebeb824c39df..f081ebce08c04df507951c7d0f3fdda0d54bf3ff 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -104,6 +104,7 @@ class Application(object): json_data = open(account_path, 'r') data = json.load(json_data) account = Account.load(data) + account.name = name self.accounts.append(account) self.save(account) diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index 5138b40576df28cf5b0c6603f6ec6cab105bb268..2b6e24afdfe146f2d7ade405694209f4be33c936 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -62,9 +62,6 @@ class Community(object): req_args={'number': block_number}) return block['dividend'] - def send_pubkey(self, account): - pass - def send_membership(self, account, membership): pass diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index a1c032a04270ae40bea9df7a325046aee93bf42a..64ffea2ad902df169a0e54edfa4c42520a531bfc 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -10,7 +10,6 @@ from ucoinpy.documents.transaction import InputSource, OutputSource, Transaction from ucoinpy.key import SigningKey from ..tools.exceptions import NotEnoughMoneyError import logging -import base64 class Wallet(object): diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index 2ca575f64ee70845338069602d78e774f79f2eeb..2b6a43834ed840a3e6035fa3c32811077630750e 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -81,7 +81,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): dialog.radio_pubkey.setChecked(True) dialog.exec_() - def certify_member(self,): + def certify_member(self): dialog = CertificationDialog(self.account) person = self.sender().data() dialog.edit_pubkey.setText(person.pubkey) diff --git a/src/cutecoin/gui/process_cfg_account.py b/src/cutecoin/gui/process_cfg_account.py index 55f46f02c65ec0dcbe27fa8fd43ab018f62bbf35..c6e05b840775cfaefd52164e4d6a029c2c3f6692 100644 --- a/src/cutecoin/gui/process_cfg_account.py +++ b/src/cutecoin/gui/process_cfg_account.py @@ -163,9 +163,8 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog): def action_remove_community(self): for index in self.list_communities.selectedIndexes(): - community = self.account.communities.communitiesList[index.row()] - self.account.wallets.removeAllWalletsOf(community) - self.account.communities.communitiesList.pop(index.row()) + community = self.account.communities[index.row()] + self.account.communities.pop(index.row()) self.list_communities.setModel(CommunitiesListModel(self.account)) diff --git a/src/cutecoin/gui/process_cfg_community.py b/src/cutecoin/gui/process_cfg_community.py index 1a7163cbef3c2e60300130ae08c8d93f8b586382..e82ea849d9f9362ed15b6a87cb31178cb0bad3a8 100644 --- a/src/cutecoin/gui/process_cfg_community.py +++ b/src/cutecoin/gui/process_cfg_community.py @@ -10,7 +10,7 @@ from ucoinpy.api.bma import ConnectionHandler from ucoinpy.documents.peer import Peer from cutecoin.gen_resources.community_cfg_uic import Ui_CommunityConfigurationDialog -from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QWidget, QAction +from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QInputDialog, QLineEdit from PyQt5.QtCore import QSignalMapper from cutecoin.models.peering import PeeringTreeModel from cutecoin.core.person import Person @@ -166,9 +166,19 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): {0}\n \ Would you like to publish the key ?".format(self.account.pubkey)) if reply == QMessageBox.Yes: + password = "" + + while not self.account.check_password(password): + password = QInputDialog.getText(self, "Account password", + "Wrong password.\nPlease enter your password", + QLineEdit.Password) + if password[1] is True: + password = password[0] + else: + return try: - self.account.send_pubkey(self.community) - except Error as e: + self.account.send_pubkey(password, self.community) + except ValueError as e: QMessageBox.critical(self, "Pubkey publishing error", e.message) else: diff --git a/src/cutecoin/tools/exceptions.py b/src/cutecoin/tools/exceptions.py index 110da3da830c12b5f2621b21affbbf2369fd1052..246f94edb81d5d2b495ca9aba3b372c6f9729d93 100644 --- a/src/cutecoin/tools/exceptions.py +++ b/src/cutecoin/tools/exceptions.py @@ -75,7 +75,7 @@ class KeyAlreadyUsed(Error): super() .__init__( "Cannot add account " + new_account.name + - " : the pgpKey " + + " : the key " + keyid + " is already used by " + found_account.name)