diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c0755d73b..3b9b657e23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Examples (eth-pm): Use sign typed data EIP-712 instead of personal sign. - Upgraded dependencies to remove warning at installation. - **Breaking**: Moved `DefaultPubSubTopic` to `waku.ts` and fixed the casing. +- **Breaking**: Rename all `pubsubTopic` occurrences to `pubSubTopic`, across all interfaces. ### Removed - Examples (cli-chat): The focus of this library is Web environment; diff --git a/proto/waku/v2/light_push.proto b/proto/waku/v2/light_push.proto index 0200c9d2e9..6ec111db71 100644 --- a/proto/waku/v2/light_push.proto +++ b/proto/waku/v2/light_push.proto @@ -5,7 +5,7 @@ package waku.v2; import "waku/v2/message.proto"; message PushRequest { - string pubsub_topic = 1; + string pub_sub_topic = 1; WakuMessage message = 2; } diff --git a/proto/waku/v2/store.proto b/proto/waku/v2/store.proto index 431a38b920..7796348034 100644 --- a/proto/waku/v2/store.proto +++ b/proto/waku/v2/store.proto @@ -25,7 +25,7 @@ message ContentFilter { } message HistoryQuery { - optional string pubsub_topic = 2; + optional string pub_sub_topic = 2; repeated ContentFilter content_filters = 3; optional PagingInfo paging_info = 4; optional double start_time = 5; diff --git a/src/lib/waku.ts b/src/lib/waku.ts index 9d66f2651d..9d7d3e9cd5 100644 --- a/src/lib/waku.ts +++ b/src/lib/waku.ts @@ -50,7 +50,7 @@ export interface CreateOptions { * * @default {@link DefaultPubSubTopic} */ - pubsubTopic?: string; + pubSubTopic?: string; /** * Set keep alive frequency in seconds: Waku will send a `/ipfs/ping/1.0.0` * request to each peer after the set number of seconds. Set to 0 to disable. @@ -158,9 +158,9 @@ export class Waku { ); // Pass pubsub topic to relay - if (options?.pubsubTopic) { + if (options?.pubSubTopic) { libp2pOpts.config.pubsub = Object.assign( - { pubsubTopic: options.pubsubTopic }, + { pubSubTopic: options.pubSubTopic }, libp2pOpts.config.pubsub ); } @@ -222,7 +222,7 @@ export class Waku { const libp2p = await Libp2p.create(libp2pOpts); const wakuStore = new WakuStore(libp2p, { - pubsubTopic: options?.pubsubTopic, + pubSubTopic: options?.pubSubTopic, }); const wakuLightPush = new WakuLightPush(libp2p); diff --git a/src/lib/waku_light_push/index.spec.ts b/src/lib/waku_light_push/index.spec.ts index fa7b7f110a..819b48bfb5 100644 --- a/src/lib/waku_light_push/index.spec.ts +++ b/src/lib/waku_light_push/index.spec.ts @@ -66,7 +66,7 @@ describe('Waku Light Push', () => { await nimWaku.start({ lightpush: true, topics: customPubSubTopic }); waku = await Waku.create({ - pubsubTopic: customPubSubTopic, + pubSubTopic: customPubSubTopic, staticNoiseKey: NOISE_KEY_1, libp2p: { modules: { transport: [TCP] } }, }); diff --git a/src/lib/waku_light_push/index.ts b/src/lib/waku_light_push/index.ts index 334483950f..e9fe73066f 100644 --- a/src/lib/waku_light_push/index.ts +++ b/src/lib/waku_light_push/index.ts @@ -66,10 +66,10 @@ export class WakuLightPush { const { stream } = await connection.newStream(LightPushCodec); try { - const pubsubTopic = opts?.pubSubTopic + const pubSubTopic = opts?.pubSubTopic ? opts.pubSubTopic : this.pubSubTopic; - const query = PushRPC.createRequest(message, pubsubTopic); + const query = PushRPC.createRequest(message, pubSubTopic); const res = await pipe( [query.encode()], lp.encode(), diff --git a/src/lib/waku_light_push/push_rpc.ts b/src/lib/waku_light_push/push_rpc.ts index 2f0c294bad..6f461b53ba 100644 --- a/src/lib/waku_light_push/push_rpc.ts +++ b/src/lib/waku_light_push/push_rpc.ts @@ -7,12 +7,12 @@ import { WakuMessage } from '../waku_message'; export class PushRPC { public constructor(public proto: proto.PushRPC) {} - static createRequest(message: WakuMessage, pubsubTopic: string): PushRPC { + static createRequest(message: WakuMessage, pubSubTopic: string): PushRPC { return new PushRPC({ requestId: uuid(), request: { message: message.proto, - pubsubTopic, + pubSubTopic: pubSubTopic, }, response: undefined, }); diff --git a/src/lib/waku_relay/index.spec.ts b/src/lib/waku_relay/index.spec.ts index 6dd4b4d608..b073310bc8 100644 --- a/src/lib/waku_relay/index.spec.ts +++ b/src/lib/waku_relay/index.spec.ts @@ -178,16 +178,16 @@ describe('Waku Relay', () => { it('Publish', async function () { this.timeout(10000); - const pubsubTopic = '/some/pubsub/topic'; + const pubSubTopic = '/some/pubsub/topic'; // 1 and 2 uses a custom pubsub const [waku1, waku2, waku3] = await Promise.all([ Waku.create({ - pubsubTopic, + pubSubTopic: pubSubTopic, staticNoiseKey: NOISE_KEY_1, }), Waku.create({ - pubsubTopic, + pubSubTopic: pubSubTopic, staticNoiseKey: NOISE_KEY_2, libp2p: { addresses: { listen: ['/ip4/0.0.0.0/tcp/0/ws'] } }, }), diff --git a/src/lib/waku_relay/index.ts b/src/lib/waku_relay/index.ts index d57d7633c1..5844e4f211 100644 --- a/src/lib/waku_relay/index.ts +++ b/src/lib/waku_relay/index.ts @@ -62,7 +62,7 @@ export interface GossipOptions { */ export class WakuRelay extends Gossipsub { heartbeat: RelayHeartbeat; - pubsubTopic: string; + pubSubTopic: string; /** * Decryption private keys to use to attempt decryption of incoming messages. @@ -97,7 +97,7 @@ export class WakuRelay extends Gossipsub { Object.assign(this, { multicodecs }); - this.pubsubTopic = options?.pubsubTopic || DefaultPubSubTopic; + this.pubSubTopic = options?.pubSubTopic || DefaultPubSubTopic; } /** @@ -109,7 +109,7 @@ export class WakuRelay extends Gossipsub { */ public start(): void { super.start(); - this.subscribe(this.pubsubTopic); + this.subscribe(this.pubSubTopic); } /** @@ -120,7 +120,7 @@ export class WakuRelay extends Gossipsub { */ public async send(message: WakuMessage): Promise { const msg = message.encode(); - await super.publish(this.pubsubTopic, Buffer.from(msg)); + await super.publish(this.pubSubTopic, Buffer.from(msg)); } /** @@ -194,7 +194,7 @@ export class WakuRelay extends Gossipsub { * Return the relay peers we are connected to and we would publish a message to */ getPeers(): Set { - return getRelayPeers(this, this.pubsubTopic, this._options.D, (id) => { + return getRelayPeers(this, this.pubSubTopic, this._options.D, (id) => { // Filter peers we would not publish to return ( this.score.score(id) >= this._options.scoreThresholds.publishThreshold @@ -207,9 +207,9 @@ export class WakuRelay extends Gossipsub { * * @override */ - subscribe(pubsubTopic: string): void { - this.on(pubsubTopic, (event) => { - dbg(`Message received on ${pubsubTopic}`); + subscribe(pubSubTopic: string): void { + this.on(pubSubTopic, (event) => { + dbg(`Message received on ${pubSubTopic}`); WakuMessage.decode(event.data, Array.from(this.decryptionKeys)) .then((wakuMsg) => { if (!wakuMsg) { @@ -235,7 +235,7 @@ export class WakuRelay extends Gossipsub { }); }); - super.subscribe(pubsubTopic); + super.subscribe(pubSubTopic); } /** diff --git a/src/lib/waku_store/history_rpc.ts b/src/lib/waku_store/history_rpc.ts index 681f915083..dd2ad185ae 100644 --- a/src/lib/waku_store/history_rpc.ts +++ b/src/lib/waku_store/history_rpc.ts @@ -11,7 +11,7 @@ export enum Direction { export interface Params { contentTopics: string[]; cursor?: proto.Index; - pubsubTopic: string; + pubSubTopic: string; direction: Direction; pageSize: number; } @@ -37,7 +37,7 @@ export class HistoryRPC { return new HistoryRPC({ requestId: uuid(), query: { - pubsubTopic: params.pubsubTopic, + pubSubTopic: params.pubSubTopic, contentFilters, pagingInfo, startTime: undefined, diff --git a/src/lib/waku_store/index.spec.ts b/src/lib/waku_store/index.spec.ts index cf66002f32..a41bb84cc2 100644 --- a/src/lib/waku_store/index.spec.ts +++ b/src/lib/waku_store/index.spec.ts @@ -120,7 +120,7 @@ describe('Waku Store', () => { } waku = await Waku.create({ - pubsubTopic: customPubSubTopic, + pubSubTopic: customPubSubTopic, staticNoiseKey: NOISE_KEY_1, libp2p: { modules: { transport: [TCP] } }, }); diff --git a/src/lib/waku_store/index.ts b/src/lib/waku_store/index.ts index 0bf2820d48..2ecbcecc5d 100644 --- a/src/lib/waku_store/index.ts +++ b/src/lib/waku_store/index.ts @@ -28,12 +28,12 @@ export interface CreateOptions { * * @default {@link DefaultPubSubTopic} */ - pubsubTopic?: string; + pubSubTopic?: string; } export interface QueryOptions { peerId?: PeerId; - pubsubTopic?: string; + pubSubTopic?: string; direction?: Direction; pageSize?: number; callback?: (messages: WakuMessage[]) => void; @@ -44,13 +44,13 @@ export interface QueryOptions { * Implements the [Waku v2 Store protocol](https://rfc.vac.dev/spec/13/). */ export class WakuStore { - pubsubTopic: string; + pubSubTopic: string; constructor(public libp2p: Libp2p, options?: CreateOptions) { - if (options?.pubsubTopic) { - this.pubsubTopic = options.pubsubTopic; + if (options?.pubSubTopic) { + this.pubSubTopic = options.pubSubTopic; } else { - this.pubsubTopic = DefaultPubSubTopic; + this.pubSubTopic = DefaultPubSubTopic; } } @@ -61,7 +61,7 @@ export class WakuStore { * retrieve all messages. * @param options * @param options.peerId The peer to query.Options - * @param options.pubsubTopic The pubsub topic to pass to the query. Defaults + * @param options.pubSubTopic The pubsub topic to pass to the query. Defaults * to the value set at creation. See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/). * @param options.callback Callback called on page of stored messages as they are retrieved * @param options.decryptionKeys Keys that will be used to decrypt messages. @@ -75,7 +75,7 @@ export class WakuStore { ): Promise { const opts = Object.assign( { - pubsubTopic: this.pubsubTopic, + pubSubTopic: this.pubSubTopic, direction: Direction.BACKWARD, pageSize: 10, }, @@ -131,7 +131,7 @@ export class WakuStore { } dbg( - `${response.messages.length} messages retrieved for pubsub topic ${opts.pubsubTopic}` + `${response.messages.length} messages retrieved for pubsub topic ${opts.pubSubTopic}` ); const pageMessages: WakuMessage[] = []; diff --git a/src/proto/waku/v2/light_push.ts b/src/proto/waku/v2/light_push.ts index 74dc68b013..bff84d2fca 100644 --- a/src/proto/waku/v2/light_push.ts +++ b/src/proto/waku/v2/light_push.ts @@ -6,7 +6,7 @@ import { WakuMessage } from '../../waku/v2/message'; export const protobufPackage = 'waku.v2'; export interface PushRequest { - pubsubTopic: string; + pubSubTopic: string; message: WakuMessage | undefined; } @@ -21,15 +21,15 @@ export interface PushRPC { response: PushResponse | undefined; } -const basePushRequest: object = { pubsubTopic: '' }; +const basePushRequest: object = { pubSubTopic: '' }; export const PushRequest = { encode( message: PushRequest, writer: _m0.Writer = _m0.Writer.create() ): _m0.Writer { - if (message.pubsubTopic !== '') { - writer.uint32(10).string(message.pubsubTopic); + if (message.pubSubTopic !== '') { + writer.uint32(10).string(message.pubSubTopic); } if (message.message !== undefined) { WakuMessage.encode(message.message, writer.uint32(18).fork()).ldelim(); @@ -45,7 +45,7 @@ export const PushRequest = { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.pubsubTopic = reader.string(); + message.pubSubTopic = reader.string(); break; case 2: message.message = WakuMessage.decode(reader, reader.uint32()); @@ -60,10 +60,10 @@ export const PushRequest = { fromJSON(object: any): PushRequest { const message = { ...basePushRequest } as PushRequest; - if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) { - message.pubsubTopic = String(object.pubsubTopic); + if (object.pubSubTopic !== undefined && object.pubSubTopic !== null) { + message.pubSubTopic = String(object.pubSubTopic); } else { - message.pubsubTopic = ''; + message.pubSubTopic = ''; } if (object.message !== undefined && object.message !== null) { message.message = WakuMessage.fromJSON(object.message); @@ -75,8 +75,8 @@ export const PushRequest = { toJSON(message: PushRequest): unknown { const obj: any = {}; - message.pubsubTopic !== undefined && - (obj.pubsubTopic = message.pubsubTopic); + message.pubSubTopic !== undefined && + (obj.pubSubTopic = message.pubSubTopic); message.message !== undefined && (obj.message = message.message ? WakuMessage.toJSON(message.message) @@ -86,10 +86,10 @@ export const PushRequest = { fromPartial(object: DeepPartial): PushRequest { const message = { ...basePushRequest } as PushRequest; - if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) { - message.pubsubTopic = object.pubsubTopic; + if (object.pubSubTopic !== undefined && object.pubSubTopic !== null) { + message.pubSubTopic = object.pubSubTopic; } else { - message.pubsubTopic = ''; + message.pubSubTopic = ''; } if (object.message !== undefined && object.message !== null) { message.message = WakuMessage.fromPartial(object.message); diff --git a/src/proto/waku/v2/store.ts b/src/proto/waku/v2/store.ts index 5be71d8d29..19bb9180a9 100644 --- a/src/proto/waku/v2/store.ts +++ b/src/proto/waku/v2/store.ts @@ -58,7 +58,7 @@ export interface ContentFilter { } export interface HistoryQuery { - pubsubTopic?: string | undefined; + pubSubTopic?: string | undefined; contentFilters: ContentFilter[]; pagingInfo?: PagingInfo | undefined; startTime?: number | undefined; @@ -366,8 +366,8 @@ export const HistoryQuery = { message: HistoryQuery, writer: _m0.Writer = _m0.Writer.create() ): _m0.Writer { - if (message.pubsubTopic !== undefined) { - writer.uint32(18).string(message.pubsubTopic); + if (message.pubSubTopic !== undefined) { + writer.uint32(18).string(message.pubSubTopic); } for (const v of message.contentFilters) { ContentFilter.encode(v!, writer.uint32(26).fork()).ldelim(); @@ -393,7 +393,7 @@ export const HistoryQuery = { const tag = reader.uint32(); switch (tag >>> 3) { case 2: - message.pubsubTopic = reader.string(); + message.pubSubTopic = reader.string(); break; case 3: message.contentFilters.push( @@ -420,10 +420,10 @@ export const HistoryQuery = { fromJSON(object: any): HistoryQuery { const message = { ...baseHistoryQuery } as HistoryQuery; message.contentFilters = []; - if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) { - message.pubsubTopic = String(object.pubsubTopic); + if (object.pubSubTopic !== undefined && object.pubSubTopic !== null) { + message.pubSubTopic = String(object.pubSubTopic); } else { - message.pubsubTopic = undefined; + message.pubSubTopic = undefined; } if (object.contentFilters !== undefined && object.contentFilters !== null) { for (const e of object.contentFilters) { @@ -450,8 +450,8 @@ export const HistoryQuery = { toJSON(message: HistoryQuery): unknown { const obj: any = {}; - message.pubsubTopic !== undefined && - (obj.pubsubTopic = message.pubsubTopic); + message.pubSubTopic !== undefined && + (obj.pubSubTopic = message.pubSubTopic); if (message.contentFilters) { obj.contentFilters = message.contentFilters.map((e) => e ? ContentFilter.toJSON(e) : undefined @@ -471,10 +471,10 @@ export const HistoryQuery = { fromPartial(object: DeepPartial): HistoryQuery { const message = { ...baseHistoryQuery } as HistoryQuery; message.contentFilters = []; - if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) { - message.pubsubTopic = object.pubsubTopic; + if (object.pubSubTopic !== undefined && object.pubSubTopic !== null) { + message.pubSubTopic = object.pubSubTopic; } else { - message.pubsubTopic = undefined; + message.pubSubTopic = undefined; } if (object.contentFilters !== undefined && object.contentFilters !== null) { for (const e of object.contentFilters) { diff --git a/src/test_utils/nim_waku.ts b/src/test_utils/nim_waku.ts index 8f93b6908c..d2ce6cd424 100644 --- a/src/test_utils/nim_waku.ts +++ b/src/test_utils/nim_waku.ts @@ -171,7 +171,7 @@ export class NimWaku { async sendMessage( message: WakuMessage, - pubsubTopic?: string + pubSubTopic?: string ): Promise { this.checkProcess(); @@ -195,7 +195,7 @@ export class NimWaku { }; return this.rpcCall('post_waku_v2_relay_v1_message', [ - pubsubTopic ? pubsubTopic : DefaultPubSubTopic, + pubSubTopic ? pubSubTopic : DefaultPubSubTopic, rpcMessage, ]); } @@ -233,7 +233,7 @@ export class NimWaku { async postAsymmetricMessage( message: WakuRelayMessage, publicKey: Uint8Array, - pubsubTopic?: string + pubSubTopic?: string ): Promise { this.checkProcess(); @@ -242,7 +242,7 @@ export class NimWaku { } return this.rpcCall('post_waku_v2_private_v1_asymmetric_message', [ - pubsubTopic ? pubsubTopic : DefaultPubSubTopic, + pubSubTopic ? pubSubTopic : DefaultPubSubTopic, message, '0x' + bufToHex(publicKey), ]); @@ -250,14 +250,14 @@ export class NimWaku { 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' + bufToHex(privateKey), ] ); @@ -275,7 +275,7 @@ export class NimWaku { async postSymmetricMessage( message: WakuRelayMessage, symKey: Uint8Array, - pubsubTopic?: string + pubSubTopic?: string ): Promise { this.checkProcess(); @@ -284,7 +284,7 @@ export class NimWaku { } return this.rpcCall('post_waku_v2_private_v1_symmetric_message', [ - pubsubTopic ? pubsubTopic : DefaultPubSubTopic, + pubSubTopic ? pubSubTopic : DefaultPubSubTopic, message, '0x' + bufToHex(symKey), ]); @@ -292,13 +292,13 @@ export class NimWaku { 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, '0x' + bufToHex(symKey)] + [pubSubTopic ? pubSubTopic : DefaultPubSubTopic, '0x' + bufToHex(symKey)] ); }