Пример #1
0
 def test_full_tx_verifying(self):
     tx = make_tx()
     tx.invoker = "something"
     full_hash, signature = crypto.sign_transaction(blake2b, secp256k1, key, tx)
     tx.signature = signature
     tx.full_hash = full_hash
     self.assertTrue(crypto.verify_full_transaction(blake2b, secp256k1, key.pubkey, tx))
     valid_tx = copy.deepcopy(tx)
     tx.payload = "forged"
     self.assertFalse(crypto.verify_full_transaction(blake2b, secp256k1, key.pubkey, tx))
     tx = copy.deepcopy(valid_tx)
     tx.invoker = "forged"
     self.assertFalse(crypto.verify_full_transaction(blake2b, secp256k1, key.pubkey, tx))
     tx = copy.deepcopy(valid_tx)
     tx.signature = "MEQCIF+o3DHBiTbpw8X6W4/yOuPF/FfANIiNnG0mFLgjBAjuAiAe/QAHN8ufmHMeRvHFItdrzVHFORGED4/msipzFORGED=="
     self.assertFalse(crypto.verify_full_transaction(blake2b, secp256k1, key.pubkey, tx))
Пример #2
0
    def verify_full_transaction(
            self, full_tx: "transaction_model.TransactionModel") -> bool:
        """Verify a full transaction
        Args:
            full_tx: TransactionModel to verify
        Returns:
            Boolean if valid signed and hashed transaction
        Raises:
            exceptions.InvalidNodeLevel when self is not level 1
            RuntimeError when no public key is set on self
        """
        if self.level != 1:
            raise exceptions.InvalidNodeLevel(
                "Transactions only exist on level 1 nodes")
        if self.pub is None:
            raise RuntimeError("No public key has been set for verifying")

        return crypto.verify_full_transaction(self.hash, self.encryption,
                                              self.pub, full_tx)