Exemple #1
0
    def create(cls, walletid, salt, password, name):
        '''
        Factory method to create a new wallet

        :param int walletid: The wallet number, unique between all wallets
        :param str salt: The account salt
        :param str password: The account password
        :param str name: The account name
        '''
        if walletid == 0:
            key = SigningKey(salt, password)
        else:
            key = SigningKey("{0}{1}".format(salt, walletid), password)
        return cls(walletid, key.pubkey, name)
Exemple #2
0
    def check_password(self, salt, password):
        '''
        Check if wallet password is ok.

        :param salt: The account salt
        :param password: The given password
        :return: True if (salt, password) generates the good public key
        .. warning:: Generates a new temporary SigningKey from salt and password
        '''
        key = None
        if self.walletid == 0:
            key = SigningKey(salt, password)
        else:
            key = SigningKey("{0}{1}".format(salt, self.walletid), password)
        return (key.pubkey == self.pubkey)
Exemple #3
0
    def revoke(self, password, community):
        """
        Revoke self-identity on server, not in blockchain

        :param str password: The account SigningKey password
        :param cutecoin.core.community.Community community: The community target of the revocation
        """
        revoked = Person.lookup(self.pubkey, community)

        revocation = Revocation(PROTOCOL_VERSION, community.currency, None)

        selfcert = revoked.selfcert(community)

        key = SigningKey(self.salt, password)
        revocation.sign(selfcert, [key])

        logging.debug("Self-Revocation Document : \n{0}".format(
            revocation.raw(selfcert)))
        logging.debug("Signature : \n{0}".format(revocation.signatures[0]))

        data = {
            'pubkey': revoked.pubkey,
            'self_': selfcert.signed_raw(),
            'sig': revocation.signatures[0]
        }
        logging.debug("Posted data : {0}".format(data))
        community.broadcast(bma.wot.Revoke, {}, data)
Exemple #4
0
    def certify(self, password, community, pubkey):
        """
        Certify an other identity

        :param str password: The account SigningKey password
        :param cutecoin.core.community.Community community: The community target of the certification
        :param str pubkey: The certified identity pubkey
        """
        certified = Person.lookup(pubkey, community)
        blockid = community.current_blockid()

        certification = Certification(PROTOCOL_VERSION, community.currency,
                                      self.pubkey, certified.pubkey,
                                      blockid['number'], blockid['hash'], None)

        selfcert = certified.selfcert(community)
        logging.debug("SelfCertification : {0}".format(selfcert.raw()))

        key = SigningKey(self.salt, password)
        certification.sign(selfcert, [key])
        signed_cert = certification.signed_raw(selfcert)
        logging.debug("Certification : {0}".format(signed_cert))

        data = {
            'pubkey': certified.pubkey,
            'self_': selfcert.signed_raw(),
            'other': "{0}\n".format(certification.inline())
        }
        logging.debug("Posted data : {0}".format(data))
        community.broadcast(bma.wot.Add, {}, data)
 def action_show_pubkey(self):
     salt = self.edit_salt.text()
     password = self.edit_password.text()
     pubkey = SigningKey(salt, password).pubkey
     QMessageBox.information(
         self, self.tr("Public key"),
         self.tr("These parameters pubkeys are : {0}").format(pubkey))
 def process_next(self):
     salt = self.config_dialog.edit_salt.text()
     password = self.config_dialog.edit_password.text()
     self.config_dialog.account.salt = salt
     self.config_dialog.account.pubkey = SigningKey(salt, password).pubkey
     self.config_dialog.password_asker = PasswordAskerDialog(
         self.config_dialog.account)
     model = CommunitiesListModel(self.config_dialog.account)
     self.config_dialog.list_communities.setModel(model)
Exemple #7
0
    def check_password(self, password):
        '''
        Method to verify the key password validity

        :param str password: The key password
        :return: True if the generated pubkey is the same as the account
        .. warnings:: Generates a new temporary SigningKey
        '''
        key = SigningKey(self.salt, password)
        return (key.pubkey == self.pubkey)
Exemple #8
0
    def send_selfcert(self, password, community):
        '''
        Send our self certification to a target community

        :param str password: The account SigningKey password
        :param community: The community target of the self certification
        '''
        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.broadcast(bma.wot.Add, {}, {
            'pubkey': self.pubkey,
            'self_': selfcert.signed_raw(),
            'other': []
        })
Exemple #9
0
    def send_membership(self, password, community, mstype):
        '''
        Send a membership document to a target community

        :param str password: The account SigningKey password
        :param community: The community target of the membership document
        :param str mstype: The type of membership demand. "IN" to join, "OUT" to leave
        '''
        self_ = Person.lookup(self.pubkey, community)
        selfcert = self_.selfcert(community)

        blockid = community.current_blockid()

        membership = Membership(PROTOCOL_VERSION, community.currency,
                                selfcert.pubkey, blockid['number'],
                                blockid['hash'], mstype, selfcert.uid,
                                selfcert.timestamp, None)
        key = SigningKey(self.salt, password)
        membership.sign([key])
        logging.debug("Membership : {0}".format(membership.signed_raw()))
        community.broadcast(bma.blockchain.Membership, {},
                            {'membership': membership.signed_raw()})
Exemple #10
0
    def send_money(self, salt, password, community, recipient, amount,
                   message):
        '''
        Send money to a given recipient in a specified community

        :param str salt: The account salt
        :param str password: The account password
        :param community: The community target of the transfer
        :param str recipient: The pubkey of the recipient
        :param int amount: The amount of money to transfer
        :param str message: The message to send with the transfer
        '''
        time = community.get_block().mediantime
        block_number = community.current_blockid()['number']
        block = community.request(bma.blockchain.Block,
                                  req_args={'number': block_number})
        txid = len(block['transactions'])
        key = None
        logging.debug("Key : {0} : {1}".format(salt, password))
        if self.walletid == 0:
            key = SigningKey(salt, password)
        else:
            key = SigningKey("{0}{1}".format(salt, self.walletid), password)
        logging.debug("Sender pubkey:{0}".format(key.pubkey))

        try:
            issuer_uid = Person.lookup(key.pubkey, community).uid
        except PersonNotFoundError:
            issuer_uid = ""

        try:
            receiver_uid = Person.lookup(recipient, community).uid
        except PersonNotFoundError:
            receiver_uid = ""

        metadata = {
            'block': block_number,
            'time': time,
            'amount': amount,
            'issuer': key.pubkey,
            'issuer_uid': issuer_uid,
            'receiver': recipient,
            'receiver_uid': receiver_uid,
            'comment': message,
            'txid': txid
        }
        transfer = Transfer.initiate(metadata)

        self.caches[community.currency]._transfers.append(transfer)

        result = self.tx_inputs(int(amount), community)
        inputs = result[0]
        self.caches[community.currency].available_sources = result[1]
        logging.debug("Inputs : {0}".format(inputs))

        outputs = self.tx_outputs(recipient, amount, inputs)
        logging.debug("Outputs : {0}".format(outputs))
        tx = Transaction(PROTOCOL_VERSION, community.currency, [self.pubkey],
                         inputs, outputs, message, None)
        logging.debug("TX : {0}".format(tx.raw()))

        tx.sign([key])
        logging.debug("Transaction : {0}".format(tx.signed_raw()))
        transfer.send(tx, community)