Skip to content
105 changes: 104 additions & 1 deletion standards/application/waku-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ An alternative would be to choose a programming language. However, such choice m
### Primitive types and general guidelines

- No `default` means that the value is mandatory, meaning a `default` value implies an optional parameter.
- Primitive types are `string`, `int`, `bool`, `enum` and `uint`
- Primitive types are `string`, `int`, `bool`, `byte`, `enum` and `uint`
- Complex pre-defined types are:
- `object`: object and other nested types.
- `array`: iterable object containing values of all the same type.
Expand Down Expand Up @@ -302,6 +302,109 @@ If the `mode` set is `core`, the initialised `WakuNode` SHOULD use:
`edge` mode SHOULD be used if node functions in resource restricted environment,
whereas `core` SHOULD be used if node has no strong hardware or bandwidth restrictions.

## Send messages

#### Type definitions

```yaml
types:
SendMessage:
type: object
fields:
contentTopic:
type: string
description: "Content-based filtering field as defined in [TOPICS](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics)"
payload:
type: array<byte>
description: "The message data to be sent."
ephemeral:
type: bool
default: false
description: "Whether the message is ephemeral. Read at [ATTRIBUTES](https://github.com/vacp2p/rfc-index/blob/main/waku/standards/core/14/message.md#message-attributes)"

RequestId:
type: string
description: "A unique identifier for a request"
```

#### Function definitions

```yaml
functions:
send:
description: "Send a message through the network."
parameters:
- name: message
type: SendMessage
description: "The message to send"
returns:
type: result<RequestId, error>
```

#### Extended definitions

When `message` is sent with `contentTopic` for the first time,
the node SHOULD trigger a subscription based on `Subscribe to messages` section.

The node uses [P2P-RELIABILITY](/standards/application/p2p-reliability.md) strategies to ensure message delivery.

## Event source

#### Type definitions

```yaml
types:
MessageSentEvent:
type: object
fields:
eventType:
type: string
default: "message:sent"
description: "Event type identifier"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I agree with this syntax. WDYM by default: "message:sent"? what other vale could it be?

I would suggest to opt for the syntax proposed in https://github.com/waku-org/specs/pull/86/files

The object that emit events, define the "topics" of the events (eg message:sent):

types:
  EventEmitter:
    type: event_emitter
    description: "An event emitter for general node events."
    events:
      "error:subscribe":
        type: string
        description: "Event emitted when subscription to a content topic irremediably fails. The event contains an error message."

And here, if you want you can have type: MessageSentEvent instead of type: string and defined MessageSentEvent with 2 fields: message_hash and request_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYM by default: "message:sent"

I meant that eventType is a property on an object that has value of message:sent

I don't understand this syntax:

events:
      "error:subscribe":
          type: string
          description: "..."

what is error:subscribe and how exactly it is a string and how to get access to it?

for the syntax I used message:sent is a value of eventType property that is defined on the type of MessageSent object

wdyt @fryorcraken

requestId:
type: RequestId
description: "The request ID associated with the sent message"

MessageErrorEvent:
type: object
fields:
eventType:
type: string
default: "message:error"
description: "Event type identifier"
requestId:
type: RequestId
description: "The request ID associated with the failed message"
error:
type: string
description: "Error message describing what went wrong"

MessageAckEvent:
type: object
fields:
eventType:
type: string
default: "message:ack"
description: "Event type identifier"
requestId:
type: RequestId
description: "The request ID associated with the acknowledged message"
ackType:
type: string
description: "Type of acknowledgment (e.g., 'store', 'filter')"

EventSource:
type: object
description: "Event source for message-related events"
fields:
onEvent:
type: function
description: "Callback for message:sent events"
parameters:
- name: event
type: MessageSentEvent | MessageErrorEvent | MessageAckEvent
```

## The Validation API

[WAKU2-RLN-RELAY](https://github.com/vacp2p/rfc-index/blob/main/waku/standards/core/17/rln-relay.md) is currently the primary message validation mechanism in place.
Expand Down
Loading