def segwit_scriptpubkey(witver, witprog):
    """Create a segwit locking script for a given witness program (P2WPKH and P2WSH)."""
    return bytes([witver + 0x50 if witver else 0, len(witprog)] + witprog)