Example #1
0
def verify_signature(signed_transaction):
    """Verify the signature of a transaction

    A valid transaction should have been signed `current_owner` corresponding private key.

    Args:
        signed_transaction (dict): a transaction with the `signature` included.

    Returns:
        bool: True if the signature is correct, False otherwise.
    """

    data = signed_transaction.copy()

    # if assignee field in the transaction, remove it
    if 'assignee' in data:
        data.pop('assignee')

    signatures = data.pop('signatures')
    for public_key_base58 in signed_transaction['transaction'][
            'current_owners']:
        public_key = PublicKey(public_key_base58)

        if isinstance(signatures, list):
            try:
                signature = [
                    s['signature'] for s in signatures
                    if s['public_key'] == public_key_base58
                ]
            except KeyError:
                return False
            if not len(signature) == 1:
                return False
            signature = signature[0]
        else:
            signature = signatures
        if not public_key.verify(serialize(data), signature):
            return False
    return True
Example #2
0
    def verify_signature(self, signed_transaction):
        """Verify the signature of a transaction

        A valid transaction should have been signed `current_owner` corresponding private key.

        Args:
            signed_transaction (dict): a transaction with the `signature` included.

        Returns:
            bool: True if the signature is correct, False otherwise.

        """
        data = signed_transaction.copy()

        # if assignee field in the transaction, remove it
        if 'assignee' in data:
            data.pop('assignee')

        signature = data.pop('signature')
        public_key_base58 = signed_transaction['transaction']['current_owner']
        public_key = PublicKey(public_key_base58)
        return public_key.verify(self.serialize(data), signature)
Example #3
0
 def test_sign_verify(self):
     message = 'Hello World!'
     public_key = PublicKey(self.PUBLIC_VALUE_COMPRESSED_B58)
     private_key = PrivateKey(self.PRIVATE_VALUE_B58)
     assert public_key.verify(message, private_key.sign(message)) is True
 def test_sign_verify(self):
     message = 'Hello World!'
     public_key = PublicKey(self.PUBLIC_VALUE_COMPRESSED_B58)
     private_key = PrivateKey(self.PRIVATE_VALUE_B58)
     assert public_key.verify(message, private_key.sign(message)) == True