Пример #1
0
 def _stamp_has_valid_wallet_signature(self):
     signature_bytes = self._evidence_of_decentralized_identity
     if signature_bytes is constants.NOT_SIGNED:
         return False
     else:
         signature = EthSignature(signature_bytes)
     proper_pubkey = signature.recover_public_key_from_msg(bytes(self.stamp))
     proper_address = proper_pubkey.to_checksum_address()
     return proper_address == self.checksum_public_address
Пример #2
0
def test_blockchain_ursula_substantiates_stamp(blockchain_ursulas):
    first_ursula = list(blockchain_ursulas)[0]
    signature_as_bytes = first_ursula._evidence_of_decentralized_identity
    signature = EthSignature(signature_bytes=signature_as_bytes)
    proper_public_key_for_first_ursula = signature.recover_public_key_from_msg(bytes(first_ursula.stamp))
    proper_address_for_first_ursula = proper_public_key_for_first_ursula.to_checksum_address()
    assert proper_address_for_first_ursula == first_ursula.checksum_public_address

    # This method is a shortcut for the above.
    assert first_ursula._stamp_has_valid_wallet_signature
Пример #3
0
    def verify_message(self, address: str, pubkey: bytes, message: bytes, signature_bytes: bytes):
        """
        Verifies that the message was signed by the keypair.
        """
        # Check that address and pubkey match
        eth_pubkey = PublicKey(pubkey)
        signature = EthSignature(signature_bytes=signature_bytes)
        if not eth_pubkey.to_checksum_address() == address:
            raise ValueError("Pubkey address ({}) doesn't match the provided address ({})".format(eth_pubkey.to_checksum_address, address))

        hashed_message = keccak(message)

        if not self.blockchain.interface.call_backend_verify(
                eth_pubkey, signature, hashed_message):
            raise PowerUpError("Signature is not valid for this message or pubkey.")
        else:
            return True