'Sign.
:param JWK key: Key for signature.'

@classmethod
def sign(cls, payload, key, alg, include_jwk=True, protect=frozenset(), **kwargs):

    assert isinstance(key, alg.kty)
    header_params = kwargs
    header_params['alg'] = alg
    if include_jwk:
        header_params['jwk'] = key.public_key()
    assert set(header_params).issubset(cls.header_cls._fields)
    assert protect.issubset(cls.header_cls._fields)
    protected_params = {}
    for header in protect:
        if (header in header_params):
            protected_params[header] = header_params.pop(header)
    if protected_params:
        protected = cls.header_cls(**protected_params).json_dumps()
    else:
        protected = ''
    header = cls.header_cls(**header_params)
    signature = alg.sign(key.key, cls._msg(protected, payload))
    return cls(protected=protected, header=header, signature=signature)
