def create_negative_gossip_transaction(number_of_block, node_private):
     tx = NegativeGossipTransaction()
     tx.timestamp = Time.get_current_time()
     tx.number_of_block = number_of_block
     tx.pubkey = Private.publickey(node_private)
     tx.signature = Private.sign(tx.get_hash(), node_private)
     return tx
 def create_positive_gossip_transaction(block_hash, node_private):
     tx = PositiveGossipTransaction()
     tx.timestamp = Time.get_current_time()
     tx.block_hash = block_hash
     tx.pubkey = Private.publickey(node_private)
     tx.signature = Private.sign(tx.get_hash(), node_private)
     return tx
 def create_payment_transaction(from_tx, amount, to, node_private):
     tx = PaymentTransaction()
     tx.from_tx = from_tx
     tx.amount = amount
     tx.to = to
     tx.pubkey = Private.publickey(node_private)
     tx.signature = Private.sign(tx.get_hash(), node_private)
     return tx
    def create_commit_reveal_pair(node_private, random_bytes, pubkey_index,
                                  epoch_hash):
        private = Private.generate()
        encoded = Private.encrypt(random_bytes, private)

        commit = TransactionFactory.create_commit_random_transaction(
            encoded, pubkey_index, epoch_hash, node_private)
        reveal = TransactionFactory.create_reveal_random_transaction(
            commit.get_hash(), private)

        return commit, reveal
Exemplo n.º 5
0
    def try_to_publish_public_key(self, current_block_number):
        if self.epoch_private_keys:
            return

        epoch_hashes = self.epoch.get_epoch_hashes()
        for _, epoch_hash in epoch_hashes.items():
            allowed_round_validators = self.permissions.get_ordered_randomizers_pubkeys_for_round(
                epoch_hash, Round.PUBLIC)
            pubkey_publishers_pubkeys = [
                validator.public_key for validator in allowed_round_validators
            ]
            if self.node_pubkey in pubkey_publishers_pubkeys:
                node_private = self.block_signer.private_key
                pubkey_index = self.permissions.get_signer_index_from_public_key(
                    self.node_pubkey, epoch_hash)

                generated_private = Private.generate()
                tx = TransactionFactory.create_public_key_transaction(
                    generated_private=generated_private,
                    epoch_hash=epoch_hash,
                    validator_index=pubkey_index,
                    node_private=node_private)
                if self.behaviour.malicious_wrong_signature:
                    tx.signature = b'0' + tx.signature[1:]

                self.epoch_private_keys.append(generated_private)
                self.logger.debug("Broadcasted public key")
                self.logger.debug(Keys.to_visual_string(tx.generated_pubkey))
                self.mempool.add_transaction(tx)
                self.network.broadcast_transaction(self.node_id,
                                                   TransactionParser.pack(tx))
 def create_split_random_transaction(encoded_splits, pubkey_index,
                                     epoch_hash, node_private):
     tx = SplitRandomTransaction()
     tx.pieces = encoded_splits
     tx.pubkey_index = pubkey_index
     tx.signature = Private.sign(tx.get_signing_hash(epoch_hash),
                                 node_private)
     return tx
Exemplo n.º 7
0
 def get_payment_transactions_for_signing(self, block_number):
     node_public = Private.publickey(self.block_signer.private_key)
     pseudo_address = sha256(node_public).digest()
     block_reward = TransactionFactory.create_block_reward(
         pseudo_address, block_number)
     block_reward_hash = block_reward.get_hash()
     self.owned_utxos.append(block_reward_hash)
     payment_txs = [block_reward] + self.mempool.pop_payment_transactions()
     return payment_txs
    def test_encryption_and_decryption(self):
        private_keys = []
        public_keys = []
        for i in range(0, 5):
            private = Private.generate()
            private_keys.append(private)
            public_keys.append(Private.publickey(private))

        raw_private_keys = Keys.list_to_bytes(private_keys)
        decoded_private_keys = Keys.list_from_bytes(raw_private_keys)

        random_bytes = os.urandom(32)
        random_value = int.from_bytes(random_bytes, byteorder='big')
        splits = split_secret(random_bytes, 3, 5)
        encoded_splits = encode_splits(splits, public_keys)
        decoded_random = decode_random(encoded_splits, decoded_private_keys)

        self.assertEqual(random_value, decoded_random)