Exemple #1
0
    def test_hashchain_reveal(self):
        seed = sha256(b'test_seed')

        self.assertEqual('1d3b37dedc74980941b3b65640e8d2851658feac0d38196f372ada9c2ac0b077',
                         bin2hstr(hashchain_reveal(seed, 1, 100)))
        self.assertEqual('127f5db0388cd82bd4af80b88e8d68409e1f70fd322f96b3f2aca55b0ade116f',
                         bin2hstr(hashchain_reveal(seed, 1, 0)))
        self.assertEqual('ff7f4850bc6499e08e104c6967ee66e665e57d7e0e429072e646d14e1b92600a',
                         bin2hstr(hashchain_reveal(seed, 1, 50)))
        self.assertNotEqual('ff7f4850bc6499e08e104c6967ee66e665e57d7e0e429072e646d14e1b92600a',
                            bin2hstr(hashchain_reveal(seed, 1, 51)))
Exemple #2
0
    def test_hashchain_reveal(self):
        seed = sha256(b'test_seed')

        self.assertEqual(
            '1d3b37dedc74980941b3b65640e8d2851658feac0d38196f372ada9c2ac0b077',
            bin2hstr(hashchain_reveal(seed, 1, 100)))
        self.assertEqual(
            '127f5db0388cd82bd4af80b88e8d68409e1f70fd322f96b3f2aca55b0ade116f',
            bin2hstr(hashchain_reveal(seed, 1, 0)))
        self.assertEqual(
            'ff7f4850bc6499e08e104c6967ee66e665e57d7e0e429072e646d14e1b92600a',
            bin2hstr(hashchain_reveal(seed, 1, 50)))
        self.assertNotEqual(
            'ff7f4850bc6499e08e104c6967ee66e665e57d7e0e429072e646d14e1b92600a',
            bin2hstr(hashchain_reveal(seed, 1, 51)))
Exemple #3
0
    def create(activation_blocknumber: int,
               xmss: XMSS,
               slavePK: bytes,
               hashchain_terminator: bytes = None):
        """
        >>> s = StakeTransaction()
        >>> slave = XMSS(4)
        >>> isinstance(s.create(0, XMSS(4), slave.pk(), None), StakeTransaction)
        True
        """

        transaction = StakeTransaction()

        transaction._data.addr_from = bytes(xmss.get_address().encode())
        transaction._data.public_key = bytes(xmss.pk())

        # Stake specific
        transaction._data.stake.activation_blocknumber = activation_blocknumber

        transaction._data.stake.slavePK = slavePK

        if hashchain_terminator is None:
            epoch = activation_blocknumber // config.dev.blocks_per_epoch
            # FIXME: We are using the same xmss for the hashchain???
            transaction._data.stake.hash = hashchain_reveal(
                xmss.get_seed_private(), epoch=epoch)
        else:
            transaction._data.stake.hash = hashchain_terminator

        # WARNING: These fields need to the calculated once all other fields are set
        transaction._data.ots_key = xmss.get_index()
        transaction._data.transaction_hash = transaction.calculate_txhash()
        return transaction
Exemple #4
0
    def create(self,
               blocknumber,
               xmss,
               slave_public_key,
               hashchain_terminator=None,
               first_hash=None,
               balance=None):
        """
        :param blocknumber:
        :type blocknumber:
        :param xmss:
        :type xmss:
        :param slave_public_key:
        :type slave_public_key:
        :param hashchain_terminator:
        :type hashchain_terminator:
        :param first_hash:
        :type first_hash:
        :param balance:
        :type balance:
        :return:
        :rtype:
        >>> s = StakeTransaction()
        >>> slave = XMSS(4)
        >>> isinstance(s.create(0, XMSS(4), slave.pk(), None, slave.pk(), 10), StakeTransaction)
        True
        """
        if not balance:
            logger.info('Invalid Balance %d', balance)
            raise Exception

        self.slave_public_key = slave_public_key
        self.epoch = blocknumber // config.dev.blocks_per_epoch  # in this block the epoch is..
        self.first_hash = first_hash
        self.balance = balance

        if hashchain_terminator is None:
            self.hash = hashchain_reveal(xmss.get_seed_private(),
                                         epoch=self.epoch + 1)
        else:
            self.hash = hashchain_terminator

        tmphash = ''.join([bin2hstr(b) for b in self.hash])

        if self.first_hash is None:
            self.first_hash = tuple()

        self.txhash = str2bin(tmphash + bin2hstr(self.first_hash) +
                              bin2hstr(self.slave_public_key))
        self._process_XMSS(xmss.get_address(), self.txhash,
                           xmss)  # self.hash to be replaced with self.txhash
        return self
Exemple #5
0
    def create(blocknumber,
               xmss,
               slave_public_key,
               hashchain_terminator=None,
               first_hash=None,
               balance=None):
        """
        >>> s = StakeTransaction()
        >>> slave = XMSS(4)
        >>> isinstance(s.create(0, XMSS(4), slave.pk(), None, slave.pk(), 10), StakeTransaction)
        True
        """
        if not balance:
            logger.info('Invalid Balance %d', balance)
            raise Exception

        transaction = StakeTransaction()

        transaction.txfrom = xmss.get_address()

        transaction.slave_public_key = slave_public_key
        transaction.epoch = blocknumber // config.dev.blocks_per_epoch  # in this block the epoch is..
        transaction.balance = balance

        transaction.first_hash = first_hash
        if transaction.first_hash is None:
            transaction.first_hash = tuple()

        transaction.hash = hashchain_terminator
        if hashchain_terminator is None:
            transaction.hash = hashchain_reveal(xmss.get_seed_private(),
                                                epoch=transaction.epoch + 1)

        transaction.PK = xmss.pk()
        transaction.ots_key = xmss.get_index()

        tmppubhash = transaction._get_pubhash()

        tmptxhash = ''.join([bin2hstr(b) for b in transaction.hash])
        tmptxhash = str2bin(tmptxhash + bin2hstr(transaction.first_hash) +
                            bin2hstr(transaction.slave_public_key))
        transaction.txhash = transaction._get_txhash(tmptxhash, tmppubhash)

        return transaction