mirror of https://github.com/waku-org/js-waku.git
Merge pull request #270 from status-im/200-pubsub-topic
Moved `DefaultPubSubTopic` to `waku.ts` and fixed the casing
This commit is contained in:
commit
c2109736d4
|
@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
refers to low latency network connections.
|
||||
- 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;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "eth-pm",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@material-ui/core": "^4.11.4",
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,7 +2,7 @@ export { getBootstrapNodes } from './lib/discovery';
|
|||
|
||||
export * as utils from './lib/utils';
|
||||
|
||||
export { Waku } from './lib/waku';
|
||||
export { Waku, DefaultPubSubTopic } from './lib/waku';
|
||||
|
||||
export { WakuMessage } from './lib/waku_message';
|
||||
|
||||
|
|
|
@ -29,11 +29,16 @@ const websocketsTransportKey = Websockets.prototype[Symbol.toStringTag];
|
|||
export const DefaultPingKeepAliveValueSecs = 0;
|
||||
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
||||
|
||||
/**
|
||||
* DefaultPubSubTopic is the default gossipsub topic to use for Waku.
|
||||
*/
|
||||
export const DefaultPubSubTopic = '/waku/2/default-waku/proto';
|
||||
|
||||
const dbg = debug('waku:waku');
|
||||
|
||||
export interface CreateOptions {
|
||||
/**
|
||||
* The PubSub Topic to use. Defaults to {@link DefaultPubsubTopic}.
|
||||
* The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}.
|
||||
*
|
||||
* One and only one pubsub topic is used by Waku. This is used by:
|
||||
* - WakuRelay to receive, route and send messages,
|
||||
|
@ -43,9 +48,9 @@ export interface CreateOptions {
|
|||
* The usage of the default pubsub topic is recommended.
|
||||
* See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
|
||||
*
|
||||
* @default {@link DefaultPubsubTopic}
|
||||
* @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.
|
||||
|
@ -153,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
|
||||
);
|
||||
}
|
||||
|
@ -217,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);
|
||||
|
||||
|
|
|
@ -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] } },
|
||||
});
|
||||
|
|
|
@ -7,8 +7,8 @@ import PeerId from 'peer-id';
|
|||
|
||||
import { PushResponse } from '../../proto/waku/v2/light_push';
|
||||
import { getPeersForProtocol, selectRandomPeer } from '../select_peer';
|
||||
import { DefaultPubSubTopic } from '../waku';
|
||||
import { WakuMessage } from '../waku_message';
|
||||
import { DefaultPubsubTopic } from '../waku_relay';
|
||||
|
||||
import { PushRPC } from './push_rpc';
|
||||
|
||||
|
@ -17,32 +17,32 @@ export { PushResponse };
|
|||
|
||||
export interface CreateOptions {
|
||||
/**
|
||||
* The PubSub Topic to use. Defaults to {@link DefaultPubsubTopic}.
|
||||
* The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}.
|
||||
*
|
||||
* The usage of the default pubsub topic is recommended.
|
||||
* See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
|
||||
*
|
||||
* @default {@link DefaultPubsubTopic}
|
||||
* @default {@link DefaultPubSubTopic}
|
||||
*/
|
||||
pubsubTopic?: string;
|
||||
pubSubTopic?: string;
|
||||
}
|
||||
|
||||
export interface PushOptions {
|
||||
peerId?: PeerId;
|
||||
pubsubTopic?: string;
|
||||
pubSubTopic?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
||||
*/
|
||||
export class WakuLightPush {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,10 +66,10 @@ export class WakuLightPush {
|
|||
|
||||
const { stream } = await connection.newStream(LightPushCodec);
|
||||
try {
|
||||
const pubsubTopic = opts?.pubsubTopic
|
||||
? opts.pubsubTopic
|
||||
: this.pubsubTopic;
|
||||
const query = PushRPC.createRequest(message, pubsubTopic);
|
||||
const pubSubTopic = opts?.pubSubTopic
|
||||
? opts.pubSubTopic
|
||||
: this.pubSubTopic;
|
||||
const query = PushRPC.createRequest(message, pubSubTopic);
|
||||
const res = await pipe(
|
||||
[query.encode()],
|
||||
lp.encode(),
|
||||
|
|
|
@ -3,20 +3,16 @@ import { v4 as uuid } from 'uuid';
|
|||
|
||||
import * as proto from '../../proto/waku/v2/light_push';
|
||||
import { WakuMessage } from '../waku_message';
|
||||
import { DefaultPubsubTopic } from '../waku_relay';
|
||||
|
||||
export class PushRPC {
|
||||
public constructor(public proto: proto.PushRPC) {}
|
||||
|
||||
static createRequest(
|
||||
message: WakuMessage,
|
||||
pubsubTopic: string = DefaultPubsubTopic
|
||||
): PushRPC {
|
||||
static createRequest(message: WakuMessage, pubSubTopic: string): PushRPC {
|
||||
return new PushRPC({
|
||||
requestId: uuid(),
|
||||
request: {
|
||||
message: message.proto,
|
||||
pubsubTopic,
|
||||
pubSubTopic: pubSubTopic,
|
||||
},
|
||||
response: undefined,
|
||||
});
|
||||
|
|
|
@ -9,11 +9,6 @@ export const RelayCodecs = [
|
|||
'/vac/waku/relay/2.0.0',
|
||||
];
|
||||
|
||||
/**
|
||||
* DefaultPubsubTopic is the default gossipsub topic to use for Waku.
|
||||
*/
|
||||
export const DefaultPubsubTopic = '/waku/2/default-waku/proto';
|
||||
|
||||
export const RelayPingContentTopic = '/relay-ping/1/ping/null';
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,11 +11,9 @@ import {
|
|||
NOISE_KEY_2,
|
||||
} from '../../test_utils';
|
||||
import { delay } from '../delay';
|
||||
import { Waku } from '../waku';
|
||||
import { DefaultPubSubTopic, Waku } from '../waku';
|
||||
import { WakuMessage } from '../waku_message';
|
||||
|
||||
import { DefaultPubsubTopic } from './index';
|
||||
|
||||
const log = debug('waku:test');
|
||||
|
||||
const TestContentTopic = '/test/1/waku-relay/utf8';
|
||||
|
@ -63,9 +61,9 @@ describe('Waku Relay', () => {
|
|||
|
||||
it('Subscribe', async function () {
|
||||
const subscribers1 =
|
||||
waku1.libp2p.pubsub.getSubscribers(DefaultPubsubTopic);
|
||||
waku1.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
|
||||
const subscribers2 =
|
||||
waku2.libp2p.pubsub.getSubscribers(DefaultPubsubTopic);
|
||||
waku2.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
|
||||
|
||||
expect(subscribers1).to.contain(waku2.libp2p.peerId.toB58String());
|
||||
expect(subscribers2).to.contain(waku1.libp2p.peerId.toB58String());
|
||||
|
@ -180,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'] } },
|
||||
}),
|
||||
|
@ -282,7 +280,7 @@ describe('Waku Relay', () => {
|
|||
it('nim subscribes to js', async function () {
|
||||
const nimPeerId = await nimWaku.getPeerId();
|
||||
const subscribers =
|
||||
waku.libp2p.pubsub.getSubscribers(DefaultPubsubTopic);
|
||||
waku.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
|
||||
|
||||
expect(subscribers).to.contain(nimPeerId.toB58String());
|
||||
});
|
||||
|
@ -371,7 +369,7 @@ describe('Waku Relay', () => {
|
|||
|
||||
while (subscribers.length === 0) {
|
||||
await delay(200);
|
||||
subscribers = waku.libp2p.pubsub.getSubscribers(DefaultPubsubTopic);
|
||||
subscribers = waku.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
|
||||
}
|
||||
|
||||
const nimPeerId = await nimWaku.getPeerId();
|
||||
|
|
|
@ -17,17 +17,17 @@ import { InMessage } from 'libp2p-interfaces/src/pubsub';
|
|||
import { SignaturePolicy } from 'libp2p-interfaces/src/pubsub/signature-policy';
|
||||
import PeerId from 'peer-id';
|
||||
|
||||
import { CreateOptions } from '../waku';
|
||||
import { CreateOptions, DefaultPubSubTopic } from '../waku';
|
||||
import { WakuMessage } from '../waku_message';
|
||||
|
||||
import * as constants from './constants';
|
||||
import { DefaultPubsubTopic, RelayCodecs } from './constants';
|
||||
import { RelayCodecs } from './constants';
|
||||
import { getRelayPeers } from './get_relay_peers';
|
||||
import { RelayHeartbeat } from './relay_heartbeat';
|
||||
|
||||
const dbg = debug('waku:relay');
|
||||
|
||||
export { RelayCodecs, DefaultPubsubTopic };
|
||||
export { RelayCodecs };
|
||||
|
||||
/**
|
||||
* See constructor libp2p-gossipsub [API](https://github.com/ChainSafe/js-libp2p-gossipsub#api).
|
||||
|
@ -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 || constants.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<void> {
|
||||
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<string> {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,7 +250,7 @@ export class WakuRelay extends Gossipsub {
|
|||
*/
|
||||
join(topic: string): void {
|
||||
if (!this.started) {
|
||||
throw new Error('WakuRelayPubsub has not started');
|
||||
throw new Error('WakuRelayPubSub has not started');
|
||||
}
|
||||
|
||||
const fanoutPeers = this.fanout.get(topic);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -120,7 +120,7 @@ describe('Waku Store', () => {
|
|||
}
|
||||
|
||||
waku = await Waku.create({
|
||||
pubsubTopic: customPubSubTopic,
|
||||
pubSubTopic: customPubSubTopic,
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { modules: { transport: [TCP] } },
|
||||
});
|
||||
|
|
|
@ -8,8 +8,8 @@ import PeerId from 'peer-id';
|
|||
|
||||
import { HistoryResponse_Error } from '../../proto/waku/v2/store';
|
||||
import { getPeersForProtocol, selectRandomPeer } from '../select_peer';
|
||||
import { DefaultPubSubTopic } from '../waku';
|
||||
import { WakuMessage } from '../waku_message';
|
||||
import { DefaultPubsubTopic } from '../waku_relay';
|
||||
|
||||
import { Direction, HistoryRPC } from './history_rpc';
|
||||
|
||||
|
@ -21,19 +21,19 @@ export { Direction };
|
|||
|
||||
export interface CreateOptions {
|
||||
/**
|
||||
* The PubSub Topic to use. Defaults to {@link DefaultPubsubTopic}.
|
||||
* The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}.
|
||||
*
|
||||
* The usage of the default pubsub topic is recommended.
|
||||
* See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
|
||||
*
|
||||
* @default {@link DefaultPubsubTopic}
|
||||
* @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<WakuMessage[]> {
|
||||
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[] = [];
|
||||
|
|
|
@ -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>): 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);
|
||||
|
|
|
@ -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>): 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) {
|
||||
|
|
|
@ -13,8 +13,8 @@ import { Multiaddr, multiaddr } from 'multiaddr';
|
|||
import PeerId from 'peer-id';
|
||||
|
||||
import { hexToBuf } from '../lib/utils';
|
||||
import { DefaultPubSubTopic } from '../lib/waku';
|
||||
import { WakuMessage } from '../lib/waku_message';
|
||||
import { DefaultPubsubTopic } from '../lib/waku_relay';
|
||||
import * as proto from '../proto/waku/v2/message';
|
||||
|
||||
import { existsAsync, mkdirAsync, openAsync } from './async_fs';
|
||||
|
@ -171,7 +171,7 @@ export class NimWaku {
|
|||
|
||||
async sendMessage(
|
||||
message: WakuMessage,
|
||||
pubsubTopic?: string
|
||||
pubSubTopic?: string
|
||||
): Promise<boolean> {
|
||||
this.checkProcess();
|
||||
|
||||
|
@ -195,7 +195,7 @@ export class NimWaku {
|
|||
};
|
||||
|
||||
return this.rpcCall<boolean>('post_waku_v2_relay_v1_message', [
|
||||
pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
|
||||
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
|
||||
rpcMessage,
|
||||
]);
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ export class NimWaku {
|
|||
|
||||
const protoMsgs = await this.rpcCall<proto.WakuMessage[]>(
|
||||
'get_waku_v2_relay_v1_messages',
|
||||
[DefaultPubsubTopic]
|
||||
[DefaultPubSubTopic]
|
||||
);
|
||||
|
||||
const msgs = await Promise.all(
|
||||
|
@ -233,7 +233,7 @@ export class NimWaku {
|
|||
async postAsymmetricMessage(
|
||||
message: WakuRelayMessage,
|
||||
publicKey: Uint8Array,
|
||||
pubsubTopic?: string
|
||||
pubSubTopic?: string
|
||||
): Promise<boolean> {
|
||||
this.checkProcess();
|
||||
|
||||
|
@ -242,7 +242,7 @@ export class NimWaku {
|
|||
}
|
||||
|
||||
return this.rpcCall<boolean>('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<WakuRelayMessage[]> {
|
||||
this.checkProcess();
|
||||
|
||||
return await this.rpcCall<WakuRelayMessage[]>(
|
||||
'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<boolean> {
|
||||
this.checkProcess();
|
||||
|
||||
|
@ -284,7 +284,7 @@ export class NimWaku {
|
|||
}
|
||||
|
||||
return this.rpcCall<boolean>('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<WakuRelayMessage[]> {
|
||||
this.checkProcess();
|
||||
|
||||
return await this.rpcCall<WakuRelayMessage[]>(
|
||||
'get_waku_v2_private_v1_symmetric_messages',
|
||||
[pubsubTopic ? pubsubTopic : DefaultPubsubTopic, '0x' + bufToHex(symKey)]
|
||||
[pubSubTopic ? pubSubTopic : DefaultPubSubTopic, '0x' + bufToHex(symKey)]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue