Beispiel #1
0
    def __init__(self):
        crypto = ECCrypto()
        key_requester = crypto.generate_key(u"curve25519")
        key_responder = crypto.generate_key(u"curve25519")

        # Random payload but unique numbers.
        sequence_number_requester = random.randint(50, 100)
        sequence_number_responder = random.randint(101, 200)
        up = random.randint(201, 220)
        down = random.randint(221, 240)
        total_up_requester = random.randint(241, 260)
        total_down_requester = random.randint(261, 280)
        total_up_responder = random.randint(281, 300)
        total_down_responder = random.randint(301, 320)

        # A random hash is generated for the previous hash. It is only used to test if a hash can be persisted.
        previous_hash_requester = sha256(str(random.randint(0,
                                                            100000))).digest()
        public_key_requester = crypto.key_to_bin(key_requester.pub())
        signature_requester = crypto.create_signature(
            key_requester,
            encode_signing_format([
                up, down, total_up_requester, total_down_requester,
                sequence_number_requester, previous_hash_requester
            ]))
        # A random hash is generated for the  hash.
        # TODO: Use the actual hash
        hash_requester = sha256(str(random.randint(0, 100000))).digest()
        # A random hash is generated for the previous hash. It is only used to test if a hash can be persisted.
        previous_hash_responder = sha256(str(random.randint(100001,
                                                            200000))).digest()
        public_key_responder = crypto.key_to_bin(key_responder.pub())
        signature_responder = crypto.create_signature(
            key_responder,
            encode_signing_format([
                up, down, total_up_requester, total_down_requester,
                sequence_number_requester, previous_hash_requester,
                total_up_responder, total_down_responder,
                sequence_number_responder, previous_hash_responder
            ]))
        # A random hash is generated for the  hash.
        # TODO: Use the actual hash
        hash_responder = sha256(str(random.randint(0, 100000))).digest()

        DatabaseBlock.__init__(
            self, (public_key_requester, public_key_responder, up, down,
                   total_up_requester, total_down_requester,
                   sequence_number_requester, previous_hash_requester,
                   signature_requester, hash_requester, total_up_responder,
                   total_down_responder, sequence_number_responder,
                   previous_hash_responder, signature_responder,
                   hash_responder, None))
Beispiel #2
0
 def sign(self, key):
     """
     Signs this block with the given key
     :param key: the key to sign this block with
     """
     crypto = ECCrypto()
     self.signature = crypto.create_signature(key, self.pack(signature=False))
Beispiel #3
0
 def sign(self, member):
     """
     Sign this tick using a private key.
     :param member: The member that signs this tick
     """
     crypto = ECCrypto()
     self._public_key = member.public_key
     self._signature = crypto.create_signature(member.private_key, self.get_sign_data())