Exemple #1
0
 def verify(self) -> bool:
     """
     verifies if this tx is signed by sender' private_key
     """
     try:
         return cryptoutil.verify_transaction_sig(self, self.signature)
     except AssertionError:
         return False
def test_sign_transaction():
    """test that signing and verifying transaction works"""
    private_key = cryptoutil.generate_key()
    sender = cryptoutil.key_to_address(private_key.get_verifying_key())
    receivers = ["fe"]
    amounts = [1]
    fee = 100
    tx = Transaction(sender, receivers, amounts, fee)

    # get the signature
    tx_sig = cryptoutil.get_transaction_sig(private_key, tx)
    # validate transaction
    assert cryptoutil.verify_transaction_sig(tx, tx_sig)
def test_verify_tx():
    """
    tests if a signed transaction can be validated
    we just need the address for this, because address=public_key
    """
    w = wallet.generate_new_wallet()
    sender = w.get_address()
    receivers = ["fe"]
    amounts = [1]
    fee = 100
    t = Transaction(sender, receivers, amounts, fee)
    w.sign_transaction(t)
    assert cryptoutil.verify_transaction_sig(t, t.get_signature())
    assert t.verify()
Exemple #4
0
def test_verify_vtx_signature():
    """
    tests if sender and receiver sigs can be validated seperately and together
    """
    sender_wallet = wallet.generate_new_wallet()
    receiver_wallet = wallet.generate_new_wallet()
    sender = sender_wallet.get_address()
    receiver = receiver_wallet.get_address()
    vt_amount = 100
    nto_amount = 100
    t = VotingTokenTransaction(sender, receiver, vt_amount, nto_amount)
    sender_wallet.sign_vtx_sender(t)
    # verify sender signature
    assert cryptoutil.verify_transaction_sig(
        t, t.get_sender_signature(), t.get_sender())
    # tx not valid because receiver did not sign
    assert False == t.verify()
    # sign with receiver
    receiver_wallet.sign_vtx_receiver(t)
    # should work
    assert cryptoutil.verify_transaction_sig(
        t, t.get_receiver_signature(), t.get_receiver())
    # should also work
    assert t.verify()
Exemple #5
0
 def verify(self)-> bool:
     """
     verifies if this tx is signed by sender_address' private_key
     """
     return cryptoutil.verify_transaction_sig(self, self.signature)
Exemple #6
0
 def verify_receiver_sig(self) -> bool:
     try:
         return cryptoutil.verify_transaction_sig(self, self.receiver_signature, self.receiver)
     except AssertionError:
         return False