From 9fe04d85f3b5232c18196c5267c4d8da29934b23 Mon Sep 17 00:00:00 2001 From: Danish Arora <35004822+danisharora099@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:52:32 +0530 Subject: [PATCH] chore: use `pubsubTopic`/`pubsubTopics` across the codebase (#1653) * chore: change all references of pubSubTopic to pubsubTopic * change references of pubSubTopics to pubsubTopics * flag words in cspell --- .cspell.json | 4 +- packages/core/src/lib/connection_manager.ts | 8 +-- packages/core/src/lib/filter/index.ts | 40 +++++++------- packages/core/src/lib/keep_alive_manager.ts | 4 +- packages/core/src/lib/light_push/index.ts | 14 ++--- packages/core/src/lib/light_push/push_rpc.ts | 4 +- .../core/src/lib/message/version_0.spec.ts | 14 ++--- packages/core/src/lib/message/version_0.ts | 14 ++--- packages/core/src/lib/store/history_rpc.ts | 4 +- packages/core/src/lib/store/index.ts | 20 +++---- packages/core/src/lib/wait_for_remote_peer.ts | 6 +-- packages/core/src/lib/waku.ts | 4 +- packages/interfaces/src/filter.ts | 2 +- packages/interfaces/src/message.ts | 10 ++-- packages/interfaces/src/protocols.ts | 2 +- packages/interfaces/src/relay.ts | 2 +- .../message-encryption/src/decoded_message.ts | 4 +- packages/message-encryption/src/ecies.spec.ts | 16 +++--- packages/message-encryption/src/ecies.ts | 18 +++---- .../message-encryption/src/symmetric.spec.ts | 16 +++--- packages/message-encryption/src/symmetric.ts | 18 +++---- packages/message-hash/src/index.spec.ts | 12 ++--- packages/relay/src/index.ts | 52 +++++++++---------- packages/relay/src/message_validator.spec.ts | 8 +-- packages/relay/src/topic_only_message.ts | 8 +-- packages/sdk/src/create.ts | 18 +++---- packages/tests/src/message_collector.ts | 10 ++-- packages/tests/src/node/node.ts | 20 +++---- .../tests/filter/multiple_pubsub.node.spec.ts | 6 +-- packages/tests/tests/filter/utils.ts | 8 +-- .../light-push/multiple_pubsub.node.spec.ts | 14 ++--- packages/tests/tests/light-push/utils.ts | 8 +-- packages/tests/tests/relay.node.spec.ts | 24 ++++----- .../tests/sharding/peer_management.spec.ts | 12 ++--- .../tests/sharding/running_nodes.spec.ts | 10 ++-- .../tests/tests/store/cursor.node.spec.ts | 4 +- .../tests/tests/store/multiple_pubsub.spec.ts | 2 +- packages/tests/tests/store/utils.ts | 10 ++-- packages/tests/tests/utils.spec.ts | 2 +- 39 files changed, 226 insertions(+), 226 deletions(-) diff --git a/.cspell.json b/.cspell.json index c87caa07e2..af91ca295d 100644 --- a/.cspell.json +++ b/.cspell.json @@ -1,5 +1,5 @@ { - "version": "0.1", + "version": "0.2", "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json", "language": "en", "words": [ @@ -123,7 +123,7 @@ "Привет", "مرحبا" ], - "flagWords": [], + "flagWords": ["pubSub", "pubSubTopics", "pubSubTopic"], "ignorePaths": [ "package.json", "package-lock.json", diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index 7d8e3d2845..4116df12f0 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -45,7 +45,7 @@ export class ConnectionManager peerId: string, libp2p: Libp2p, keepAliveOptions: KeepAliveOptions, - pubSubTopics: PubSubTopic[], + pubsubTopics: PubSubTopic[], relay?: IRelay, options?: ConnectionManagerOptions ): ConnectionManager { @@ -54,7 +54,7 @@ export class ConnectionManager instance = new ConnectionManager( libp2p, keepAliveOptions, - pubSubTopics, + pubsubTopics, relay, options ); @@ -500,9 +500,9 @@ export class ConnectionManager // If there's no shard information, simply return true if (!shardInfo) return true; - const pubSubTopics = shardInfoToPubSubTopics(shardInfo); + const pubsubTopics = shardInfoToPubSubTopics(shardInfo); - const isTopicConfigured = pubSubTopics.some((topic) => + const isTopicConfigured = pubsubTopics.some((topic) => this.configuredPubSubTopics.includes(topic) ); return isTopicConfigured; diff --git a/packages/core/src/lib/filter/index.ts b/packages/core/src/lib/filter/index.ts index d0b6d68c58..a7e1cf5bf5 100644 --- a/packages/core/src/lib/filter/index.ts +++ b/packages/core/src/lib/filter/index.ts @@ -50,7 +50,7 @@ export const FilterCodecs = { class Subscription { private readonly peer: Peer; - private readonly pubSubTopic: PubSubTopic; + private readonly pubsubTopic: PubSubTopic; private newStream: (peer: Peer) => Promise; private subscriptionCallbacks: Map< @@ -59,12 +59,12 @@ class Subscription { >; constructor( - pubSubTopic: PubSubTopic, + pubsubTopic: PubSubTopic, remotePeer: Peer, newStream: (peer: Peer) => Promise ) { this.peer = remotePeer; - this.pubSubTopic = pubSubTopic; + this.pubsubTopic = pubsubTopic; this.newStream = newStream; this.subscriptionCallbacks = new Map(); } @@ -80,7 +80,7 @@ class Subscription { const stream = await this.newStream(this.peer); const request = FilterSubscribeRpc.createSubscribeRequest( - this.pubSubTopic, + this.pubsubTopic, contentTopics ); @@ -145,7 +145,7 @@ class Subscription { async unsubscribe(contentTopics: ContentTopic[]): Promise { const stream = await this.newStream(this.peer); const unsubscribeRequest = FilterSubscribeRpc.createUnsubscribeRequest( - this.pubSubTopic, + this.pubsubTopic, contentTopics ); @@ -194,7 +194,7 @@ class Subscription { const stream = await this.newStream(this.peer); const request = FilterSubscribeRpc.createUnsubscribeAllRequest( - this.pubSubTopic + this.pubsubTopic ); try { @@ -229,35 +229,35 @@ class Subscription { log("No subscription callback available for ", contentTopic); return; } - await pushMessage(subscriptionCallback, this.pubSubTopic, message); + await pushMessage(subscriptionCallback, this.pubsubTopic, message); } } class Filter extends BaseProtocol implements IReceiver { - private readonly pubSubTopics: PubSubTopic[] = []; + private readonly pubsubTopics: PubSubTopic[] = []; private activeSubscriptions = new Map(); private readonly NUM_PEERS_PROTOCOL = 1; private getActiveSubscription( - pubSubTopic: PubSubTopic, + pubsubTopic: PubSubTopic, peerIdStr: PeerIdStr ): Subscription | undefined { - return this.activeSubscriptions.get(`${pubSubTopic}_${peerIdStr}`); + return this.activeSubscriptions.get(`${pubsubTopic}_${peerIdStr}`); } private setActiveSubscription( - pubSubTopic: PubSubTopic, + pubsubTopic: PubSubTopic, peerIdStr: PeerIdStr, subscription: Subscription ): Subscription { - this.activeSubscriptions.set(`${pubSubTopic}_${peerIdStr}`, subscription); + this.activeSubscriptions.set(`${pubsubTopic}_${peerIdStr}`, subscription); return subscription; } constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) { super(FilterCodecs.SUBSCRIBE, libp2p.components); - this.pubSubTopics = options?.pubSubTopics || [DefaultPubSubTopic]; + this.pubsubTopics = options?.pubsubTopics || [DefaultPubSubTopic]; libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => { log("Failed to register ", FilterCodecs.PUSH, e); @@ -267,9 +267,9 @@ class Filter extends BaseProtocol implements IReceiver { } async createSubscription( - pubSubTopic: string = DefaultPubSubTopic + pubsubTopic: string = DefaultPubSubTopic ): Promise { - ensurePubsubTopicIsConfigured(pubSubTopic, this.pubSubTopics); + ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics); //TODO: get a relevant peer for the topic/shard // https://github.com/waku-org/js-waku/pull/1586#discussion_r1336428230 @@ -281,11 +281,11 @@ class Filter extends BaseProtocol implements IReceiver { )[0]; const subscription = - this.getActiveSubscription(pubSubTopic, peer.id.toString()) ?? + this.getActiveSubscription(pubsubTopic, peer.id.toString()) ?? this.setActiveSubscription( - pubSubTopic, + pubsubTopic, peer.id.toString(), - new Subscription(pubSubTopic, peer, this.getStream.bind(this, peer)) + new Subscription(pubsubTopic, peer, this.getStream.bind(this, peer)) ); return subscription; @@ -385,7 +385,7 @@ export function wakuFilter( async function pushMessage( subscriptionCallback: SubscriptionCallback, - pubSubTopic: PubSubTopic, + pubsubTopic: PubSubTopic, message: WakuMessage ): Promise { const { decoders, callback } = subscriptionCallback; @@ -399,7 +399,7 @@ async function pushMessage( try { const decodePromises = decoders.map((dec) => dec - .fromProtoObj(pubSubTopic, message as IProtoMessage) + .fromProtoObj(pubsubTopic, message as IProtoMessage) .then((decoded) => decoded || Promise.reject("Decoding failed")) ); diff --git a/packages/core/src/lib/keep_alive_manager.ts b/packages/core/src/lib/keep_alive_manager.ts index 9746f52869..d731dfb2cf 100644 --- a/packages/core/src/lib/keep_alive_manager.ts +++ b/packages/core/src/lib/keep_alive_manager.ts @@ -118,12 +118,12 @@ export class KeepAliveManager { ): NodeJS.Timeout[] { // send a ping message to each PubSubTopic the peer is part of const intervals: NodeJS.Timeout[] = []; - for (const topic of relay.pubSubTopics) { + for (const topic of relay.pubsubTopics) { const meshPeers = relay.getMeshPeers(topic); if (!meshPeers.includes(peerIdStr)) continue; const encoder = createEncoder({ - pubSubTopic: topic, + pubsubTopic: topic, contentTopic: RelayPingContentTopic, ephemeral: true }); diff --git a/packages/core/src/lib/light_push/index.ts b/packages/core/src/lib/light_push/index.ts index 547d1372ff..d7b7b4b6b3 100644 --- a/packages/core/src/lib/light_push/index.ts +++ b/packages/core/src/lib/light_push/index.ts @@ -42,18 +42,18 @@ type PreparePushMessageResult = * Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/). */ class LightPush extends BaseProtocol implements ILightPush { - private readonly pubSubTopics: PubSubTopic[]; + private readonly pubsubTopics: PubSubTopic[]; private readonly NUM_PEERS_PROTOCOL = 1; constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) { super(LightPushCodec, libp2p.components); - this.pubSubTopics = options?.pubSubTopics ?? [DefaultPubSubTopic]; + this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic]; } private async preparePushMessage( encoder: IEncoder, message: IMessage, - pubSubTopic: string + pubsubTopic: string ): Promise { try { if (!isSizeValid(message.payload)) { @@ -70,7 +70,7 @@ class LightPush extends BaseProtocol implements ILightPush { }; } - const query = PushRpc.createRequest(protoMessage, pubSubTopic); + const query = PushRpc.createRequest(protoMessage, pubsubTopic); return { query, error: null }; } catch (error) { log("Failed to prepare push message", error); @@ -83,15 +83,15 @@ class LightPush extends BaseProtocol implements ILightPush { } async send(encoder: IEncoder, message: IMessage): Promise { - const { pubSubTopic } = encoder; - ensurePubsubTopicIsConfigured(pubSubTopic, this.pubSubTopics); + const { pubsubTopic } = encoder; + ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics); const recipients: PeerId[] = []; const { query, error: preparationError } = await this.preparePushMessage( encoder, message, - pubSubTopic + pubsubTopic ); if (preparationError || !query) { diff --git a/packages/core/src/lib/light_push/push_rpc.ts b/packages/core/src/lib/light_push/push_rpc.ts index fa69f96cf8..7eb0d8f654 100644 --- a/packages/core/src/lib/light_push/push_rpc.ts +++ b/packages/core/src/lib/light_push/push_rpc.ts @@ -7,13 +7,13 @@ export class PushRpc { static createRequest( message: proto.WakuMessage, - pubSubTopic: string + pubsubTopic: string ): PushRpc { return new PushRpc({ requestId: uuid(), request: { message: message, - pubsubTopic: pubSubTopic + pubsubTopic: pubsubTopic }, response: undefined }); diff --git a/packages/core/src/lib/message/version_0.spec.ts b/packages/core/src/lib/message/version_0.spec.ts index c27dadac7b..4ee67ff165 100644 --- a/packages/core/src/lib/message/version_0.spec.ts +++ b/packages/core/src/lib/message/version_0.spec.ts @@ -11,7 +11,7 @@ describe("Waku Message version 0", function () { fc.string({ minLength: 1 }), fc.string({ minLength: 1 }), fc.uint8Array({ minLength: 1 }), - async (contentTopic, pubSubTopic, payload) => { + async (contentTopic, pubsubTopic, payload) => { const encoder = createEncoder({ contentTopic }); @@ -19,12 +19,12 @@ describe("Waku Message version 0", function () { const decoder = createDecoder(contentTopic); const protoResult = await decoder.fromWireToProtoObj(bytes); const result = (await decoder.fromProtoObj( - pubSubTopic, + pubsubTopic, protoResult! )) as DecodedMessage; expect(result.contentTopic).to.eq(contentTopic); - expect(result.pubSubTopic).to.eq(pubSubTopic); + expect(result.pubsubTopic).to.eq(pubsubTopic); expect(result.version).to.eq(0); expect(result.ephemeral).to.be.false; expect(result.payload).to.deep.eq(payload); @@ -40,7 +40,7 @@ describe("Waku Message version 0", function () { fc.string({ minLength: 1 }), fc.string({ minLength: 1 }), fc.uint8Array({ minLength: 1 }), - async (contentTopic, pubSubTopic, payload) => { + async (contentTopic, pubsubTopic, payload) => { const encoder = createEncoder({ contentTopic, ephemeral: true @@ -49,7 +49,7 @@ describe("Waku Message version 0", function () { const decoder = createDecoder(contentTopic); const protoResult = await decoder.fromWireToProtoObj(bytes); const result = (await decoder.fromProtoObj( - pubSubTopic, + pubsubTopic, protoResult! )) as DecodedMessage; @@ -65,7 +65,7 @@ describe("Waku Message version 0", function () { fc.string({ minLength: 1 }), fc.string({ minLength: 1 }), fc.uint8Array({ minLength: 1 }), - async (contentTopic, pubSubTopic, payload) => { + async (contentTopic, pubsubTopic, payload) => { // Encode the length of the payload // Not a relevant real life example const metaSetter = ( @@ -86,7 +86,7 @@ describe("Waku Message version 0", function () { const decoder = createDecoder(contentTopic); const protoResult = await decoder.fromWireToProtoObj(bytes); const result = (await decoder.fromProtoObj( - pubSubTopic, + pubsubTopic, protoResult! )) as DecodedMessage; diff --git a/packages/core/src/lib/message/version_0.ts b/packages/core/src/lib/message/version_0.ts index 0577d27cac..95e3476ca9 100644 --- a/packages/core/src/lib/message/version_0.ts +++ b/packages/core/src/lib/message/version_0.ts @@ -22,7 +22,7 @@ export { proto }; export class DecodedMessage implements IDecodedMessage { constructor( - public pubSubTopic: string, + public pubsubTopic: string, protected proto: proto.WakuMessage ) {} @@ -76,7 +76,7 @@ export class Encoder implements IEncoder { constructor( public contentTopic: string, public ephemeral: boolean = false, - public pubSubTopic: PubSubTopic, + public pubsubTopic: PubSubTopic, public metaSetter?: IMetaSetter ) { if (!contentTopic || contentTopic === "") { @@ -119,17 +119,17 @@ export class Encoder implements IEncoder { * messages. */ export function createEncoder({ - pubSubTopic = DefaultPubSubTopic, + pubsubTopic = DefaultPubSubTopic, contentTopic, ephemeral, metaSetter }: EncoderOptions): Encoder { - return new Encoder(contentTopic, ephemeral, pubSubTopic, metaSetter); + return new Encoder(contentTopic, ephemeral, pubsubTopic, metaSetter); } export class Decoder implements IDecoder { constructor( - public pubSubTopic: PubSubTopic, + public pubsubTopic: PubSubTopic, public contentTopic: string ) { if (!contentTopic || contentTopic === "") { @@ -152,7 +152,7 @@ export class Decoder implements IDecoder { } async fromProtoObj( - pubSubTopic: string, + pubsubTopic: string, proto: IProtoMessage ): Promise { // https://rfc.vac.dev/spec/14/ @@ -167,7 +167,7 @@ export class Decoder implements IDecoder { return Promise.resolve(undefined); } - return new DecodedMessage(pubSubTopic, proto); + return new DecodedMessage(pubsubTopic, proto); } } diff --git a/packages/core/src/lib/store/history_rpc.ts b/packages/core/src/lib/store/history_rpc.ts index 23764ff821..2db298d90a 100644 --- a/packages/core/src/lib/store/history_rpc.ts +++ b/packages/core/src/lib/store/history_rpc.ts @@ -11,7 +11,7 @@ export enum PageDirection { export interface Params { contentTopics: string[]; - pubSubTopic: string; + pubsubTopic: string; pageDirection: PageDirection; pageSize: number; startTime?: Date; @@ -59,7 +59,7 @@ export class HistoryRpc { return new HistoryRpc({ requestId: uuid(), query: { - pubsubTopic: params.pubSubTopic, + pubsubTopic: params.pubsubTopic, contentFilters, pagingInfo, startTime, diff --git a/packages/core/src/lib/store/index.ts b/packages/core/src/lib/store/index.ts index 6d5cedc4de..9937593498 100644 --- a/packages/core/src/lib/store/index.ts +++ b/packages/core/src/lib/store/index.ts @@ -75,12 +75,12 @@ export interface QueryOptions { * The Waku Store protocol can be used to retrieved historical messages. */ class Store extends BaseProtocol implements IStore { - private readonly pubSubTopics: PubSubTopic[]; + private readonly pubsubTopics: PubSubTopic[]; private readonly NUM_PEERS_PROTOCOL = 1; constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) { super(StoreCodec, libp2p.components); - this.pubSubTopics = options?.pubSubTopics ?? [DefaultPubSubTopic]; + this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic]; } /** @@ -231,7 +231,7 @@ class Store extends BaseProtocol implements IStore { // convert array to set to remove duplicates const uniquePubSubTopicsInQuery = Array.from( - new Set(decoders.map((decoder) => decoder.pubSubTopic)) + new Set(decoders.map((decoder) => decoder.pubsubTopic)) ); // If multiple pubsub topics are provided, throw an error @@ -244,9 +244,9 @@ class Store extends BaseProtocol implements IStore { // we can be certain that there is only one pubsub topic in the query const pubSubTopicForQuery = uniquePubSubTopicsInQuery[0]; - ensurePubsubTopicIsConfigured(pubSubTopicForQuery, this.pubSubTopics); + ensurePubsubTopicIsConfigured(pubSubTopicForQuery, this.pubsubTopics); - // check that the pubSubTopic from the Cursor and Decoder match + // check that the pubsubTopic from the Cursor and Decoder match if ( options?.cursor?.pubsubTopic && options.cursor.pubsubTopic !== pubSubTopicForQuery @@ -267,7 +267,7 @@ class Store extends BaseProtocol implements IStore { }); const contentTopics = decoders - .filter((decoder) => decoder.pubSubTopic === pubSubTopicForQuery) + .filter((decoder) => decoder.pubsubTopic === pubSubTopicForQuery) .map((dec) => dec.contentTopic); if (contentTopics.length === 0) { @@ -276,7 +276,7 @@ class Store extends BaseProtocol implements IStore { const queryOpts = Object.assign( { - pubSubTopic: pubSubTopicForQuery, + pubsubTopic: pubSubTopicForQuery, pageDirection: PageDirection.BACKWARD, pageSize: DefaultPageSize }, @@ -327,7 +327,7 @@ async function* paginate( log( "Querying store peer", - `for (${queryOpts.pubSubTopic})`, + `for (${queryOpts.pubsubTopic})`, queryOpts.contentTopics ); @@ -374,7 +374,7 @@ async function* paginate( const decoder = decoders.get(contentTopic); if (decoder) { return decoder.fromProtoObj( - queryOpts.pubSubTopic, + queryOpts.pubsubTopic, toProtoMessage(protoMsg) ); } @@ -425,7 +425,7 @@ export async function createCursor(message: IDecodedMessage): Promise { return { digest, - pubsubTopic: message.pubSubTopic, + pubsubTopic: message.pubsubTopic, senderTime: messageTime, receiverTime: messageTime }; diff --git a/packages/core/src/lib/wait_for_remote_peer.ts b/packages/core/src/lib/wait_for_remote_peer.ts index 84901e801f..8c3631a486 100644 --- a/packages/core/src/lib/wait_for_remote_peer.ts +++ b/packages/core/src/lib/wait_for_remote_peer.ts @@ -97,13 +97,13 @@ async function waitForConnectedPeer(protocol: IBaseProtocol): Promise { /** * Wait for at least one peer with the given protocol to be connected and in the gossipsub - * mesh for all pubSubTopics. + * mesh for all pubsubTopics. */ async function waitForGossipSubPeerInMesh(waku: IRelay): Promise { let peers = waku.getMeshPeers(); - const pubSubTopics = waku.pubSubTopics; + const pubsubTopics = waku.pubsubTopics; - for (const topic of pubSubTopics) { + for (const topic of pubsubTopics) { while (peers.length == 0) { await pEvent(waku.gossipSub, "gossipsub:heartbeat"); peers = waku.getMeshPeers(topic); diff --git a/packages/core/src/lib/waku.ts b/packages/core/src/lib/waku.ts index 0da4102ab1..5dd390a9d3 100644 --- a/packages/core/src/lib/waku.ts +++ b/packages/core/src/lib/waku.ts @@ -53,7 +53,7 @@ export class WakuNode implements Waku { constructor( options: WakuOptions, - public readonly pubSubTopics: PubSubTopic[], + public readonly pubsubTopics: PubSubTopic[], libp2p: Libp2p, store?: (libp2p: Libp2p) => IStore, lightPush?: (libp2p: Libp2p) => ILightPush, @@ -88,7 +88,7 @@ export class WakuNode implements Waku { peerId, libp2p, { pingKeepAlive, relayKeepAlive }, - pubSubTopics, + pubsubTopics, this.relay ); diff --git a/packages/interfaces/src/filter.ts b/packages/interfaces/src/filter.ts index 5d9d04566b..34dad0f87c 100644 --- a/packages/interfaces/src/filter.ts +++ b/packages/interfaces/src/filter.ts @@ -25,7 +25,7 @@ export interface IFilterSubscription { export type IFilter = IReceiver & IBaseProtocol & { createSubscription( - pubSubTopic?: string, + pubsubTopic?: string, peerId?: PeerId ): Promise; }; diff --git a/packages/interfaces/src/message.ts b/packages/interfaces/src/message.ts index c9383ffb2b..d18c4e5f20 100644 --- a/packages/interfaces/src/message.ts +++ b/packages/interfaces/src/message.ts @@ -38,7 +38,7 @@ export interface IMetaSetter { } export interface EncoderOptions { - pubSubTopic?: PubSubTopic; + pubsubTopic?: PubSubTopic; /** The content topic to set on outgoing messages. */ contentTopic: string; /** @@ -55,7 +55,7 @@ export interface EncoderOptions { } export interface IEncoder { - pubSubTopic: PubSubTopic; + pubsubTopic: PubSubTopic; contentTopic: string; ephemeral: boolean; toWire: (message: IMessage) => Promise; @@ -65,7 +65,7 @@ export interface IEncoder { export interface IDecodedMessage { payload: Uint8Array; contentTopic: string; - pubSubTopic: PubSubTopic; + pubsubTopic: PubSubTopic; timestamp: Date | undefined; rateLimitProof: IRateLimitProof | undefined; ephemeral: boolean | undefined; @@ -73,11 +73,11 @@ export interface IDecodedMessage { } export interface IDecoder { - pubSubTopic: PubSubTopic; + pubsubTopic: PubSubTopic; contentTopic: string; fromWireToProtoObj: (bytes: Uint8Array) => Promise; fromProtoObj: ( - pubSubTopic: string, + pubsubTopic: string, proto: IProtoMessage ) => Promise; } diff --git a/packages/interfaces/src/protocols.ts b/packages/interfaces/src/protocols.ts index 059672f7d8..923ddfc4e5 100644 --- a/packages/interfaces/src/protocols.ts +++ b/packages/interfaces/src/protocols.ts @@ -39,7 +39,7 @@ export type ProtocolCreateOptions = { * See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details. * */ - pubSubTopics?: PubSubTopic[]; + pubsubTopics?: PubSubTopic[]; /** * You can pass options to the `Libp2p` instance used by {@link @waku/core!WakuNode} using the `libp2p` property. * This property is the same type as the one passed to [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create) diff --git a/packages/interfaces/src/relay.ts b/packages/interfaces/src/relay.ts index f98f219ba4..856f3d615c 100644 --- a/packages/interfaces/src/relay.ts +++ b/packages/interfaces/src/relay.ts @@ -13,7 +13,7 @@ import type { ISender } from "./sender.js"; * @property getMeshPeers - Function to retrieve the mesh peers for a given topic or all topics if none is specified. Returns an array of peer IDs as strings. */ export interface IRelayAPI { - readonly pubSubTopics: Set; + readonly pubsubTopics: Set; readonly gossipSub: GossipSub; start: () => Promise; getMeshPeers: (topic?: TopicStr) => PeerIdStr[]; diff --git a/packages/message-encryption/src/decoded_message.ts b/packages/message-encryption/src/decoded_message.ts index 28412b46d0..05ba932a87 100644 --- a/packages/message-encryption/src/decoded_message.ts +++ b/packages/message-encryption/src/decoded_message.ts @@ -11,13 +11,13 @@ export class DecodedMessage private readonly _decodedPayload: Uint8Array; constructor( - pubSubTopic: string, + pubsubTopic: string, proto: proto.WakuMessage, decodedPayload: Uint8Array, public signature?: Uint8Array, public signaturePublicKey?: Uint8Array ) { - super(pubSubTopic, proto); + super(pubsubTopic, proto); this._decodedPayload = decodedPayload; } diff --git a/packages/message-encryption/src/ecies.spec.ts b/packages/message-encryption/src/ecies.spec.ts index 14325b21c8..f6948c56c4 100644 --- a/packages/message-encryption/src/ecies.spec.ts +++ b/packages/message-encryption/src/ecies.spec.ts @@ -13,7 +13,7 @@ describe("Ecies Encryption", function () { fc.string({ minLength: 1 }), fc.uint8Array({ minLength: 1 }), fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }), - async (pubSubTopic, contentTopic, payload, privateKey) => { + async (pubsubTopic, contentTopic, payload, privateKey) => { const publicKey = getPublicKey(privateKey); const encoder = createEncoder({ @@ -25,11 +25,11 @@ describe("Ecies Encryption", function () { const decoder = createDecoder(contentTopic, privateKey); const protoResult = await decoder.fromWireToProtoObj(bytes!); if (!protoResult) throw "Failed to proto decode"; - const result = await decoder.fromProtoObj(pubSubTopic, protoResult); + const result = await decoder.fromProtoObj(pubsubTopic, protoResult); if (!result) throw "Failed to decode"; expect(result.contentTopic).to.equal(contentTopic); - expect(result.pubSubTopic).to.equal(pubSubTopic); + expect(result.pubsubTopic).to.equal(pubsubTopic); expect(result.version).to.equal(1); expect(result?.payload).to.deep.equal(payload); expect(result.signature).to.be.undefined; @@ -50,7 +50,7 @@ describe("Ecies Encryption", function () { fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }), fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }), async ( - pubSubTopic, + pubsubTopic, contentTopic, payload, alicePrivateKey, @@ -69,11 +69,11 @@ describe("Ecies Encryption", function () { const decoder = createDecoder(contentTopic, bobPrivateKey); const protoResult = await decoder.fromWireToProtoObj(bytes!); if (!protoResult) throw "Failed to proto decode"; - const result = await decoder.fromProtoObj(pubSubTopic, protoResult); + const result = await decoder.fromProtoObj(pubsubTopic, protoResult); if (!result) throw "Failed to decode"; expect(result.contentTopic).to.equal(contentTopic); - expect(result.pubSubTopic).to.equal(pubSubTopic); + expect(result.pubsubTopic).to.equal(pubsubTopic); expect(result.version).to.equal(1); expect(result?.payload).to.deep.equal(payload); expect(result.signature).to.not.be.undefined; @@ -90,7 +90,7 @@ describe("Ecies Encryption", function () { fc.string({ minLength: 1 }), fc.uint8Array({ minLength: 1 }), fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }), - async (pubSubTopic, contentTopic, payload, privateKey) => { + async (pubsubTopic, contentTopic, payload, privateKey) => { const publicKey = getPublicKey(privateKey); const metaSetter = ( msg: IProtoMessage & { meta: undefined } @@ -111,7 +111,7 @@ describe("Ecies Encryption", function () { const decoder = createDecoder(contentTopic, privateKey); const protoResult = await decoder.fromWireToProtoObj(bytes!); if (!protoResult) throw "Failed to proto decode"; - const result = await decoder.fromProtoObj(pubSubTopic, protoResult); + const result = await decoder.fromProtoObj(pubsubTopic, protoResult); if (!result) throw "Failed to decode"; const expectedMeta = metaSetter({ diff --git a/packages/message-encryption/src/ecies.ts b/packages/message-encryption/src/ecies.ts index 4037cc3740..1d26c77c8b 100644 --- a/packages/message-encryption/src/ecies.ts +++ b/packages/message-encryption/src/ecies.ts @@ -33,7 +33,7 @@ const log = debug("waku:message-encryption:ecies"); class Encoder implements IEncoder { constructor( - public pubSubTopic: PubSubTopic, + public pubsubTopic: PubSubTopic, public contentTopic: string, private publicKey: Uint8Array, private sigPrivKey?: Uint8Array, @@ -97,7 +97,7 @@ export interface EncoderOptions extends BaseEncoderOptions { * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/). */ export function createEncoder({ - pubSubTopic = DefaultPubSubTopic, + pubsubTopic = DefaultPubSubTopic, contentTopic, publicKey, sigPrivKey, @@ -105,7 +105,7 @@ export function createEncoder({ metaSetter }: EncoderOptions): Encoder { return new Encoder( - pubSubTopic, + pubsubTopic, contentTopic, publicKey, sigPrivKey, @@ -116,15 +116,15 @@ export function createEncoder({ class Decoder extends DecoderV0 implements IDecoder { constructor( - pubSubTopic: PubSubTopic, + pubsubTopic: PubSubTopic, contentTopic: string, private privateKey: Uint8Array ) { - super(pubSubTopic, contentTopic); + super(pubsubTopic, contentTopic); } async fromProtoObj( - pubSubTopic: string, + pubsubTopic: string, protoMessage: IProtoMessage ): Promise { const cipherPayload = protoMessage.payload; @@ -165,7 +165,7 @@ class Decoder extends DecoderV0 implements IDecoder { log("Message decrypted", protoMessage); return new DecodedMessage( - pubSubTopic, + pubsubTopic, protoMessage, res.payload, res.sig?.signature, @@ -189,7 +189,7 @@ class Decoder extends DecoderV0 implements IDecoder { export function createDecoder( contentTopic: string, privateKey: Uint8Array, - pubSubTopic: PubSubTopic = DefaultPubSubTopic + pubsubTopic: PubSubTopic = DefaultPubSubTopic ): Decoder { - return new Decoder(pubSubTopic, contentTopic, privateKey); + return new Decoder(pubsubTopic, contentTopic, privateKey); } diff --git a/packages/message-encryption/src/symmetric.spec.ts b/packages/message-encryption/src/symmetric.spec.ts index 9223c6a01d..0a6370c0f6 100644 --- a/packages/message-encryption/src/symmetric.spec.ts +++ b/packages/message-encryption/src/symmetric.spec.ts @@ -13,7 +13,7 @@ describe("Symmetric Encryption", function () { fc.string({ minLength: 1 }), fc.uint8Array({ minLength: 1 }), fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }), - async (pubSubTopic, contentTopic, payload, symKey) => { + async (pubsubTopic, contentTopic, payload, symKey) => { const encoder = createEncoder({ contentTopic, symKey @@ -23,11 +23,11 @@ describe("Symmetric Encryption", function () { const decoder = createDecoder(contentTopic, symKey); const protoResult = await decoder.fromWireToProtoObj(bytes!); if (!protoResult) throw "Failed to proto decode"; - const result = await decoder.fromProtoObj(pubSubTopic, protoResult); + const result = await decoder.fromProtoObj(pubsubTopic, protoResult); if (!result) throw "Failed to decode"; expect(result.contentTopic).to.equal(contentTopic); - expect(result.pubSubTopic).to.equal(pubSubTopic); + expect(result.pubsubTopic).to.equal(pubsubTopic); expect(result.version).to.equal(1); expect(result?.payload).to.deep.equal(payload); expect(result.signature).to.be.undefined; @@ -45,7 +45,7 @@ describe("Symmetric Encryption", function () { fc.uint8Array({ minLength: 1 }), fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }), fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }), - async (pubSubTopic, contentTopic, payload, sigPrivKey, symKey) => { + async (pubsubTopic, contentTopic, payload, sigPrivKey, symKey) => { const sigPubKey = getPublicKey(sigPrivKey); const encoder = createEncoder({ @@ -58,11 +58,11 @@ describe("Symmetric Encryption", function () { const decoder = createDecoder(contentTopic, symKey); const protoResult = await decoder.fromWireToProtoObj(bytes!); if (!protoResult) throw "Failed to proto decode"; - const result = await decoder.fromProtoObj(pubSubTopic, protoResult); + const result = await decoder.fromProtoObj(pubsubTopic, protoResult); if (!result) throw "Failed to decode"; expect(result.contentTopic).to.equal(contentTopic); - expect(result.pubSubTopic).to.equal(pubSubTopic); + expect(result.pubsubTopic).to.equal(pubsubTopic); expect(result.version).to.equal(1); expect(result?.payload).to.deep.equal(payload); expect(result.signature).to.not.be.undefined; @@ -79,7 +79,7 @@ describe("Symmetric Encryption", function () { fc.string({ minLength: 1 }), fc.uint8Array({ minLength: 1 }), fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }), - async (pubSubTopic, contentTopic, payload, symKey) => { + async (pubsubTopic, contentTopic, payload, symKey) => { const metaSetter = ( msg: IProtoMessage & { meta: undefined } ): Uint8Array => { @@ -99,7 +99,7 @@ describe("Symmetric Encryption", function () { const decoder = createDecoder(contentTopic, symKey); const protoResult = await decoder.fromWireToProtoObj(bytes!); if (!protoResult) throw "Failed to proto decode"; - const result = await decoder.fromProtoObj(pubSubTopic, protoResult); + const result = await decoder.fromProtoObj(pubsubTopic, protoResult); if (!result) throw "Failed to decode"; const expectedMeta = metaSetter({ diff --git a/packages/message-encryption/src/symmetric.ts b/packages/message-encryption/src/symmetric.ts index eb1c2511d2..cdcd44a405 100644 --- a/packages/message-encryption/src/symmetric.ts +++ b/packages/message-encryption/src/symmetric.ts @@ -29,7 +29,7 @@ const log = debug("waku:message-encryption:symmetric"); class Encoder implements IEncoder { constructor( - public pubSubTopic: PubSubTopic, + public pubsubTopic: PubSubTopic, public contentTopic: string, private symKey: Uint8Array, private sigPrivKey?: Uint8Array, @@ -93,7 +93,7 @@ export interface EncoderOptions extends BaseEncoderOptions { * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/). */ export function createEncoder({ - pubSubTopic = DefaultPubSubTopic, + pubsubTopic = DefaultPubSubTopic, contentTopic, symKey, sigPrivKey, @@ -101,7 +101,7 @@ export function createEncoder({ metaSetter }: EncoderOptions): Encoder { return new Encoder( - pubSubTopic, + pubsubTopic, contentTopic, symKey, sigPrivKey, @@ -112,15 +112,15 @@ export function createEncoder({ class Decoder extends DecoderV0 implements IDecoder { constructor( - pubSubTopic: PubSubTopic, + pubsubTopic: PubSubTopic, contentTopic: string, private symKey: Uint8Array ) { - super(pubSubTopic, contentTopic); + super(pubsubTopic, contentTopic); } async fromProtoObj( - pubSubTopic: string, + pubsubTopic: string, protoMessage: IProtoMessage ): Promise { const cipherPayload = protoMessage.payload; @@ -161,7 +161,7 @@ class Decoder extends DecoderV0 implements IDecoder { log("Message decrypted", protoMessage); return new DecodedMessage( - pubSubTopic, + pubsubTopic, protoMessage, res.payload, res.sig?.signature, @@ -185,7 +185,7 @@ class Decoder extends DecoderV0 implements IDecoder { export function createDecoder( contentTopic: string, symKey: Uint8Array, - pubSubTopic: PubSubTopic = DefaultPubSubTopic + pubsubTopic: PubSubTopic = DefaultPubSubTopic ): Decoder { - return new Decoder(pubSubTopic, contentTopic, symKey); + return new Decoder(pubsubTopic, contentTopic, symKey); } diff --git a/packages/message-hash/src/index.spec.ts b/packages/message-hash/src/index.spec.ts index 4978754b27..11b32dad78 100644 --- a/packages/message-hash/src/index.spec.ts +++ b/packages/message-hash/src/index.spec.ts @@ -10,7 +10,7 @@ describe("RFC Test Vectors", () => { const expectedHash = "4fdde1099c9f77f6dae8147b6b3179aba1fc8e14a7bf35203fc253ee479f135f"; - const pubSubTopic = "/waku/2/default-waku/proto"; + const pubsubTopic = "/waku/2/default-waku/proto"; const message: IProtoMessage = { payload: hexToBytes("0x010203045445535405060708"), contentTopic: "/waku/2/default-content/proto", @@ -21,7 +21,7 @@ describe("RFC Test Vectors", () => { version: undefined }; - const hash = messageHash(pubSubTopic, message); + const hash = messageHash(pubsubTopic, message); expect(bytesToHex(hash)).to.equal(expectedHash); }); @@ -30,7 +30,7 @@ describe("RFC Test Vectors", () => { const expectedHash = "87619d05e563521d9126749b45bd4cc2430df0607e77e23572d874ed9c1aaa62"; - const pubSubTopic = "/waku/2/default-waku/proto"; + const pubsubTopic = "/waku/2/default-waku/proto"; const message: IProtoMessage = { payload: hexToBytes("0x010203045445535405060708"), contentTopic: "/waku/2/default-content/proto", @@ -41,7 +41,7 @@ describe("RFC Test Vectors", () => { version: undefined }; - const hash = messageHash(pubSubTopic, message); + const hash = messageHash(pubsubTopic, message); expect(bytesToHex(hash)).to.equal(expectedHash); }); @@ -50,7 +50,7 @@ describe("RFC Test Vectors", () => { const expectedHash = "e1a9596237dbe2cc8aaf4b838c46a7052df6bc0d42ba214b998a8bfdbe8487d6"; - const pubSubTopic = "/waku/2/default-waku/proto"; + const pubsubTopic = "/waku/2/default-waku/proto"; const message: IProtoMessage = { payload: new Uint8Array(), contentTopic: "/waku/2/default-content/proto", @@ -61,7 +61,7 @@ describe("RFC Test Vectors", () => { version: undefined }; - const hash = messageHash(pubSubTopic, message); + const hash = messageHash(pubsubTopic, message); expect(bytesToHex(hash)).to.equal(expectedHash); }); diff --git a/packages/relay/src/index.ts b/packages/relay/src/index.ts index bf258c0f6f..28270ba03c 100644 --- a/packages/relay/src/index.ts +++ b/packages/relay/src/index.ts @@ -48,7 +48,7 @@ export type ContentTopic = string; * Throws if libp2p.pubsub does not support Waku Relay */ class Relay implements IRelay { - public readonly pubSubTopics: Set; + public readonly pubsubTopics: Set; private defaultDecoder: IDecoder; public static multicodec: string = RelayCodecs[0]; @@ -68,7 +68,7 @@ class Relay implements IRelay { } this.gossipSub = libp2p.services.pubsub as GossipSub; - this.pubSubTopics = new Set(options?.pubSubTopics ?? [DefaultPubSubTopic]); + this.pubsubTopics = new Set(options?.pubsubTopics ?? [DefaultPubSubTopic]); if (this.gossipSub.isStarted()) { this.subscribeToAllTopics(); @@ -103,8 +103,8 @@ class Relay implements IRelay { public async send(encoder: IEncoder, message: IMessage): Promise { const recipients: PeerId[] = []; - const { pubSubTopic } = encoder; - if (!this.pubSubTopics.has(pubSubTopic)) { + const { pubsubTopic } = encoder; + if (!this.pubsubTopics.has(pubsubTopic)) { log("Failed to send waku relay: topic not configured"); return { recipients, @@ -129,7 +129,7 @@ class Relay implements IRelay { }; } - return this.gossipSub.publish(pubSubTopic, msg); + return this.gossipSub.publish(pubsubTopic, msg); } public subscribe( @@ -139,15 +139,15 @@ class Relay implements IRelay { const observers: Array<[PubSubTopic, Observer]> = []; for (const decoder of Array.isArray(decoders) ? decoders : [decoders]) { - const { pubSubTopic } = decoder; + const { pubsubTopic } = decoder; const ctObs: Map>> = this.observers.get( - pubSubTopic + pubsubTopic ) ?? new Map(); - const observer = { pubSubTopic, decoder, callback }; + const observer = { pubsubTopic, decoder, callback }; pushOrInitMapSet(ctObs, decoder.contentTopic, observer); - this.observers.set(pubSubTopic, ctObs); - observers.push([pubSubTopic, observer]); + this.observers.set(pubsubTopic, ctObs); + observers.push([pubsubTopic, observer]); } return () => { @@ -158,8 +158,8 @@ class Relay implements IRelay { private removeObservers( observers: Array<[PubSubTopic, Observer]> ): void { - for (const [pubSubTopic, observer] of observers) { - const ctObs = this.observers.get(pubSubTopic); + for (const [pubsubTopic, observer] of observers) { + const ctObs = this.observers.get(pubsubTopic); if (!ctObs) continue; const contentTopic = observer.decoder.contentTopic; @@ -168,7 +168,7 @@ class Relay implements IRelay { _obs.delete(observer); ctObs.set(contentTopic, _obs); - this.observers.set(pubSubTopic, ctObs); + this.observers.set(pubsubTopic, ctObs); } } @@ -180,8 +180,8 @@ class Relay implements IRelay { public getActiveSubscriptions(): ActiveSubscriptions { const map = new Map(); - for (const pubSubTopic of this.pubSubTopics) { - map.set(pubSubTopic, Array.from(this.observers.keys())); + for (const pubsubTopic of this.pubsubTopics) { + map.set(pubsubTopic, Array.from(this.observers.keys())); } return map; } @@ -191,13 +191,13 @@ class Relay implements IRelay { } private subscribeToAllTopics(): void { - for (const pubSubTopic of this.pubSubTopics) { - this.gossipSubSubscribe(pubSubTopic); + for (const pubsubTopic of this.pubsubTopics) { + this.gossipSubSubscribe(pubsubTopic); } } private async processIncomingMessage( - pubSubTopic: string, + pubsubTopic: string, bytes: Uint8Array ): Promise { const topicOnlyMsg = await this.defaultDecoder.fromWireToProtoObj(bytes); @@ -206,8 +206,8 @@ class Relay implements IRelay { return; } - // Retrieve the map of content topics for the given pubSubTopic - const contentTopicMap = this.observers.get(pubSubTopic); + // Retrieve the map of content topics for the given pubsubTopic + const contentTopicMap = this.observers.get(pubsubTopic); if (!contentTopicMap) { return; } @@ -231,7 +231,7 @@ class Relay implements IRelay { ); return; } - const msg = await decoder.fromProtoObj(pubSubTopic, protoMsg); + const msg = await decoder.fromProtoObj(pubsubTopic, protoMsg); if (msg) { await callback(msg); } else { @@ -250,12 +250,12 @@ class Relay implements IRelay { * * @override */ - private gossipSubSubscribe(pubSubTopic: string): void { + private gossipSubSubscribe(pubsubTopic: string): void { this.gossipSub.addEventListener( "gossipsub:message", (event: CustomEvent) => { - if (event.detail.msg.topic !== pubSubTopic) return; - log(`Message received on ${pubSubTopic}`); + if (event.detail.msg.topic !== pubsubTopic) return; + log(`Message received on ${pubsubTopic}`); this.processIncomingMessage( event.detail.msg.topic, @@ -264,8 +264,8 @@ class Relay implements IRelay { } ); - this.gossipSub.topicValidators.set(pubSubTopic, messageValidator); - this.gossipSub.subscribe(pubSubTopic); + this.gossipSub.topicValidators.set(pubsubTopic, messageValidator); + this.gossipSub.subscribe(pubsubTopic); } private isRelayPubSub(pubsub: PubSub | undefined): boolean { diff --git a/packages/relay/src/message_validator.spec.ts b/packages/relay/src/message_validator.spec.ts index 23d7b00462..a5f9585f89 100644 --- a/packages/relay/src/message_validator.spec.ts +++ b/packages/relay/src/message_validator.spec.ts @@ -14,7 +14,7 @@ describe("Message Validator", () => { fc.uint8Array({ minLength: 1 }), fc.string({ minLength: 1 }), fc.string({ minLength: 1 }), - async (payload, pubSubTopic, contentTopic) => { + async (payload, pubsubTopic, contentTopic) => { const peerId = await createSecp256k1PeerId(); const encoder = createEncoder({ contentTopic }); @@ -22,7 +22,7 @@ describe("Message Validator", () => { const message: UnsignedMessage = { type: "unsigned", - topic: pubSubTopic, + topic: pubsubTopic, data: bytes }; @@ -39,12 +39,12 @@ describe("Message Validator", () => { fc.asyncProperty( fc.uint8Array(), fc.string(), - async (data, pubSubTopic) => { + async (data, pubsubTopic) => { const peerId = await createSecp256k1PeerId(); const message: UnsignedMessage = { type: "unsigned", - topic: pubSubTopic, + topic: pubsubTopic, data }; diff --git a/packages/relay/src/topic_only_message.ts b/packages/relay/src/topic_only_message.ts index 845280b860..fca98b045b 100644 --- a/packages/relay/src/topic_only_message.ts +++ b/packages/relay/src/topic_only_message.ts @@ -17,7 +17,7 @@ export class TopicOnlyMessage implements IDecodedMessage { public ephemeral: undefined; constructor( - public pubSubTopic: string, + public pubsubTopic: string, private proto: ProtoTopicOnlyMessage ) {} @@ -27,7 +27,7 @@ export class TopicOnlyMessage implements IDecodedMessage { } export class TopicOnlyDecoder implements IDecoder { - pubSubTopic = DefaultPubSubTopic; + pubsubTopic = DefaultPubSubTopic; public contentTopic = ""; fromWireToProtoObj(bytes: Uint8Array): Promise { @@ -45,9 +45,9 @@ export class TopicOnlyDecoder implements IDecoder { } async fromProtoObj( - pubSubTopic: string, + pubsubTopic: string, proto: IProtoMessage ): Promise { - return new TopicOnlyMessage(pubSubTopic, proto); + return new TopicOnlyMessage(pubsubTopic, proto); } } diff --git a/packages/sdk/src/create.ts b/packages/sdk/src/create.ts index 53a8fa5a02..7732c51bec 100644 --- a/packages/sdk/src/create.ts +++ b/packages/sdk/src/create.ts @@ -46,8 +46,8 @@ export async function createLightNode( ): Promise { options = options ?? {}; - if (!options.pubSubTopics) { - options.pubSubTopics = [DefaultPubSubTopic]; + if (!options.pubsubTopics) { + options.pubsubTopics = [DefaultPubSubTopic]; } const libp2pOptions = options?.libp2p ?? {}; @@ -69,7 +69,7 @@ export async function createLightNode( return new WakuNode( options ?? {}, - options.pubSubTopics, + options.pubsubTopics, libp2p, store, lightPush, @@ -86,8 +86,8 @@ export async function createRelayNode( ): Promise { options = options ?? {}; - if (!options.pubSubTopics) { - options.pubSubTopics = [DefaultPubSubTopic]; + if (!options.pubsubTopics) { + options.pubsubTopics = [DefaultPubSubTopic]; } const libp2pOptions = options?.libp2p ?? {}; @@ -107,7 +107,7 @@ export async function createRelayNode( return new WakuNode( options, - options.pubSubTopics, + options.pubsubTopics, libp2p, undefined, undefined, @@ -134,8 +134,8 @@ export async function createFullNode( ): Promise { options = options ?? {}; - if (!options.pubSubTopics) { - options.pubSubTopics = [DefaultPubSubTopic]; + if (!options.pubsubTopics) { + options.pubsubTopics = [DefaultPubSubTopic]; } const libp2pOptions = options?.libp2p ?? {}; @@ -158,7 +158,7 @@ export async function createFullNode( return new WakuNode( options ?? {}, - options.pubSubTopics, + options.pubsubTopics, libp2p, store, lightPush, diff --git a/packages/tests/src/message_collector.ts b/packages/tests/src/message_collector.ts index 7aa7a54615..ac7e06ba23 100644 --- a/packages/tests/src/message_collector.ts +++ b/packages/tests/src/message_collector.ts @@ -64,20 +64,20 @@ export class MessageCollector { async waitForMessages( numMessages: number, options?: { - pubSubTopic?: string; + pubsubTopic?: string; timeoutDuration?: number; exact?: boolean; } ): Promise { const startTime = Date.now(); - const pubSubTopic = options?.pubSubTopic || DefaultPubSubTopic; + const pubsubTopic = options?.pubsubTopic || DefaultPubSubTopic; const timeoutDuration = options?.timeoutDuration || 400; const exact = options?.exact || false; while (this.count < numMessages) { if (this.nwaku) { try { - this.list = await this.nwaku.messages(pubSubTopic); + this.list = await this.nwaku.messages(pubsubTopic); } catch (error) { log(`Can't retrieve messages because of ${error}`); await delay(10); @@ -191,11 +191,11 @@ export class MessageCollector { } } else { // js-waku message specific assertions - expect(message.pubSubTopic).to.eq( + expect(message.pubsubTopic).to.eq( options.expectedPubSubTopic || DefaultPubSubTopic, `Message pub/sub topic mismatch. Expected: ${ options.expectedPubSubTopic || DefaultPubSubTopic - }. Got: ${message.pubSubTopic}` + }. Got: ${message.pubsubTopic}` ); expect(bytesToUtf8(message.payload)).to.eq( diff --git a/packages/tests/src/node/node.ts b/packages/tests/src/node/node.ts index d9603df053..14dd6fdc0d 100644 --- a/packages/tests/src/node/node.ts +++ b/packages/tests/src/node/node.ts @@ -216,7 +216,7 @@ export class NimGoNode { async sendMessage( message: MessageRpcQuery, - pubSubTopic: string = DefaultPubSubTopic + pubsubTopic: string = DefaultPubSubTopic ): Promise { this.checkProcess(); @@ -225,7 +225,7 @@ export class NimGoNode { } return this.rpcCall("post_waku_v2_relay_v1_message", [ - pubSubTopic, + pubsubTopic, message ]); } @@ -264,7 +264,7 @@ export class NimGoNode { async postAsymmetricMessage( message: MessageRpcQuery, publicKey: Uint8Array, - pubSubTopic?: string + pubsubTopic?: string ): Promise { this.checkProcess(); @@ -273,7 +273,7 @@ export class NimGoNode { } return this.rpcCall("post_waku_v2_private_v1_asymmetric_message", [ - pubSubTopic ? pubSubTopic : DefaultPubSubTopic, + pubsubTopic ? pubsubTopic : DefaultPubSubTopic, message, "0x" + bytesToHex(publicKey) ]); @@ -281,14 +281,14 @@ export class NimGoNode { async getAsymmetricMessages( privateKey: Uint8Array, - pubSubTopic?: string + pubsubTopic?: string ): Promise { this.checkProcess(); return await this.rpcCall( "get_waku_v2_private_v1_asymmetric_messages", [ - pubSubTopic ? pubSubTopic : DefaultPubSubTopic, + pubsubTopic ? pubsubTopic : DefaultPubSubTopic, "0x" + bytesToHex(privateKey) ] ); @@ -306,7 +306,7 @@ export class NimGoNode { async postSymmetricMessage( message: MessageRpcQuery, symKey: Uint8Array, - pubSubTopic?: string + pubsubTopic?: string ): Promise { this.checkProcess(); @@ -315,7 +315,7 @@ export class NimGoNode { } return this.rpcCall("post_waku_v2_private_v1_symmetric_message", [ - pubSubTopic ? pubSubTopic : DefaultPubSubTopic, + pubsubTopic ? pubsubTopic : DefaultPubSubTopic, message, "0x" + bytesToHex(symKey) ]); @@ -323,14 +323,14 @@ export class NimGoNode { async getSymmetricMessages( symKey: Uint8Array, - pubSubTopic?: string + pubsubTopic?: string ): Promise { this.checkProcess(); return await this.rpcCall( "get_waku_v2_private_v1_symmetric_messages", [ - pubSubTopic ? pubSubTopic : DefaultPubSubTopic, + pubsubTopic ? pubsubTopic : DefaultPubSubTopic, "0x" + bytesToHex(symKey) ] ); diff --git a/packages/tests/tests/filter/multiple_pubsub.node.spec.ts b/packages/tests/tests/filter/multiple_pubsub.node.spec.ts index dd0ed193fd..efd787dc99 100644 --- a/packages/tests/tests/filter/multiple_pubsub.node.spec.ts +++ b/packages/tests/tests/filter/multiple_pubsub.node.spec.ts @@ -34,7 +34,7 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () { const customPubSubTopic = "/waku/2/custom-dapp/proto"; const customContentTopic = "/test/2/waku-filter"; const newEncoder = createEncoder({ - pubSubTopic: customPubSubTopic, + pubsubTopic: customPubSubTopic, contentTopic: customContentTopic }); const newDecoder = createDecoder(customContentTopic, customPubSubTopic); @@ -124,10 +124,10 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () { // While loop is done because of https://github.com/waku-org/js-waku/issues/1606 while ( !(await messageCollector.waitForMessages(1, { - pubSubTopic: customPubSubTopic + pubsubTopic: customPubSubTopic })) || !(await messageCollector2.waitForMessages(1, { - pubSubTopic: DefaultPubSubTopic + pubsubTopic: DefaultPubSubTopic })) ) { await waku.lightPush.send(newEncoder, { payload: utf8ToBytes("M1") }); diff --git a/packages/tests/tests/filter/utils.ts b/packages/tests/tests/filter/utils.ts index 0eee4b12a1..cf8881c31e 100644 --- a/packages/tests/tests/filter/utils.ts +++ b/packages/tests/tests/filter/utils.ts @@ -65,7 +65,7 @@ export async function validatePingError( export async function runNodes( context: Context, - pubSubTopics: string[] + pubsubTopics: string[] ): Promise<[NimGoNode, LightNode]> { const nwaku = new NimGoNode(makeLogFileName(context)); @@ -74,7 +74,7 @@ export async function runNodes( filter: true, lightpush: true, relay: true, - topic: pubSubTopics + topic: pubsubTopics }, { retries: 3 } ); @@ -82,7 +82,7 @@ export async function runNodes( let waku: LightNode | undefined; try { waku = await createLightNode({ - pubSubTopics: pubSubTopics, + pubsubTopics: pubsubTopics, staticNoiseKey: NOISE_KEY_1, libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } } }); @@ -94,7 +94,7 @@ export async function runNodes( if (waku) { await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]); - await nwaku.ensureSubscriptions(pubSubTopics); + await nwaku.ensureSubscriptions(pubsubTopics); return [nwaku, waku]; } else { throw new Error("Failed to initialize waku"); diff --git a/packages/tests/tests/light-push/multiple_pubsub.node.spec.ts b/packages/tests/tests/light-push/multiple_pubsub.node.spec.ts index 05f8f5068a..9e64dc4815 100644 --- a/packages/tests/tests/light-push/multiple_pubsub.node.spec.ts +++ b/packages/tests/tests/light-push/multiple_pubsub.node.spec.ts @@ -32,7 +32,7 @@ describe("Waku Light Push : Multiple PubSubtopics", function () { const customContentTopic = "/test/2/waku-light-push/utf8"; const customEncoder = createEncoder({ contentTopic: customContentTopic, - pubSubTopic: customPubSubTopic + pubsubTopic: customPubSubTopic }); let nimPeerId: PeerId; @@ -51,7 +51,7 @@ describe("Waku Light Push : Multiple PubSubtopics", function () { await tearDownNodes([nwaku, nwaku2], waku); }); - it("Push message on custom pubSubTopic", async function () { + it("Push message on custom pubsubTopic", async function () { const pushResponse = await waku.lightPush.send(customEncoder, { payload: utf8ToBytes(messageText) }); @@ -60,7 +60,7 @@ describe("Waku Light Push : Multiple PubSubtopics", function () { expect( await messageCollector.waitForMessages(1, { - pubSubTopic: customPubSubTopic + pubsubTopic: customPubSubTopic }) ).to.eq(true); messageCollector.verifyReceivedMessage(0, { @@ -83,13 +83,13 @@ describe("Waku Light Push : Multiple PubSubtopics", function () { expect( await messageCollector.waitForMessages(1, { - pubSubTopic: customPubSubTopic + pubsubTopic: customPubSubTopic }) ).to.eq(true); expect( await messageCollector2.waitForMessages(1, { - pubSubTopic: DefaultPubSubTopic + pubsubTopic: DefaultPubSubTopic }) ).to.eq(true); @@ -126,10 +126,10 @@ describe("Waku Light Push : Multiple PubSubtopics", function () { // While loop is done because of https://github.com/waku-org/js-waku/issues/1606 while ( !(await messageCollector.waitForMessages(1, { - pubSubTopic: customPubSubTopic + pubsubTopic: customPubSubTopic })) || !(await messageCollector2.waitForMessages(1, { - pubSubTopic: DefaultPubSubTopic + pubsubTopic: DefaultPubSubTopic })) || pushResponse1!.recipients[0].toString() === pushResponse2!.recipients[0].toString() diff --git a/packages/tests/tests/light-push/utils.ts b/packages/tests/tests/light-push/utils.ts index 5632f265ff..418948d6ff 100644 --- a/packages/tests/tests/light-push/utils.ts +++ b/packages/tests/tests/light-push/utils.ts @@ -14,18 +14,18 @@ export const messagePayload = { payload: utf8ToBytes(messageText) }; export async function runNodes( context: Mocha.Context, - pubSubTopics: string[] + pubsubTopics: string[] ): Promise<[NimGoNode, LightNode]> { const nwaku = new NimGoNode(makeLogFileName(context)); await nwaku.start( - { lightpush: true, relay: true, topic: pubSubTopics }, + { lightpush: true, relay: true, topic: pubsubTopics }, { retries: 3 } ); let waku: LightNode | undefined; try { waku = await createLightNode({ - pubSubTopics: pubSubTopics, + pubsubTopics: pubsubTopics, staticNoiseKey: NOISE_KEY_1 }); await waku.start(); @@ -36,7 +36,7 @@ export async function runNodes( if (waku) { await waku.dial(await nwaku.getMultiaddrWithId()); await waitForRemotePeer(waku, [Protocols.LightPush]); - await nwaku.ensureSubscriptions(pubSubTopics); + await nwaku.ensureSubscriptions(pubsubTopics); return [nwaku, waku]; } else { throw new Error("Failed to initialize waku"); diff --git a/packages/tests/tests/relay.node.spec.ts b/packages/tests/tests/relay.node.spec.ts index bb3045d29f..d948d6b930 100644 --- a/packages/tests/tests/relay.node.spec.ts +++ b/packages/tests/tests/relay.node.spec.ts @@ -267,7 +267,7 @@ describe("Waku Relay [node only]", () => { const CustomEncoder = createEncoder({ contentTopic: CustomContentTopic, - pubSubTopic: CustomPubSubTopic + pubsubTopic: CustomPubSubTopic }); const CustomDecoder = createDecoder(CustomContentTopic, CustomPubSubTopic); @@ -301,16 +301,16 @@ describe("Waku Relay [node only]", () => { [waku1, waku2, waku3] = await Promise.all([ createRelayNode({ - pubSubTopics: [testItem.pubsub], + pubsubTopics: [testItem.pubsub], staticNoiseKey: NOISE_KEY_1 }).then((waku) => waku.start().then(() => waku)), createRelayNode({ - pubSubTopics: [testItem.pubsub], + pubsubTopics: [testItem.pubsub], staticNoiseKey: NOISE_KEY_2, libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } } }).then((waku) => waku.start().then(() => waku)), createRelayNode({ - pubSubTopics: [testItem.pubsub], + pubsubTopics: [testItem.pubsub], staticNoiseKey: NOISE_KEY_3 }).then((waku) => waku.start().then(() => waku)) ]); @@ -401,16 +401,16 @@ describe("Waku Relay [node only]", () => { // Waku1 and waku2 are using multiple pubsub topis [waku1, waku2, waku3] = await Promise.all([ createRelayNode({ - pubSubTopics: [DefaultPubSubTopic, CustomPubSubTopic], + pubsubTopics: [DefaultPubSubTopic, CustomPubSubTopic], staticNoiseKey: NOISE_KEY_1 }).then((waku) => waku.start().then(() => waku)), createRelayNode({ - pubSubTopics: [DefaultPubSubTopic, CustomPubSubTopic], + pubsubTopics: [DefaultPubSubTopic, CustomPubSubTopic], staticNoiseKey: NOISE_KEY_2, libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } } }).then((waku) => waku.start().then(() => waku)), createRelayNode({ - pubSubTopics: [DefaultPubSubTopic], + pubsubTopics: [DefaultPubSubTopic], staticNoiseKey: NOISE_KEY_3 }).then((waku) => waku.start().then(() => waku)) ]); @@ -475,11 +475,11 @@ describe("Waku Relay [node only]", () => { [waku1, waku2, waku3] = await Promise.all([ createRelayNode({ - pubSubTopics: [CustomPubSubTopic], + pubsubTopics: [CustomPubSubTopic], staticNoiseKey: NOISE_KEY_1 }).then((waku) => waku.start().then(() => waku)), createRelayNode({ - pubSubTopics: [CustomPubSubTopic], + pubsubTopics: [CustomPubSubTopic], staticNoiseKey: NOISE_KEY_2, libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } } }).then((waku) => waku.start().then(() => waku)), @@ -529,7 +529,7 @@ describe("Waku Relay [node only]", () => { await waku3NoMsgPromise; expect(bytesToUtf8(waku2ReceivedMsg.payload!)).to.eq(messageText); - expect(waku2ReceivedMsg.pubSubTopic).to.eq(CustomPubSubTopic); + expect(waku2ReceivedMsg.pubsubTopic).to.eq(CustomPubSubTopic); }); it("Publishes <= 1 MB and rejects others", async function () { @@ -539,11 +539,11 @@ describe("Waku Relay [node only]", () => { // 1 and 2 uses a custom pubsub [waku1, waku2] = await Promise.all([ createRelayNode({ - pubSubTopics: [CustomPubSubTopic], + pubsubTopics: [CustomPubSubTopic], staticNoiseKey: NOISE_KEY_1 }).then((waku) => waku.start().then(() => waku)), createRelayNode({ - pubSubTopics: [CustomPubSubTopic], + pubsubTopics: [CustomPubSubTopic], staticNoiseKey: NOISE_KEY_2, libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } } }).then((waku) => waku.start().then(() => waku)) diff --git a/packages/tests/tests/sharding/peer_management.spec.ts b/packages/tests/tests/sharding/peer_management.spec.ts index be4c7a5210..5257c93d8d 100644 --- a/packages/tests/tests/sharding/peer_management.spec.ts +++ b/packages/tests/tests/sharding/peer_management.spec.ts @@ -38,10 +38,10 @@ describe("Static Sharding: Peer Management", function () { it("all px service nodes subscribed to the shard topic should be dialed", async function () { this.timeout(100_000); - const pubSubTopics = ["/waku/2/rs/18/2"]; + const pubsubTopics = ["/waku/2/rs/18/2"]; await nwaku1.start({ - topic: pubSubTopics, + topic: pubsubTopics, discv5Discovery: true, peerExchange: true, relay: true @@ -50,7 +50,7 @@ describe("Static Sharding: Peer Management", function () { const enr1 = (await nwaku1.info()).enrUri; await nwaku2.start({ - topic: pubSubTopics, + topic: pubsubTopics, discv5Discovery: true, peerExchange: true, discv5BootstrapNode: enr1, @@ -60,7 +60,7 @@ describe("Static Sharding: Peer Management", function () { const enr2 = (await nwaku2.info()).enrUri; await nwaku3.start({ - topic: pubSubTopics, + topic: pubsubTopics, discv5Discovery: true, peerExchange: true, discv5BootstrapNode: enr2, @@ -69,7 +69,7 @@ describe("Static Sharding: Peer Management", function () { const nwaku3Ma = await nwaku3.getMultiaddrWithId(); waku = await createLightNode({ - pubSubTopics, + pubsubTopics, libp2p: { peerDiscovery: [ bootstrap({ list: [nwaku3Ma.toString()] }), @@ -139,7 +139,7 @@ describe("Static Sharding: Peer Management", function () { const nwaku3Ma = await nwaku3.getMultiaddrWithId(); waku = await createLightNode({ - pubSubTopics: pubSubTopicsToDial, + pubsubTopics: pubSubTopicsToDial, libp2p: { peerDiscovery: [ bootstrap({ list: [nwaku3Ma.toString()] }), diff --git a/packages/tests/tests/sharding/running_nodes.spec.ts b/packages/tests/tests/sharding/running_nodes.spec.ts index 26ff23805e..14e92c6b46 100644 --- a/packages/tests/tests/sharding/running_nodes.spec.ts +++ b/packages/tests/tests/sharding/running_nodes.spec.ts @@ -29,17 +29,17 @@ describe("Static Sharding: Running Nodes", () => { it("configure the node with multiple pubsub topics", async function () { this.timeout(15_000); waku = await createLightNode({ - pubSubTopics: [PubSubTopic1, PubSubTopic2] + pubsubTopics: [PubSubTopic1, PubSubTopic2] }); const encoder1 = createEncoder({ contentTopic: ContentTopic, - pubSubTopic: PubSubTopic1 + pubsubTopic: PubSubTopic1 }); const encoder2 = createEncoder({ contentTopic: ContentTopic, - pubSubTopic: PubSubTopic2 + pubsubTopic: PubSubTopic2 }); const request1 = await waku.lightPush.send(encoder1, { @@ -57,13 +57,13 @@ describe("Static Sharding: Running Nodes", () => { it("using a protocol with unconfigured pubsub topic should fail", async function () { this.timeout(15_000); waku = await createLightNode({ - pubSubTopics: [PubSubTopic1] + pubsubTopics: [PubSubTopic1] }); // use a pubsub topic that is not configured const encoder = createEncoder({ contentTopic: ContentTopic, - pubSubTopic: PubSubTopic2 + pubsubTopic: PubSubTopic2 }); try { diff --git a/packages/tests/tests/store/cursor.node.spec.ts b/packages/tests/tests/store/cursor.node.spec.ts index 007931b390..f191caf0e0 100644 --- a/packages/tests/tests/store/cursor.node.spec.ts +++ b/packages/tests/tests/store/cursor.node.spec.ts @@ -169,7 +169,7 @@ describe("Waku Store, cursor", function () { } }); - it("Passing cursor with wrong pubSubTopic", async function () { + it("Passing cursor with wrong pubsubTopic", async function () { await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic); waku = await startAndConnectLightNode(nwaku); @@ -179,7 +179,7 @@ describe("Waku Store, cursor", function () { messages.push(msg as DecodedMessage); } } - messages[5].pubSubTopic = customPubSubTopic; + messages[5].pubsubTopic = customPubSubTopic; const cursor = await createCursor(messages[5]); try { diff --git a/packages/tests/tests/store/multiple_pubsub.spec.ts b/packages/tests/tests/store/multiple_pubsub.spec.ts index f64e80be7e..4a95da6c3a 100644 --- a/packages/tests/tests/store/multiple_pubsub.spec.ts +++ b/packages/tests/tests/store/multiple_pubsub.spec.ts @@ -113,7 +113,7 @@ describe("Waku Store, custom pubsub topic", function () { waku = await createLightNode({ staticNoiseKey: NOISE_KEY_1, - pubSubTopics: [customPubSubTopic, DefaultPubSubTopic] + pubsubTopics: [customPubSubTopic, DefaultPubSubTopic] }); await waku.start(); diff --git a/packages/tests/tests/store/utils.ts b/packages/tests/tests/store/utils.ts index f7ee512fee..646a8815bf 100644 --- a/packages/tests/tests/store/utils.ts +++ b/packages/tests/tests/store/utils.ts @@ -31,7 +31,7 @@ export async function sendMessages( instance: NimGoNode, numMessages: number, contentTopic: string, - pubSubTopic: string + pubsubTopic: string ): Promise { for (let i = 0; i < numMessages; i++) { expect( @@ -40,7 +40,7 @@ export async function sendMessages( payload: new Uint8Array([i]), contentTopic: contentTopic }), - pubSubTopic + pubsubTopic ) ).to.eq(true); await delay(1); // to ensure each timestamp is unique. @@ -56,7 +56,7 @@ export async function processQueriedMessages( for await (const query of instance.store.queryGenerator(decoders)) { for await (const msg of query) { if (msg) { - expect(msg.pubSubTopic).to.eq(expectedTopic); + expect(msg.pubsubTopic).to.eq(expectedTopic); localMessages.push(msg as DecodedMessage); } } @@ -66,10 +66,10 @@ export async function processQueriedMessages( export async function startAndConnectLightNode( instance: NimGoNode, - pubSubTopics: string[] = [DefaultPubSubTopic] + pubsubTopics: string[] = [DefaultPubSubTopic] ): Promise { const waku = await createLightNode({ - pubSubTopics: pubSubTopics, + pubsubTopics: pubsubTopics, staticNoiseKey: NOISE_KEY_1 }); await waku.start(); diff --git a/packages/tests/tests/utils.spec.ts b/packages/tests/tests/utils.spec.ts index c0001adff2..22ad45aeec 100644 --- a/packages/tests/tests/utils.spec.ts +++ b/packages/tests/tests/utils.spec.ts @@ -70,7 +70,7 @@ describe("Util: toAsyncIterator: Filter", () => { const { value } = await iterator.next(); expect(value.contentTopic).to.eq(TestContentTopic); - expect(value.pubSubTopic).to.eq(DefaultPubSubTopic); + expect(value.pubsubTopic).to.eq(DefaultPubSubTopic); expect(bytesToUtf8(value.payload)).to.eq(messageText); });