@classmethod
def sorted_params(cls, params):
    """
        Sort parameters.

        works with RFC 5849 logic. params is a list of key, value pairs
        """
    if isinstance(params, dict):
        params = params.items()
    if not params:
        return params
    ordered = []
    params_sorting = []
    for i, (key, value) in enumerate(params):
        base_key = key.split('[')[0]
        params_sorting.append((base_key, value, i, key))
    for _, value, _, key in sorted(params_sorting):
        ordered.append((key, value))
    return ordered
