diff --git a/.cspell.json b/.cspell.json index 03e3041bda..2c619023e7 100644 --- a/.cspell.json +++ b/.cspell.json @@ -42,6 +42,7 @@ "mplex", "muxed", "muxer", + "mvps", "nodekey", "peerhave", "prettierignore", diff --git a/src/lib/chat_message/index.ts b/src/lib/chat_message/index.ts index e12db9462c..04e3389d17 100644 --- a/src/lib/chat_message/index.ts +++ b/src/lib/chat_message/index.ts @@ -2,6 +2,13 @@ import { Reader } from 'protobufjs/minimal'; import * as proto from '../../proto/chat/v2/chat_message'; +/** + * ChatMessage is used by the various show case waku apps that demonstrates + * waku used as the network layer for chat group applications. + * + * This is included to help building PoC and MVPs. Apps that aim to be + * production ready should use a more appropriate data structure. + */ export class ChatMessage { public constructor(public proto: proto.ChatMessage) {} @@ -23,11 +30,19 @@ export class ChatMessage { }); } + /** + * Decode a protobuf payload to a ChatMessage. + * @param bytes The payload to decode. + */ static decode(bytes: Uint8Array): ChatMessage { const protoMsg = proto.ChatMessage.decode(Reader.create(bytes)); return new ChatMessage(protoMsg); } + /** + * Encode this ChatMessage to a byte array, to be used as a protobuf payload. + * @returns The encoded payload. + */ encode(): Uint8Array { return proto.ChatMessage.encode(this.proto).finish(); } diff --git a/src/lib/waku_relay/relay_heartbeat.ts b/src/lib/waku_relay/relay_heartbeat.ts index 21b81cb83f..054af00c96 100644 --- a/src/lib/waku_relay/relay_heartbeat.ts +++ b/src/lib/waku_relay/relay_heartbeat.ts @@ -1,3 +1,8 @@ +/** + * @hidden + * @module + */ + import Gossipsub from 'libp2p-gossipsub'; import { Heartbeat } from 'libp2p-gossipsub/src/heartbeat'; import { shuffle } from 'libp2p-gossipsub/src/utils'; diff --git a/src/lib/waku_store/index.ts b/src/lib/waku_store/index.ts index 1a328cb63c..329265b04e 100644 --- a/src/lib/waku_store/index.ts +++ b/src/lib/waku_store/index.ts @@ -10,15 +10,21 @@ import { HistoryRPC } from './history_rpc'; export const StoreCodec = '/vac/waku/store/2.0.0-beta3'; +/** + * Implements the [Waku v2 Store protocol](https://rfc.vac.dev/spec/13/). + */ export class WakuStore { constructor(public libp2p: Libp2p) {} /** - * Retrieve history from given peer - * @param peerId - * @param contentTopics - * @param pubsubTopic - * @throws if not able to reach peer + * Query given peer using Waku Store. + * + * @param peerId The peer to query. + * @param contentTopics The content topics to retrieve, leave empty to + * retrieve all messages. + * @param pubsubTopic The pubsub topic to retrieve. Currently, all waku nodes + * use the same pubsub topic. This is reserved for future applications. + * @throws If not able to reach the peer to query. */ async queryHistory( peerId: PeerId, diff --git a/src/test_utils/async_fs.ts b/src/test_utils/async_fs.ts index dc671f45ba..fff62e3903 100644 --- a/src/test_utils/async_fs.ts +++ b/src/test_utils/async_fs.ts @@ -1,3 +1,10 @@ +/** + * Various promisify of fs utilities. + * + * @hidden + * @module + */ + import fs, { promises as asyncFs } from 'fs'; import { promisify } from 'util'; diff --git a/src/test_utils/constants.ts b/src/test_utils/constants.ts index dd832689df..152e58b9a2 100644 --- a/src/test_utils/constants.ts +++ b/src/test_utils/constants.ts @@ -1,2 +1,9 @@ +/** + * Some constants for test purposes. + * + * @hidden + * @module + */ + export const NOISE_KEY_1 = Buffer.alloc(32, 1); export const NOISE_KEY_2 = Buffer.alloc(32, 1); diff --git a/src/test_utils/index.ts b/src/test_utils/index.ts index 59bbdc199b..e97b1a2943 100644 --- a/src/test_utils/index.ts +++ b/src/test_utils/index.ts @@ -1,3 +1,10 @@ +/** + * A collection of tools to test the WakuJS library. + * + * @hidden + * @module + */ + export * from './async_fs'; export * from './constants'; export * from './log_file'; diff --git a/src/test_utils/log_file.ts b/src/test_utils/log_file.ts index 6412f39c20..70e5f0aca5 100644 --- a/src/test_utils/log_file.ts +++ b/src/test_utils/log_file.ts @@ -1,3 +1,10 @@ +/** + * Utilities to make it help check nim-waku logs. + * + * @hidden + * @module + */ + import { Context } from 'mocha'; import pTimeout from 'p-timeout'; import { Tail } from 'tail'; diff --git a/src/test_utils/nim_waku.ts b/src/test_utils/nim_waku.ts index 19b5725399..bb9040499a 100644 --- a/src/test_utils/nim_waku.ts +++ b/src/test_utils/nim_waku.ts @@ -1,3 +1,8 @@ +/** + * @hidden + * @module + */ + import { ChildProcess, spawn } from 'child_process'; import { randomInt } from 'crypto';