def construct_witness(items: Sequence[Union[str, int, bytes]]) -> bytes:
    """Constructs a witness from the given stack items."""
    witness = bytearray()
    witness += var_int(len(items))
    for item in items:
        if type(item) is int:
            item = script_num_to_bytes(item)
        elif isinstance(item, (bytes, bytearray)):
            pass  # use as-is
        else:
            assert is_hex_str(item), repr(item)
            item = bfh(item)
        witness += witness_push(item)
    return bytes(witness)
Constructs a witness from the given stack items.
electrum/bitcoin.py