This specification describes the API for consuming go-waku when built as a dynamic or static library
# libgowaku.h
## General
### JSONResponse
All the API functions return a `JSONResponse` unless specified otherwise. `JSONResponse` is a `char *` whose format depends on whether the function was executed sucessfully or not:
{ "result": ... } // result format depends on the function response
```
## Events
Asynchronous events require a callback to be registered. An example of an asynchronous event that might be emitted is receiving a message. When an event is emitted, this callback will be triggered receiving a json string with the following format:
1.`void* cb`: callback that will be executed when an async event is emitted. The function signature for the callback should be `void myCallback(char* signalJSON)`
1.`char* configJSON`: JSON string containing the options used to initialize a go-waku node. It can be `NULL` to use defaults. All the keys from the configuration are optional. If a key is `undefined`, or `null`, a default value will be set
1.`char* address`: multiaddress of the peer being dialed
2.`int ms`: max duration in milliseconds this function might take to execute. If the function execution takes longer than this value, the execution will be canceled and an error returned. Use `0` for unlimited duration
1.`char* peerID`: peerID to dial. The peer must be already known. It must have been added before with `waku_add_peer` or previously dialed with `waku_dial_peer`
2.`int ms`: max duration in milliseconds this function might take to execute. If the function execution takes longer than this value, the execution will be canceled and an error returned. Use `0` for unlimited duration
"timestamp": 1647963508000000000 // Unix timestamp in nanoseconds
}
```
3.`char* topic`: pubsub topic. Set to `NULL` to use the default pubsub topic
4.`int ms`: max duration in milliseconds this function might take to execute. If the function execution takes longer than this value, the execution will be canceled and an error returned. Use `0` for unlimited duration
**Returns**
`JSONResponse` containing the message ID. An `error` message otherwise
Publish a message encrypted with a secp256k1 public key using waku relay
**Parameters**
1.`char* messageJSON`: json string containing the [Waku Message](https://rfc.vac.dev/spec/14/)
```js
{
"payload":"", // base64 encoded payload. waku_utils_base64_encode can be used for this
"contentTopic: "...",
"version": 1,
"timestamp": 1647963508000000000 // Unix timestamp in nanoseconds
}
```
2.`char* topic`: pubsub topic. Set to `NULL` to use the default pubsub topic
3.`char* publicKey`: hex string prefixed with "0x" containing a valid secp256k1 public key.
4.`char* optionalSigningKey`: optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
5.`int ms`: max duration in milliseconds this function might take to execute. If the function execution takes longer than this value, the execution will be canceled and an error returned. Use `0` for unlimited duration
**Returns**
`JSONResponse` containing the message ID. An `error` message otherwise
Publish a message encrypted with a 32 bytes symmetric key using waku relay
**Parameters**
1.`char* messageJSON`: json string containing the [Waku Message](https://rfc.vac.dev/spec/14/)
```js
{
"payload":"", // base64 encoded payload. waku_utils_base64_encode can be used for this
"contentTopic: "...",
"version": 1,
"timestamp": 1647963508000000000 // Unix timestamp in nanoseconds
}
```
2.`char* topic`: pubsub topic. Set to `NULL` to use the default pubsub topic
3.`char* symmetricKey`: hex string prefixed with "0x" containing a 32 bytes symmetric key
4.`char* optionalSigningKey`: optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
5.`int ms`: max duration in milliseconds this function might take to execute. If the function execution takes longer than this value, the execution will be canceled and an error returned. Use `0` for unlimited duration
**Returns**
`JSONResponse` containing the message ID. An `error` message otherwise
When a message is received, a ``"message"` event` is emitted containing the message, and pubsub topic in which the message was received. Here's an example event that could be received:
1.`char* messageJSON`: json string containing the [Waku Message](https://rfc.vac.dev/spec/14/)
```js
{
"payload":"", // base64 encoded payload. waku_utils_base64_encode can be used for this
"contentTopic: "...",
"version": 1,
"timestamp": 1647963508000000000 // Unix timestamp in nanoseconds
}
```
2.`char* topic`: pubsub topic. Set to `NULL` to use the default pubsub topic
3.`char* peerID`: should contain the ID of a peer supporting the lightpush protocol. Use NULL to automatically select a node
4.`int ms`: max duration in milliseconds this function might take to execute. If the function execution takes longer than this value, the execution will be canceled and an error returned. Use `0` for unlimited duration
1.`char* messageJSON`: json string containing the [Waku Message](https://rfc.vac.dev/spec/14/)
```js
{
"payload":"", // base64 encoded payload. waku_utils_base64_encode can be used for this
"contentTopic: "...",
"version": 1,
"timestamp": 1647963508000000000 // Unix timestamp in nanoseconds
}
```
2.`char* topic`: pubsub topic. Set to `NULL` to use the default pubsub topic
3.`char* publicKey`: hex string prefixed with "0x" containing a valid secp256k1 public key.
4.`char* optionalSigningKey`: optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
5.`char* peerID`: should contain the ID of a peer supporting the lightpush protocol. Use NULL to automatically select a node
6.`int ms`: max duration in milliseconds this function might take to execute. If the function execution takes longer than this value, the execution will be canceled and an error returned. Use `0` for unlimited duration
**Returns**
`JSONResponse` containing the message ID. An `error` message otherwise
1.`char* messageJSON`: json string containing the [Waku Message](https://rfc.vac.dev/spec/14/)
```js
{
"payload":"", // base64 encoded payload. waku_utils_base64_encode can be used for this
"contentTopic: "...",
"version": 1,
"timestamp": 1647963508000000000 // Unix timestamp in nanoseconds
}
```
2.`char* topic`: pubsub topic. Set to `NULL` to use the default pubsub topic
3.`char* symmetricKey`: hex string prefixed with "0x" containing a 32 bytes symmetric key
4.`char* optionalSigningKey`: optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
5.`char* peerID`: should contain the ID of a peer supporting the lightpush protocol. Use NULL to automatically select a node
6.`int ms`: max duration in milliseconds this function might take to execute. If the function execution takes longer than this value, the execution will be canceled and an error returned. Use `0` for unlimited duration
1.`char* queryJSON`: json string containing the query. If the message length is greater than 0, this function should be executed again, setting the `cursor` attribute with the cursor returned in the response
```js
{
"pubsubTopic": "...", // optional string
"startTime": 1234, // optional, unix epoch time in nanoseconds
"endTime": 1234, // optional, unix epoch time in nanoseconds
"contentFilters": [ // optional
{
"contentTopic": "..."
}, ...
],
"pagingOptions": { // optional pagination information
"pageSize": 40, // number
"cursor": { // optional
"digest": ...,
"receiverTime": ...,
"senderTime": ...,
"pubsubTopic" ...,
},
"forward": true, // sort order
}
}
```
2.`char* peerID`: should contain the ID of a peer supporting the store protocol. Use NULL to automatically select a node
3.`int ms`: max duration in milliseconds this function might take to execute. If the function execution takes longer than this value, the execution will be canceled and an error returned. Use `0` for unlimited duration