# 1️⃣-Message Format

## Overview

All messages sent between nodes have headers. The initial handshake messages are sent unencrypted, and all other messages are encrypted and authenticated using the keys that are generated during the initial handshake.

All messages payloads are serialized using **Protocol Buffers**.

Protocol buffers are a language-neutral, platform-neutral, extensible mechanism for serializing structured data. You can find [documentation on the Google Developers site](https://developers.google.com/protocol-buffers/).

To develop with protocol buffers you will need to install the protocol buffer compiler (to compile `.proto` files) and the protocol buffer runtime for your chosen programming language.

Protocol buffers currently support development in Java, Python, Go, Rust, C, C++, Objective-C, C#, Dart, Ruby, Perl, Haskell, Javascript, [and more](https://github.com/protocolbuffers/protobuf/blob/master/docs/third_party.md#programming-languages).

### The unencrypted message

| Size (bytes) | Name     | Data Type | Description                                             |
| ------------ | -------- | --------- | ------------------------------------------------------- |
| 4            | magic    | uint32    | Magic value to specify the message's network            |
| 4            | length   | uint32    | Payload length                                          |
| 4            | type     | uint32    | Message type                                            |
| 4            | checksum | uint32    | First 4 bytes of sha256 hash of JSON-serialized message |
| length       | payload  | bytes     | The actual data                                         |

#### Magic values

| Network | Magic value  |
| ------- | ------------ |
| mainnet | `0xd9b4bef9` |
| testnet | `0x0709110b` |
| simnet  | `0x12141c16` |
| regnet  | `0xdab5bffa` |

### The encrypted message

| Size (bytes) | Name       | Data Type | Description           |
| ------------ | ---------- | --------- | --------------------- |
| 4            | length     | uint32    | Length of the payload |
| length       | ciphertext | bytes     | The encrypted data    |

#### Ciphertext pre-encryption format

| Size (bytes) | Name    | Data Type | Description     |
| ------------ | ------- | --------- | --------------- |
| 4            | length  | uint32    | Payload length  |
| 4            | type    | uint32    | Message type    |
| length       | payload | bytes     | The actual data |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://opendex.network/bold/01-message-format.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
