# Blockchain Authentication

Endpoints to generate a Bearer Token using the Sign in with Ethereum (SIWE) standard. See https://docs.login.xyz/sign-in-with-ethereum/quickstart-guide.

## Generate a SIWE nonce

`GET /v2/auth/siwe/nonce`

Get a nonce to perform a Sign in with Ethereum (SIWE) verification. (https://docs.login.xyz/sign-in-with-ethereum/quickstart-guide)

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `nonce` | string | nonce (e.g. `AwxV9CQHJamoLxIJlfeh`) |


**Example**

```bash
curl "https://api.demo.omniaexchange.com/api/v2/auth/siwe/nonce"
```

---

## SIWE Verification

`POST /v2/auth/siwe/verify`

Perform Sign in with Ethereum (SIWE) verification. This will issue you a token if successful.

**Request Body** _(required)_

  | Field | Type | Description |
  |-------|------|-------------|
  | `message` | string | SIWE Message (e.g. `message -> demo.omniaexchange.com wants you to sign in with your Ethereum account:
0x12YOUR_PUBLIC_KEY34

Sign in to use the app

URI: https://demo.omniaexchange.com
Version: 1
Chain ID: 11155111
Nonce: AwxV9CQHJamoLxIJlfeh
Issued At: 2023-11-12T15:13:37.996908215Z`) |
  | `signature` | string | Signature of the message (e.g. `0xc2d0018de1528b8dab42e85482263060903ec1fec13768f66977f9b7b37333a3f2a1bbf42`) |

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `jwtToken` | string | The token you should include on any requests to endpoints that require authorisation (e.g. `eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJIaSI6IkRpZCBub3QgdGhpbmsgYW55b25lIHdvdWxkIGRlY29kZSB0aGlzIiwicHVia2V5IjoiMHgwMFlvdXJQdWJsaWNLZXkwMCIsImlhdCI6MTY5OTgwMTE5NSwiZXhwIjoxNjk5ODg3NTk1fQ.CZdxZje7VRrMdfbfQSbnaliNmpmhat_tNZWiDqi-tboXqBLnP1qQRpwdl8A89eaGxkvmVmZGbeA8wP6ghqHjuzCjr1G5OwG40draexCZyBgys1IaPJFHVujrKxr3BxI5U0e8fSQ7s_kuWy3mA5SzlQJnlMy6y5WeY0GS7PACgXRBH3g3R0cua-pNmA-PzvRPTaQzU4-Bs3rsisNIcaJMIXCS2ofnvH6aLmWDpucfepJ1NgX0QJHZupBNBAoV67NPz4c9McERwG5G_pykmwz9sOJxLNpjjvf8OyF_21epX_YkxR1tzhPAHQuiIg8DAAWI7S435cR1yQyoY7R0TJWPZQ`) |

- **400**: Bad request

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid schema):
  ```json
  {"code":"INVALID_SCHEMA","description":"Missing or malformed schema"}
  ```
- **401**: Unauthorized

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid nonce):
  ```json
  {"code":"INVALID_NONCE","description":"Invalid nonce"}
  ```
- **403**: Forbidden

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (User not whitelisted):
  ```json
  {"code":"USER_NOT_WHITELISTED","description":"User is not whitelisted"}
  ```

**Example**

```bash
curl -X POST "https://api.demo.omniaexchange.com/api/v2/auth/siwe/verify" \
  -H "Content-Type: application/json" \
  -d '{"message": "message -> demo.omniaexchange.com wants you to sign in with your Ethereum account:
0x12YOUR_PUBLIC_KEY34

Sign in to use the app

URI: https://demo.omniaexchange.com
Version: 1
Chain ID: 11155111
Nonce: AwxV9CQHJamoLxIJlfeh
Issued At: 2023-11-12T15:13:37.996908215Z", "signature": "0xc2d0018de1528b8dab42e85482263060903ec1fec13768f66977f9b7b37333a3f2a1bbf42"}'
```

---

