> For the complete documentation index, see [llms.txt](https://docs.cabbagino.com/cabbagino/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cabbagino.com/cabbagino/payment-api-2.0/signature.md).

# Signature

Signature - a string in hexadecimal format formed by one-way coding. You cannot decode or generate this string without knowing all the necessary components. The signature is based on the potential importance of each query parameter.

SHA-1 hash algorithm is used for signature generating.

{% hint style="info" %}
Secure Hash Algorithm 1 – cryptographic hashing algorithm. For an input message of arbitrary length (a maximum of 2^64 bits, approximately equal to 2 exabytes), the algorithm generates a 160-bit hash value, also called a message digest. It is used in many cryptographic applications and protocols.
{% endhint %}

{% code title="Python code snippet" overflow="wrap" lineNumbers="true" %}

```python
def sign_params(input_params: Mapping, salt: AnyStr) -> AnyStr:
    params = {}
    for k, v in input_params.items():
        if isinstance(v, list):
            new_v = ';'.join(sorted(map(str, v)))
            params[str(k)] = str(new_v)
        elif isinstance(v, dict):
            sorted_dict = sorted(v)
            new_v = ';'.join(f'{key}:{v[key]}' for key in sorted_dict)
            params[str(k)] = str(new_v)
        else:
            params[str(k)] = str(v)

    sign_str = ';'.join(
        ['%s:%s' % (k.lower(), params[k]) for k in sorted(params.keys()) 
        if params[k].strip() != '']) + ';'
    logging.debug(sign_str + salt)
    return hashlib.sha1(sign_str.encode('utf-8') + 
    salt.encode('utf-8')).hexdigest()
```

{% endcode %}

### Signature generating algorithm <a href="#signature-generating-algorithm" id="signature-generating-algorithm"></a>

1. A signature string is generated:
   * all query parameters are sorted alphabetically;
   * sorted not empty parameters are connected in series to one line (concatenation) using the symbol-separator between them;
   * the end of the line is appended with the site salt using the symbol-separator
2. SHA-1 hash is taken from the received string.

### Signature generating rules <a href="#signature-generating-rules" id="signature-generating-rules"></a>

* Signed string coding – UTF-8;
* Query parameter names are presented in lower case. The string can be composed of Latin letters from a to z, numbers from 0 to 9, underlining sign "\_";
* A semicolon is used as the delimiter between parameters ”;”;
* Each parameter is attached as a substring ”param\_name:param\_value”, where param name – a parameter name, param\_value – parameter value, a colon - internal delimiter;
* Parameters which value is an empty string ”” – are skipped;
* If the parameter value is an array, then its elements are also sorted according to the growth of their keys and connected in series by a delimiter. In this case, the array elements (nested arrays) are skipped, and the delimiter character is not added;
* To avoid double signing, the "signature" parameter is always excluded from the signature.<br>

{% hint style="info" %}
In summary, the process of generating a signature using the SHA-1 hash algorithm and the described rules helps ensure data integrity and authenticity by providing a unique identifier that can be used to verify the validity of the data while maintaining a secure and consistent approach to signing.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cabbagino.com/cabbagino/payment-api-2.0/signature.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
