---
# System prepended metadata

title: L2 Auth API

---

# L2 Auth API

Test endpoint: [wss://backend.l2dex.io:9511/ws/auth](wss://backend.l2dex.io:9511/ws/auth)

## 1. Messages flow

![](https://i.imgur.com/RaBNNI0.png)




**Flow example:**
|  step | base64 encoded message |
| -------- | -------- | 
| 1     | `AK1BAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==`     | 
| 2     | `AK1BFXWTjxJVSBK8pojuZb47/xXPZQDweqjXFdGLEOmjqNcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==`     | 
| 3     | `AK1BFXWTjxJVSBK8pojuZb47/xXPZQDweqjXFdGLEOmjqNdDIQRNY933NBZhzTODPEX1FDba5OHbseUalDJCxJZbMrV91axTeYFnxU+dfmQ5ZDU0liX5jJa8Kf9VCrJbBlrb8wQAq2FAQgoSo8WQah/hL5PZvT6pIDszcpFrhG2+QU0jRlYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==`     |
| 4     | `AK1BFXWTjxJVSBK8pojuZb47/xXPZQDweqjXFdGLEOmjqNdDIQRNY933NBZhzTODPEX1FDba5OHbseUalDJCxJZbMrV91axTeYFnxU+dfmQ5ZDU0liX5jJa8Kf9VCrJbBlrb8wQAq2FAQgoSo8WQah/hL5PZvT6pIDszcpFrhG2+QU0jRlYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACg==`     | 


## 2. Client to Exchange messages
``` golang
const (
		AuthType = types.Char('A')      // Запрос на авторизацию
		SignatureType = types.Char('S') // Подписанное сообщение
)
```
- [x]  **Auth is a structure containing Auth message fields in useable format.**
```golang
type Auth struct {
	MessageType  types.Char         `json:"message_type"`
	SessionToken types.SessionToken `json:"session_token"`
	Signature    types.Signature    `json:"signature"`
	PublicKey    types.PublicKey    `json:"public_key"`
	AccountID    types.Uint64       `json:"account_id"`
}
```

- [x] **Signature is a structure containing Signature message fields in useable format.**

```golang
type Signature struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	OrderID     types.Uint64    `json:"order_id"`
	AccountID   types.Uint64    `json:"account_id"`
	Signature   types.Signature `json:"signature"`
}
```

## 3. Exchange to Client messages

``` golang
const (
		AuthType = types.Char('A')       // Предложение к рукопожатию
		SignatureType = types.Char('S')  // Подписанное сообщение
		ErrorType = types.Char('!')      // Сообщение об ошибке
)
```

- [x] **Auth is a structure containing Auth message fields in usable format.**
```golang
type Auth struct {
	MessageType  types.Char         `json:"message_type"`
	SessionToken types.SessionToken `json:"session_token"`
	Signature    types.Signature    `json:"signature"`
	PublicKey    types.PublicKey    `json:"public_key"`
	AccountID    types.Uint64       `json:"account_id"`
}
```

- [x]  **Signature is a structure containing Signature message fields in usable format.**
```golang
type Signature struct {
	MessageType    types.Char      `json:"message_type"`
	SymbolID       types.Uint16    `json:"symbol_id"`
	BlockchainID   types.Char      `json:"blockchain_id"`
	SignatureL2A   types.Signature `json:"signature_l2a"`
	SignatureMaker types.Signature `json:"signature_maker"`
	SignatureTaker types.Signature `json:"signature_taker"`
	Timestamp      types.Timestamp `json:"timestamp"`
}
```

- [x] **Error is a structure containing Error message fields in usable format.***
```golang
type Error struct {
	MessageType   types.Char      `json:"message_type"`
	Timestamp     types.Timestamp `json:"timestamp"`
	Code          types.Uint16    `json:"code"`
	MessageLength types.Uint16    `json:"message_length"`
	Message       types.String    `json:"message"`
}
```

## 4. Examples
1. [Typescript client side library](https://gitlab.l2a.io/l2a.io/l2a-web/tree/develop/plugins/api/messages/auth) 
2. [Golang client side example](https://gitlab.l2a.io/l2a.io/l2a-core/blob/master/cmd/tools/l2a-client/l2a_client.go)
