fix: library docs

This commit is contained in:
Richard Ramos 2022-05-06 14:13:10 -04:00
parent 912292ad1d
commit 3bc8a4df9f
No known key found for this signature in database
GPG Key ID: BD36D48BC9FFC88C
5 changed files with 262 additions and 160 deletions

View File

@ -20,7 +20,7 @@ This specification describes the API for consuming go-waku when built as a dynam
### JSONResponse ### 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: 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:
```json ```js
// On failure: // On failure:
{ "error": "the error message" } { "error": "the error message" }
@ -30,7 +30,7 @@ All the API functions return a `JSONResponse` unless specified otherwise. `JSONR
## Events ## 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: 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:
```json ```js
{ {
"nodeId": 0, // go-waku node that emitted the signal "nodeId": 0, // go-waku node that emitted the signal
"type": "message", // type of signal being emitted. Currently only "message" is available "type": "message", // type of signal being emitted. Currently only "message" is available
@ -38,21 +38,20 @@ Asynchronous events require a callback to be registered. An example of an asynch
} }
``` ```
### `extern void gowaku_set_event_callback(void* cb)` ### `extern void waku_set_event_callback(void* cb)`
Register callback to act as event handler and receive application signals, which are used to react to asyncronous events in waku. Register callback to act as signal handler and receive application signals, which are used to react to asyncronous events in waku.
**Parameters** **Parameters**
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. `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)`
## Node management ## Node management
### `extern char* gowaku_new(char* configJSON)` ### `extern char* waku_new(char* configJSON)`
Initialize a go-waku node. Initialize a go-waku node.
**Parameters** **Parameters**
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* 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
```json ```js
// example config: // example config:
{ {
"host": "0.0.0.0", "host": "0.0.0.0",
@ -73,134 +72,104 @@ Initialize a go-waku node.
- `minPeersToPublish` - `Number` (optional). The minimum number of peers required on a topic to allow broadcasting a message. Default `0` - `minPeersToPublish` - `Number` (optional). The minimum number of peers required on a topic to allow broadcasting a message. Default `0`
**Returns** **Returns**
`JSONResponse` with a `result` containing an `int` which represents the `nodeID` which should be used in all calls from this API that require interacting with the node if the function executes successfully. An `error` message otherwise `JSONResponse` with a NULL `result`. An `error` message otherwise
--- ---
### `extern char* gowaku_start(int nodeID)` ### `extern char* waku_start()`
Initialize a go-waku node mounting all the protocols that were enabled during the waku node initialization. Initialize a go-waku node mounting all the protocols that were enabled during the waku node initialization.
**Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new`
---
### `extern char* gowaku_stop(int nodeID)`
Stops a go-waku node
**Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new`
**Returns** **Returns**
`JSONResponse` containing a null `result` if the function executes successfully. An `error` message otherwise `JSONResponse` containing a null `result` if the function executes successfully. An `error` message otherwise
--- ---
### `extern char* gowaku_peerid(int nodeID)` ### `extern char* waku_stop()`
Obtain the peer ID of the go-waku node. Stops a go-waku node
**Parameters** **Returns**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` `JSONResponse` containing a null `result` if the function executes successfully. An `error` message otherwise
---
### `extern char* waku_peerid()`
Obtain the peer ID of the go-waku node.
**Returns** **Returns**
`JSONResponse` containing the peer ID (base58 encoded) if the function executes successfully. An `error` message otherwise `JSONResponse` containing the peer ID (base58 encoded) if the function executes successfully. An `error` message otherwise
--- ---
### `extern char* gowaku_listen_addresses(int nodeID)` ### `extern char* waku_listen_addresses()`
Obtain the multiaddresses the wakunode is listening to Obtain the multiaddresses the wakunode is listening to
**Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new`
**Returns** **Returns**
`JSONResponse` containing an array of multiaddresses if the function executes successfully. An `error` message otherwise `JSONResponse` containing an array of multiaddresses if the function executes successfully. An `error` message otherwise
## Connecting to peers ## Connecting to peers
### `extern char* gowaku_add_peer(int nodeID, char* address, char* protocolID)` ### `extern char* waku_add_peer(char* address, char* protocolID)`
Add node multiaddress and protocol to the wakunode peerstore Add node multiaddress and protocol to the wakunode peerstore
**Parameters** **Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` 1. `char* address`: multiaddress of the peer being added
2. `char* address`: multiaddress of the peer being added 2. `char* protocolID`: protocol supported by the peer
3. `char* protocolID`: protocol supported by the peer
**Returns** **Returns**
`JSONResponse` containing the peer ID (base58 encoded) of the peer that was added if the function executes successfully. An `error` message otherwise `JSONResponse` containing the peer ID (base58 encoded) of the peer that was added if the function executes successfully. An `error` message otherwise
--- ---
### `extern char* gowaku_dial_peer(int nodeID, char* address, int ms)` ### `extern char* waku_connect(char* address, int ms)`
Dial peer at multiaddress. Connect to peer at multiaddress.
**Parameters** **Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` 1. `char* address`: multiaddress of the peer being dialed
2. `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
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
**Returns** **Returns**
`JSONResponse` with a null `result` if the function executes successfully. An `error` message otherwise `JSONResponse` with a null `result` if the function executes successfully. An `error` message otherwise
--- ---
### `extern char* gowaku_dial_peerid(int nodeID, char* id, int ms)` ### `extern char* waku_connect_peerid(char* id, int ms)`
Dial peer using peerID. Connect to peer using peerID.
**Parameters** **Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` 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. `char* peerID`: peerID to dial. The peer must be already known. It must have been added before with `gowaku_add_peer` or previously dialed with `gowaku_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
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
**Returns** **Returns**
`JSONResponse` with a null `result` if the function executes successfully. An `error` message otherwise `JSONResponse` with a null `result` if the function executes successfully. An `error` message otherwise
--- ---
### `extern char* gowaku_close_peer(int nodeID, char* address)` ### `extern char* waku_disconnect(char* peerID)`
Disconnect a peer using its multiaddress Disconnect a peer using its peerID.
**Parameters** **Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` 1. `char* peerID`: peerID to disconnect.
2. `char* address`: multiaddress of the peer being disconnected.
**Returns** **Returns**
`JSONResponse` with a null `result` if the function executes successfully. An `error` message otherwise `JSONResponse` with a null `result` if the function executes successfully. An `error` message otherwise
--- ---
### `extern char* gowaku_close_peerid(int nodeID, char* id)` ### `extern char* waku_peer_cnt()`
Disconnect a peer using its peerID
**Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new`
2. `char* peerID`: peerID to disconnect.
**Returns**
`JSONResponse` with a null `result` if the function executes successfully. An `error` message otherwise
---
### `extern char* gowaku_peer_cnt(int nodeID)`
Obtain number of connected peers Obtain number of connected peers
**Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new`
**Returns** **Returns**
`JSONResponse` containing an `int` with the number of connected peers. An `error` message otherwise `JSONResponse` containing an `int` with the number of connected peers. An `error` message otherwise
--- ---
### `extern char* gowaku_peers(int nodeID)` ### `extern char* waku_peers()`
Retrieve the list of peers known by the go-waku node Retrieve the list of peers known by the go-waku node
**Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new`
**Returns** **Returns**
`JSONResponse` containing a list of peers. An `error` message otherwise. The list of peers has this format: `JSONResponse` containing a list of peers. An `error` message otherwise. The list of peers has this format:
```json ```js
{ {
"result":[ "result":[
... ...
@ -226,7 +195,7 @@ Retrieve the list of peers known by the go-waku node
## Waku Relay ## Waku Relay
### `extern char* gowaku_content_topic(char* applicationName, unsigned int applicationVersion, char* contentTopicName, char* encoding)` ### `extern char* waku_content_topic(char* applicationName, unsigned int applicationVersion, char* contentTopicName, char* encoding)`
Create a content topic string according to [RFC 23](https://rfc.vac.dev/spec/23/) Create a content topic string according to [RFC 23](https://rfc.vac.dev/spec/23/)
**Parameters** **Parameters**
@ -243,7 +212,7 @@ Create a content topic string according to [RFC 23](https://rfc.vac.dev/spec/23/
-- --
### `extern char* gowaku_pubsub_topic(char* name, char* encoding)` ### `extern char* waku_pubsub_topic(char* name, char* encoding)`
Create a pubsub topic string according to [RFC 23](https://rfc.vac.dev/spec/23/) Create a pubsub topic string according to [RFC 23](https://rfc.vac.dev/spec/23/)
**Parameters** **Parameters**
@ -258,7 +227,7 @@ Create a pubsub topic string according to [RFC 23](https://rfc.vac.dev/spec/23/)
--- ---
### `extern char* gowaku_default_pubsub_topic()` ### `extern char* waku_default_pubsub_topic()`
Returns the default pubsub topic used for exchanging waku messages defined in [RFC 10](https://rfc.vac.dev/spec/10/) Returns the default pubsub topic used for exchanging waku messages defined in [RFC 10](https://rfc.vac.dev/spec/10/)
**Returns** **Returns**
@ -269,15 +238,14 @@ Returns the default pubsub topic used for exchanging waku messages defined in [R
--- ---
### `extern char* gowaku_relay_publish(int nodeID, char* messageJSON, char* topic, int ms)` ### `extern char* waku_relay_publish(char* messageJSON, char* topic, int ms)`
Publish a message using waku relay. Publish a message using waku relay.
**Parameters** **Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` 1. `char* messageJSON`: json string containing the [Waku Message](https://rfc.vac.dev/spec/14/)
2. `char* messageJSON`: json string containing the [Waku Message](https://rfc.vac.dev/spec/14/) ```js
```json
{ {
"payload":"", // base64 encoded payload. gowaku_utils_base64_encode can be used for this "payload":"", // base64 encoded payload. waku_utils_base64_encode can be used for this
"contentTopic: "...", "contentTopic: "...",
"version": 1, "version": 1,
"timestamp": 1647963508000000000 // Unix timestamp in nanoseconds "timestamp": 1647963508000000000 // Unix timestamp in nanoseconds
@ -291,41 +259,83 @@ Publish a message using waku relay.
--- ---
### `extern char* gowaku_enough_peers(int nodeID, char* topic)` ### `extern char* waku_relay_publish_enc_asymmetric(char* messageJSON, char* topic, char* publicKey, char* optionalSigningKey, int ms)`
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
---
### `extern char* waku_relay_publish_enc_symmetric(char* messageJSON, char* topic, char* symmetricKey, char* optionalSigningKey, int ms)`
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
---
### `extern char* waku_enough_peers(char* topic)`
Determine if there are enough peers to publish a message on a topic. Determine if there are enough peers to publish a message on a topic.
**Parameters** **Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` 1. `char* topic`: pubsub topic to verify. Use `NULL` to verify the number of peers in the default pubsub topic
2. `char* topic`: pubsub topic to verify. Use `NULL` to verify the number of peers in the default pubsub topic
**Returns** **Returns**
`JSONResponse` with a boolean indicating if there are enough peers or not. An `error` message otherwise `JSONResponse` with a boolean indicating if there are enough peers or not. An `error` message otherwise
--- ---
### `extern char* gowaku_relay_subscribe(int nodeID, char* topic)` ### `extern char* waku_relay_subscribe(char* topic)`
Subscribe to a WakuRelay topic to receive messages. Subscribe to a WakuRelay topic to receive messages.
**Parameters** **Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` 1. `char* topic`: pubsub topic to subscribe to. Use `NULL` for subscribing to the default pubsub topic
2. `char* topic`: pubsub topic to subscribe to. Use `NULL` for subscribing to the default pubsub topic
**Returns** **Returns**
`JSONResponse` with a subscription ID. An `error` message otherwise `JSONResponse` with a subscription ID. An `error` message otherwise
**Events** **Events**
When a message is received, a ``"message"` event` is emitted containing the message, pubsub topic, and nodeID in which the message was received. Here's an example event that could be received: 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:
```json ```js
{ {
"nodeId":1,
"type":"message", "type":"message",
"event":{ "event":{
"subscriptionID":"...",
"pubsubTopic":"/waku/2/default-waku/proto", "pubsubTopic":"/waku/2/default-waku/proto",
"messageID":"0x6496491e40dbe0b6c3a2198c2426b16301688a2daebc4f57ad7706115eac3ad1", "messageID":"0x6496491e40dbe0b6c3a2198c2426b16301688a2daebc4f57ad7706115eac3ad1",
"wakuMessage":{ "wakuMessage":{
"payload":"...", // base64 encoded message. Use gowaku_decode_data to decode "payload":"...", // base64 encoded message. Use waku_decode_data to decode
"contentTopic":"ABC", "contentTopic":"ABC",
"version":1, "version":1,
"timestamp":1647826358000000000 // in nanoseconds "timestamp":1647826358000000000 // in nanoseconds
@ -334,87 +344,171 @@ When a message is received, a ``"message"` event` is emitted containing the mess
} }
``` ```
### `extern char* gowaku_relay_close_subscription(int nodeID, char* subsID)` ---
Closes a waku relay subscription. No more messages will be received from this subscription
### `extern char* waku_relay_unsubscribe(char* topic)`
Closes the subscription to a pubsub topic.
**Parameters** **Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` 1. `char* topic`: pubsub topic to unsubscribe from. Use `NULL` for unsubscribe from the default pubsub topic
2. `char* subsID`: subscription ID to close
**Returns** **Returns**
`JSONResponse` with null `response` if successful. An `error` message otherwise `JSONResponse` with null `response` if successful. An `error` message otherwise
## Waku LightPush
### `extern char* waku_lightpush_publish(char* messageJSON, char* topic, char* peerID, int ms)`
Publish a message using waku lightpush.
**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* 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
**Returns**
`JSONResponse` containing the message ID. An `error` message otherwise
--- ---
### `extern char* gowaku_relay_unsubscribe_from_topic(int nodeID, char* topic)` ### `extern char* waku_lightpush_publish_enc_asymmetric(char* messageJSON, char* topic, char* publicKey, char* optionalSigningKey, char* peerID, int ms)`
Closes the pubsub subscription to a pubsub topic. Existing subscriptions will not be closed, but they will stop receiving messages Publish a message encrypted with a secp256k1 public key using waku lightpush
**Parameters** **Parameters**
1. `int nodeID`: the node identifier obtained from a succesful execution of `gowaku_new` 1. `char* messageJSON`: json string containing the [Waku Message](https://rfc.vac.dev/spec/14/)
2. `char* topic`: pubsub topic to unsubscribe. Use `NULL` for unsubscribe from the default pubsub topic ```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** **Returns**
`JSONResponse` with null `response` if successful. An `error` message otherwise `JSONResponse` containing the message ID. An `error` message otherwise
---
### `extern char* waku_lightpush_publish_enc_symmetric(char* messageJSON, char* topic, char* symmetricKey, char* optionalSigningKey, char* peerID, int ms)`
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. `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
## Waku Store
### `extern char* waku_store_query(char* queryJSON, char* peerID, int ms)`
Query historic messages using waku store protocol.
**Parameters**
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
**Returns**
`JSONResponse` containing the store response. An `error` message otherwise
```js
{
"result": {
"messages": [ ... ], // array of waku messages
"pagingOptions": { // optional pagination information
"pageSize": 40, // number
"cursor": { // optional
"digest": ...,
"receiverTime": ...,
"senderTime": ...,
"pubsubTopic" ...,
},
"forward": true, // sort order
}
}
}
```
## Waku Message Utils ## Waku Message Utils
### `extern char* gowaku_encode_data(char* data, char* keyType, char* key, char* signingKey, int version)`
Encode a byte array according to [RFC 26](https://rfc.vac.dev/spec/26/). This function can be used to encrypt the payload of a waku message
**Parameters** ### `extern char* waku_utils_base64_encode(char* data)`
1. `char* data`: byte array to encode in base64 format. (gowaku_utils_base64_encode can be used to encode the message) Encode a byte array to base64 useful for creating the payload of a waku message in the format understood by `waku_relay_publish`
2. `char* keyType`: defines the type of key to use:
- `NONE`: no encryption will be applied
- `ASYMMETRIC`: encrypt the payload using a secp256k1 public key
- `SYMMETRIC`: encrypt the payload using a 32 bit key.
3. `char* key`: hex key (`0x123...abc`) used for encrypting the `data`.
- When `version` is 0: No encryption is used
- When `version` is 1
- If using `ASYMMETRIC` encoding, `key` must contain a secp256k1 public key to encrypt the data with
- If using `SYMMETRIC` encoding, `key` must contain a 32 bytes symmetric key.
4. `char* signingKey`: Hex string containing a secp256k1 private key to sign the encoded message, It's optional. To not sign the message use `NULL` instead.
5. `int version`: is used to define the type of payload encryption
**Returns**
`JSONResponse` with the base64 encoded payload. An `error` message otherwise.
---
### `extern char* gowaku_decode_data(char* data, char* keyType, char* key, int version)`
Decode a byte array according to [RFC 26](https://rfc.vac.dev/spec/26/). This function can be used to decrypt the payload of a waku message
**Parameters**
1. `char* data`: byte array to decode, in base64.
2. `char* keyType`: defines the type of key to use:
- `NONE`: no encryption was used in the payload
- `ASYMMETRIC`: decrypt the payload using a secp256k1 public key
- `SYMMETRIC`: decrypt the payload using a 32 bit key.
3. `char* key`: hex key (`0x123...abc`) used for decrypting the `data`.
- When `version` is 0: No encryption is used
- When `version` is 1
- If using `ASYMMETRIC` encoding, `key` must contain a secp256k1 private key to decrypt the data
- If using `SYMMETRIC` encoding, `key` must contain a 32 bytes symmetric key.
4. `int version`: is used to define the type of payload encryption
**Returns**
`JSONResponse` with the decoded payload. An `error` message otherwise. The decoded payload has this format:
```json
{
"result": {
"pubkey":"0x04123...abc", // secp256k1 public key
"signature":"0x123...abc", // secp256k1 signature
"data":"...", // base64 encoded
"padding":"..." // base64 encoded
}
}
```
---
### `extern char* gowaku_utils_base64_encode(char* data)`
Encode a byte array to base64 useful for creating the payload of a waku message in the format understood by `gowaku_relay_publish`
**Parameters** **Parameters**
1. `char* data`: byte array to encode 1. `char* data`: byte array to encode
@ -424,7 +518,7 @@ A `char *` containing the base64 encoded byte array
--- ---
### `extern char* gowaku_utils_base64_decode(char* data)` ### `extern char* waku_utils_base64_decode(char* data)`
Decode a base64 string (useful for reading the payload from waku messages) Decode a base64 string (useful for reading the payload from waku messages)
**Parameters** **Parameters**
@ -433,6 +527,12 @@ Decode a base64 string (useful for reading the payload from waku messages)
**Returns** **Returns**
`JSONResponse` with the decoded payload. An `error` message otherwise. The decoded payload has this format: `JSONResponse` with the decoded payload. An `error` message otherwise. The decoded payload has this format:
---
### `extern void waku_utils_free(char* data)`
Frees a char* since all strings returned by gowaku are allocated in the C heap using malloc.
**Parameters**
1. `char* data`: variable to free
# Copyright # Copyright

View File

@ -27,6 +27,7 @@ func main() {}
// - nodeKey: secp256k1 private key. Default random // - nodeKey: secp256k1 private key. Default random
// - keepAliveInterval: interval in seconds to ping all peers // - keepAliveInterval: interval in seconds to ping all peers
// - relay: Enable WakuRelay. Default `true` // - relay: Enable WakuRelay. Default `true`
// - minPeersToPublish: The minimum number of peers required on a topic to allow broadcasting a message. Default `0`
func waku_new(configJSON *C.char) *C.char { func waku_new(configJSON *C.char) *C.char {
response := mobile.NewNode(C.GoString(configJSON)) response := mobile.NewNode(C.GoString(configJSON))
return C.CString(response) return C.CString(response)
@ -114,8 +115,8 @@ func waku_default_pubsub_topic() *C.char {
} }
//export waku_set_event_callback //export waku_set_event_callback
// Register callback to act as signal handler and receive application signal // Register callback to act as signal handler and receive application signals
// (in JSON) which are used o react to asynchronous events in waku. The function // (in JSON) which are used to react to asynchronous events in waku. The function
// signature for the callback should be `void myCallback(char* signalJSON)` // signature for the callback should be `void myCallback(char* signalJSON)`
func waku_set_event_callback(cb unsafe.Pointer) { func waku_set_event_callback(cb unsafe.Pointer) {
mobile.SetEventCallback(cb) mobile.SetEventCallback(cb)

View File

@ -31,7 +31,7 @@ func waku_lightpush_publish_enc_asymmetric(messageJSON *C.char, topic *C.char, p
//export waku_lightpush_publish_enc_symmetric //export waku_lightpush_publish_enc_symmetric
// Publish a message encrypted with a 32 bytes symmetric key using waku relay. Use NULL for topic to use the default pubsub topic. // Publish a message encrypted with a 32 bytes symmetric key using waku relay. Use NULL for topic to use the default pubsub topic.
// peerID should contain the ID of a peer supporting the lightpush protocol. Use NULL to automatically select a node // peerID should contain the ID of a peer supporting the lightpush protocol. Use NULL to automatically select a node
// publicKey must be a hex string prefixed with "0x" containing a 32 bytes symmetric key // symmetricKey must be a hex string prefixed with "0x" containing a 32 bytes symmetric key
// optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise // optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
// If ms is greater than 0, the broadcast of the message must happen before the timeout // If ms is greater than 0, the broadcast of the message must happen before the timeout
// (in milliseconds) is reached, or an error will be returned. // (in milliseconds) is reached, or an error will be returned.

View File

@ -15,16 +15,16 @@ func waku_relay_enough_peers(topic *C.char) *C.char {
} }
//export waku_relay_publish //export waku_relay_publish
// Publish a message using waku relay. Use NULL for topic to use the default pubsub topic // Publish a message using waku relay and returns the message ID. Use NULL for topic to use the default pubsub topic
// If ms is greater than 0, the broadcast of the message must happen before the timeout // If ms is greater than 0, the broadcast of the message must happen before the timeout
// (in milliseconds) is reached, or an error will be returned // (in milliseconds) is reached, or an error will be returned.
func waku_relay_publish(messageJSON *C.char, topic *C.char, ms C.int) *C.char { func waku_relay_publish(messageJSON *C.char, topic *C.char, ms C.int) *C.char {
response := mobile.RelayPublish(C.GoString(messageJSON), C.GoString(topic), int(ms)) response := mobile.RelayPublish(C.GoString(messageJSON), C.GoString(topic), int(ms))
return C.CString(response) return C.CString(response)
} }
//export waku_relay_publish_enc_asymmetric //export waku_relay_publish_enc_asymmetric
// Publish a message encrypted with a secp256k1 public key using waku relay. Use NULL for topic to use the default pubsub topic. // Publish a message encrypted with a secp256k1 public key using waku relay and returns the message ID. Use NULL for topic to use the default pubsub topic.
// publicKey must be a hex string prefixed with "0x" containing a valid secp256k1 public key. // publicKey must be a hex string prefixed with "0x" containing a valid secp256k1 public key.
// optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise // optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
// If ms is greater than 0, the broadcast of the message must happen before the timeout // If ms is greater than 0, the broadcast of the message must happen before the timeout
@ -35,8 +35,8 @@ func waku_relay_publish_enc_asymmetric(messageJSON *C.char, topic *C.char, publi
} }
//export waku_relay_publish_enc_symmetric //export waku_relay_publish_enc_symmetric
// Publish a message encrypted with a 32 bytes symmetric key using waku relay. Use NULL for topic to use the default pubsub topic. // Publish a message encrypted with a 32 bytes symmetric key using waku relay and returns the message ID. Use NULL for topic to use the default pubsub topic.
// publicKey must be a hex string prefixed with "0x" containing a 32 bytes symmetric key // symmetricKey must be a hex string prefixed with "0x" containing a 32 bytes symmetric key
// optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise // optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
// If ms is greater than 0, the broadcast of the message must happen before the timeout // If ms is greater than 0, the broadcast of the message must happen before the timeout
// (in milliseconds) is reached, or an error will be returned. // (in milliseconds) is reached, or an error will be returned.
@ -47,8 +47,8 @@ func waku_relay_publish_enc_symmetric(messageJSON *C.char, topic *C.char, symmet
//export waku_relay_subscribe //export waku_relay_subscribe
// Subscribe to a WakuRelay topic. Set the topic to NULL to subscribe // Subscribe to a WakuRelay topic. Set the topic to NULL to subscribe
// to the default topic. Returns a json response. When a message is received, // to the default topic. Returns a json response. When a message is received,
// a "message" event is emitted containing the message and pubsub topic in which // a "message" event is emitted containing the message and pubsub topic in which
// the message was received // the message was received
func waku_relay_subscribe(topic *C.char) *C.char { func waku_relay_subscribe(topic *C.char) *C.char {
response := mobile.RelaySubscribe(C.GoString(topic)) response := mobile.RelaySubscribe(C.GoString(topic))

View File

@ -29,7 +29,8 @@ import (
// "forward": true, // sort order // "forward": true, // sort order
// } // }
// } // }
// peerID should contain the ID of a peer supporting the lightpush protocol. Use NULL to automatically select a node // 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
// peerID should contain the ID of a peer supporting the store protocol. Use NULL to automatically select a node
// If ms is greater than 0, the broadcast of the message must happen before the timeout // If ms is greater than 0, the broadcast of the message must happen before the timeout
// (in milliseconds) is reached, or an error will be returned // (in milliseconds) is reached, or an error will be returned
func waku_store_query(queryJSON *C.char, peerID *C.char, ms C.int) *C.char { func waku_store_query(queryJSON *C.char, peerID *C.char, ms C.int) *C.char {