# Authenticate requests

After you've created your API key, make a test request to verify that your authentication and signing setup works correctly.

## How it works

### Base URL

The base URL for all Revolut X Crypto Exchange REST API endpoints is:

```
https://revx.revolut.com/api/
```

### Authentication headers

Every request to an authenticated endpoint must include the following headers:

| Header | Description |
| :--- | :--- |
| **`X-Revx-API-Key`** | Your API key (64-character alphanumeric string). |
| **`X-Revx-Timestamp`** | The Unix timestamp of the request, provided in **milliseconds**. |
| **`X-Revx-Signature`** | The request digest string signed with your **private key**. |

## Before you begin

Before you start, make sure you have:

- An [API key](/docs/guides/crypto-exchange/get-started/create-an-api-key) to authenticate your requests.
- The private key (`private.pem`) you saved when [generating signing keys](/docs/guides/crypto-exchange/get-started/create-an-api-key#generate-an-ed25519-key-pair).

## Signing a request

To generate the `X-Revx-Signature` header, you must sign a specific string constructed from your request data:

1. **Construct the message string** by concatenating the present components in order, with no separators.
2. **Sign the message** using your **Ed25519 private key**.
   Ed25519 signing produces a 64-byte raw signature that is unique to both the message and the private key.
3. **Base64-encode** the raw signature bytes.

**Send the encoded value** in the `X-Revx-Signature` header.

### 1. Construct the message string

The string to sign is a concatenation of the following values, in this specific order:

| # | Component | Notes | Example |
|---|---|---|---|
| 1 | **Timestamp** | Same value as the `X-Revx-Timestamp` header | `1783616701644` |
| 2 | **HTTP method** | Uppercase | `GET` |
| 3 | **Request path** | Starting from `/api`, including any path parameters | `/api/1.0/orders/active` |
| 4 | **Query string** _(if present)_ | Without the `?` prefix _(empty string if none)_ | `limit=10` |
| 5 | **Request body** _(if present)_ | Minified JSON _(empty string if none)_ | `{"client_order_id":"3fa85f64-5717-4562-b3fc-2c963f66afa6", ...}` <br /> _(see below for the full sample)_|

A sample minified request body JSON migh look like this: 
```json
{"client_order_id":"3fa85f64-5717-4562-b3fc-2c963f66afa6","symbol":"BTC-USD","side":"sell","order_configuration":{"limit":{"base_size":"0.1","price":"120000.50","execution_instructions":["post_only"]}}}
```

:::note
When concatenating, do not add any separators (spaces, newlines, or commas) between the fields.
:::

:::warning[URL-encode query string values in the signature]
If your request includes URL-encoded query string values (e.g., `key=hello%3Aworld`), you must use the same URL-encoded value when constructing the signature message.
Signing the raw, unencoded value (e.g., `key=hello:world`) will cause signature verification to fail.

Keep the space encoding consistent between the request and the signature message.
Some API clients encode spaces as `+` in query strings (for example, [Bruno](https://www.usebruno.com/)), others as `%20`.
Either approach is valid, provided the signature message uses the same encoding as the request.
:::

**Example message:**

```text
1765360896219POST/api/1.0/orders{"client_order_id":"3b364427-1f4f-4f66-9935-86b6fb115d26","symbol":"BTC-USD","side":"buy","order_configuration":{"limit":{"base_size":"0.1","price":"90000.1"}}}
```

### 2. Sign the message

1. Sign the constructed string using your **Ed25519 private key**.
2. **Base64-encode** the resulting signature.
3. Send this value in the `X-Revx-Signature` header.

## Code examples

Generate the signature programmatically.

:::note
The code samples below are included for educational purposes only and are not considered production-ready. 
Adjust them to your needs before use.
:::

### Python example

```python
import base64
from pathlib import Path
from nacl.signing import SigningKey
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend

# 1. Load your Private Key
pem_data = Path("private.pem").read_bytes()
private_key_obj = serialization.load_pem_private_key(
    pem_data,
    password=None,
    backend=default_backend()
)

# Extract raw bytes for PyNaCl
raw_private = private_key_obj.private_bytes(
    encoding=serialization.Encoding.Raw,
    format=serialization.PrivateFormat.Raw,
    encryption_algorithm=serialization.NoEncryption()
)

# 2. Prepare the message
timestamp = "1785313433816"
method = "GET"
path = "/api/1.0/orders/active"
query = "status=open&limit=10"
body = "" # Empty for GET

# Concatenate without separators
message = f"{timestamp}{method}{path}{query}{body}".encode('utf-8')

# 3. Sign and Encode
signing_key = SigningKey(raw_private)
signed = signing_key.sign(message)
signature = base64.b64encode(signed.signature).decode()

print(f"X-Revx-Signature: {signature}")
```

### Node.js example

```javascript
const crypto = require('crypto');
const fs = require('fs');

// 1. Load your Private Key
const privateKey = fs.readFileSync('private.pem', 'utf8');

// 2. Prepare the message
const timestamp = Date.now().toString();
const method = 'POST';
const path = '/api/1.0/orders';
const body = JSON.stringify({
  client_order_id: crypto.randomUUID(),
  symbol: "BTC-USD",
  side: "buy",
  order_configuration: {
    limit: {
      base_size: "0.005",
      price: "90000.1"
    }
  }
});

// Concatenate without separators
const message = timestamp + method + path + body;

// 3. Sign and Encode
// Note: Use crypto.sign with null to indicate pure Ed25519 signing (no hashing algorithm)
const signatureBuffer = crypto.sign(null, Buffer.from(message), privateKey);
const signature = signatureBuffer.toString('base64');

console.log(`X-Revx-Timestamp: ${timestamp}`);
console.log(`X-Revx-Signature: ${signature}`);
```

Include the `X-Revx-API-Key`, `X-Revx-Timestamp`, and `X-Revx-Signature` headers in your request and send it. 

See [Make your first request](/docs/guides/crypto-exchange/get-started/make-your-first-request) for more details.