# Message Format

## API format <a href="#api-format" id="api-format"></a>

Two type of API will be documented following.

* Wallet Manager API

The API provide by Wallet Manager to receive instructs from merchant. eg. get address, withdraw.

* Merchant API

The API provided at merchant side to receive callbacks. eg. deposit and withdraw status.

Both APIs are using same signing mechanism to protest messages being sent not be forged.

## Request <a href="#request" id="request"></a>

Headers are added in request to verify message. Every program is assigned an address in Ethereum format for identification. It’s the program’s responsibilities to protect its private key. All messages should be signed before sending out to other program.

### Header

5 additional HTTP headers added.

<table><thead><tr><th width="233">Field</th><th width="100">Type</th><th>Comments</th></tr></thead><tbody><tr><td>X-Message-Address</td><td> String</td><td>An Ethereum address use to identify the sender<br>0x8F9092CE573e41d72378Cf8c9d3335584e6843F1</td></tr><tr><td>X-Message-Timestamp</td><td>Long</td><td>Timestamp of the message sent</td></tr><tr><td>X-Message-Session</td><td>String</td><td>Snowflake ID generated at program startup.</td></tr><tr><td>X-Message-Sequence</td><td>String</td><td>Sequence of message in this session.</td></tr><tr><td>X-Message-Signature</td><td>String</td><td>ECDSA_Sign(HSA265(X-Message-Timestamp#X-Message-Session#X-Message-Sequence#BODY))<br>Using secp256k1 curve</td></tr></tbody></table>

{% hint style="info" %}
BODY is optional in generating signature.
{% endhint %}

## Response <a href="#response" id="response"></a>

Response JSON Message (Similar to the response JSON RPC 2.0)&#x20;

[JSON-RPC 2.0 Specification](https://www.jsonrpc.org/specification)

But only implement two objects in the response json.

* result\
  This member is REQUIRED on success. \
  This member MUST NOT exist if there was an error invoking the method. \
  The value of this member is determined by the method invoked on the Server.
* error\
  This member is REQUIRED on error. \
  This member MUST NOT exist if there was no error triggered during invocation. \
  The value for this member MUST be an Object.
  * code\
    A Number that indicates the error type that occurred. \
    This MUST be an integer.
  * message\
    A String providing a short description of the error. \
    The message SHOULD be limited to a concise single sentence.
  * data\
    A Primitive or Structured value that contains additional information about the error. \
    This may be omitted. \
    The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).

Success message&#x20;

```json
{"result": {"id":19, "value":"abc"}}
```

Error message

```json
// data is optional
{"error": {"code":21, "message":"Invalid request"}}
```

```json
// error message with data
{"error": {"code":21, "message":"Invalid request", "data":{"value":"abc"}}}
```
