> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vitawallet.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Autenticación

> Firma HMAC-SHA256 y headers obligatorios para cada petición.

Vita Wallet usa **HMAC-SHA256** para autenticar cada petición. La firma garantiza que el mensaje proviene del emisor correcto y que su contenido no fue alterado en tránsito.

## Headers obligatorios

| Header | Tipo | Descripción |
| - | - | - |
| `x-date` | String | Datetime ISO8601 con timezone (ej. `2018-07-12T13:46:28.629Z`) |
| `x-login` | String | xLogin del business |
| `x-trans-key` | String | xTransKey del business |
| `Content-Type` | String | `application/json` |
| `Authorization` | String | Formato: `V2-HMAC-SHA256, Signature: <hash>` |

### Ejemplo de header `Authorization`

```
Authorization: V2-HMAC-SHA256, Signature: 80ebe700c5db952bd4c60ae53fe1971ec6e4fe84dc0922b67eca6b3e18707260
```

## Cómo generar la firma

El hash se calcula uniendo:

1. `x-login`
2. `x-date`
3. El body de la petición ordenado alfabéticamente y concatenado sin separadores (ver detalle abajo).

> [!NOTE]
>
> Si el body es `null`, la firma se calcula **sin** el body.

### Formato del body ordenado

Para un body como:

```json theme={null}
{ "order": "xyz", "amount": 400, "statuses": ["deposit", "payment"] }
```

El `sorted_request_body` resultante es:

```
amount400orderxyzstatusesdeposit,payment
```

> [!WARNING]
>
> Cuando un valor es un array, los elementos se separan con `,` (coma). Las claves se ordenan alfabéticamente y se concatenan sin separadores.

## Implementaciones por lenguaje

```python Python theme={null}
import hmac, hashlib

signature = hmac.new(
    secret_key.encode(),
    (x_login + x_date + sorted_request_body).encode(),
    hashlib.sha256
).hexdigest()
```

```ruby Ruby theme={null}
require 'openssl'

signature = OpenSSL::HMAC.hexdigest(
  'sha256',
  secret_key,
  "#{x_login}#{x_date}#{sorted_request_body}"
)
```

```php PHP theme={null}
$signature = hash_hmac(
  "sha256",
  "$xLogin$xDate$sortedRequestBody",
  $secretKey
);
```

```javascript Node.js theme={null}
const crypto = require('crypto');

const signature = crypto
  .createHmac('sha256', secretKey)
  .update(`${xLogin}${xDate}${sortedRequestBody}`)
  .digest('hex');
```

## Cómo obtener credenciales

En la sección **Integraciones** de tu cuenta Vita Wallet encontrarás un botón para solicitar las credenciales de acceso. Se enviarán por email con instrucciones.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.