Пример #1
0
 def unlockhash(self):
     """
     Calculate unlock hash of the spendable key
     """
     if self._unlockhash is None:
         pub_key = Ed25519PublicKey(pub_key=self._pk)
         encoded_pub_key = binary.encode(pub_key)
         hash = utils.hash(encoded_pub_key, encoding_type='slice')
         self._unlockhash = UnlockHash(unlock_type=UNLOCK_TYPE_PUBKEY, hash=hash)
     return self._unlockhash
Пример #2
0
    def _generate_spendable_key(self, index):
        """
        Generate a @Spendablekey object from the seed and index

        @param index: Index of key to generate from the seed
        """
        binary_seed = bytearray()
        binary_seed.extend(binary.encode(self._seed))
        binary_seed.extend(binary.encode(index))
        binary_seed_hash = utils.hash(binary_seed)
        sk = ed25519.SigningKey(binary_seed_hash)
        pk = sk.get_verifying_key()
        return SpendableKey(pub_key=pk.to_bytes(), sec_key=sk)
Пример #3
0
    def get_input_signature_hash(self, input_index, extra_objects=None):
        """
        Builds a signature hash for an input

        @param input_index: Index of the input we will get signature hash for
        """
        if extra_objects is None:
            extra_objects = []

        buffer = bytearray()
        # encode the transaction version
        buffer.extend(self._version)
        # encode the input index
        buffer.extend(binary.encode(input_index))

        # encode extra objects if exists
        for extra_object in extra_objects:
            buffer.extend(binary.encode(extra_object))

        # encode the number of coins inputs
        buffer.extend(binary.encode(len(self._coins_inputs)))

        # encode inputs parent_ids
        for coin_input in self._coins_inputs:
            buffer.extend(binary.encode(coin_input.parent_id, type_='hex'))

        # encode coin outputs
        buffer.extend(binary.encode(self._coins_outputs, type_='slice'))

        # encode the number of blockstakes
        buffer.extend(binary.encode(len(self._blockstakes_inputs)))
        # encode blockstack inputs parent_ids
        for bs_input in self._blockstakes_inputs:
            buffer.extend(binary.encode(bs_input.parent_id, type_='hex'))

        # encode blockstake outputs
        buffer.extend(binary.encode(self._blockstakes_outputs, type_='slice'))

        # encode miner fees
        buffer.extend(binary.encode(len(self._minerfees)))
        for miner_fee in self._minerfees:
            buffer.extend(binary.encode(miner_fee, type_='currency'))

        # encode custom data_
        buffer.extend(binary.encode(self._data, type_='slice'))

        # now we need to return the hash value of the binary array
        # return bytes(buffer)
        return hash(data=buffer)
Пример #4
0
def ulh():
    """
    Generates a test unlockhash of with unlock type publickey
    """
    hash = utils.hash(b'hello')
    return UnlockHash(unlock_type=UNLOCK_TYPE_PUBKEY, hash=hash)
Пример #5
0
def recipient():
    """
    Generates a recipient address
    """
    hash = utils.hash(b'hello recipient')
    return str(UnlockHash(unlock_type=UNLOCK_TYPE_PUBKEY, hash=hash))