Ejemplo n.º 1
0
    def compute_and_cast_vote(consensus_id, fromaddress, answerNo,
                              previous_vote_hash):
        """
        Generates the answer message with linkable ring signature and posts
        it using ConsensusProtocol.post_message(message).
        
        This method should be invoked by
        shared.workerQueue.put( ("castVote", ( consensus_id, fromaddress, answerNo, previous_vote_hash ) ) ) 
        """
        log_debug("compute_and_cast_vote(%d, %s, %d)" %
                  (consensus_id, fromaddress, answerNo))
        cp = ConsensusProtocol.read_from_id(consensus_id)
        if cp is None:
            return None
        cp.update_status_bar("Computing vote...")

        # We can allow votes to be cast up until the commitment phase started.
        # It can happen that a user queues the vote in the work queue just before
        # the deadline, and the posting window closes in the meantime.
        # We still want the vote to be sent.
        if cp.get_status() > ConsensusProtocol.STATUS_COMMITMENT_PHASE:
            return None

        if answerNo < 0 or answerNo >= len(cp.data.answers):
            raise Exception('Invalid answer number: %d' % answerNo)

        if fromaddress not in cp.data.addresses:
            raise Exception(
                'Vote casting address not in list of voter addresses! (%s)' %
                fromaddress)

        privSigningKey = helper_keys.getPrivateSigningKey(fromaddress)
        if privSigningKey is None:
            raise Exception(
                "Vote: We don't have the private keys for address %s" %
                fromaddress)
        privSigningKey = arithmetic.decode(privSigningKey, 256)

        signer_index = cp.data.addresses.index(fromaddress)

        message = VotingData.encode_vote(answerNo, previous_vote_hash)

        rs = RingSignature.sign_message(message, cp.data.signing_keys,
                                        privSigningKey, signer_index)
        c0, ss, Y_tilde = rs

        data = VotingData.encode_ring_signature(message, c0, ss, Y_tilde)
        message_hash = cp.post_message(data)
        cp.update_status_bar('')
        cp.data.settings_set_already_voted_address(fromaddress, message_hash)
        cp.refresh_ui()
    def compute_and_cast_vote(consensus_id, fromaddress, answerNo, previous_vote_hash):
        """
        Generates the answer message with linkable ring signature and posts
        it using ConsensusProtocol.post_message(message).
        
        This method should be invoked by
        shared.workerQueue.put( ("castVote", ( consensus_id, fromaddress, answerNo, previous_vote_hash ) ) ) 
        """
        log_debug("compute_and_cast_vote(%d, %s, %d)" % ( consensus_id, fromaddress, answerNo ) )
        cp = ConsensusProtocol.read_from_id( consensus_id )
        if cp is None:
            return None
        cp.update_status_bar( "Computing vote..." )
        
        # We can allow votes to be cast up until the commitment phase started.
        # It can happen that a user queues the vote in the work queue just before
        # the deadline, and the posting window closes in the meantime.
        # We still want the vote to be sent.
        if cp.get_status() > ConsensusProtocol.STATUS_COMMITMENT_PHASE:
            return None
        
        if answerNo < 0 or answerNo >= len( cp.data.answers ):
            raise Exception( 'Invalid answer number: %d' % answerNo )
        
        if fromaddress not in cp.data.addresses:
            raise Exception( 'Vote casting address not in list of voter addresses! (%s)' % fromaddress )

        privSigningKey = helper_keys.getPrivateSigningKey( fromaddress )
        if privSigningKey is None:
            raise Exception( "Vote: We don't have the private keys for address %s" % fromaddress )
        privSigningKey = arithmetic.decode( privSigningKey, 256 )
        
        signer_index = cp.data.addresses.index( fromaddress )
        
        message = VotingData.encode_vote( answerNo, previous_vote_hash )

        rs = RingSignature.sign_message(message, cp.data.signing_keys, privSigningKey, signer_index)
        c0, ss, Y_tilde = rs
        
        data = VotingData.encode_ring_signature( message, c0, ss, Y_tilde)
        message_hash = cp.post_message( data )
        cp.update_status_bar( '' )
        cp.data.settings_set_already_voted_address( fromaddress, message_hash )
        cp.refresh_ui()
 def pubkey_to_point(curve, pubkey):
     assert len( pubkey ) == 64
     return ec_point.Point( curve,
                            x=arithmetic.decode( pubkey[:32], 256 ), 
                            y=arithmetic.decode( pubkey[32:], 256 ) )
     
Ejemplo n.º 4
0
 def pubkey_to_point(curve, pubkey):
     assert len(pubkey) == 64
     return ec_point.Point(curve,
                           x=arithmetic.decode(pubkey[:32], 256),
                           y=arithmetic.decode(pubkey[32:], 256))