コード例 #1
0
 def test_transaction_creation(self):
     # Create transaction and check if used ordered dict
     t = Transaction("1234", "4567")
     o_dict = OrderedDict({"addr_from": "1234"})
     o_dict["addr_to"] = "4567"
     self.assertTrue(type(t.get_json()) == type(o_dict))
     self.assertDictEqual(t.get_json(), o_dict)
コード例 #2
0
 def validate_transaction(self, transaction):
     """
     Validate that a transaction signature corresponds to the provided data
     """
     t_sig = b64decode(transaction["signature"].encode())
     pubkey = b64decode(transaction["pubkey"].encode())
     verifier = PKCS1_v1_5.new(RSA.importKey(pubkey))
     digest = SHA256.new()
     t = Transaction(transaction["addr_from"], transaction["addr_to"])
     digest.update(str(t.get_json()).encode())
     verified = verifier.verify(digest, t_sig)
     if verified:
         return True
     else:
         logger.info("Signature is invalid")
     return False
コード例 #3
0
    def test_transaction_signature(self):
        # Create transaction
        t = Transaction("1234", "4567")
        # Create Private Key
        key = RSA.generate(1024)
        # Sign transaction and recover complete transaction JSON
        signed_json = t.get_signed_json(key)

        # Verify signature and public key match
        t_sig = b64decode(signed_json["signature"].encode())
        pubkey = b64decode(signed_json["pubkey"].encode())
        verifier = PKCS1_v1_5.new(RSA.importKey(pubkey))
        digest = SHA256.new()
        t = Transaction(signed_json["addr_from"], signed_json["addr_to"])
        digest.update(str(t.get_json()).encode())

        self.assertTrue(verifier.verify(digest, t_sig))