Skip to content

Commit 3b4bc8b

Browse files
chore: update changelog & minor improvements (#1153)
* address comments from #1145 * fix: typedoc * address comments in #1146 (review) - update changelog - change naming for `EciesEncoderOptions` and `SymmetricEncoderOptions`
1 parent 598c8d3 commit 3b4bc8b

File tree

7 files changed

+53
-57
lines changed

7 files changed

+53
-57
lines changed

packages/core/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Dependency on `@waku/peer-exchange`.
1717

18+
### Changed
19+
20+
- `Filter`, `LightPush` and `Store` classes now takes in `options` of type `ProtocolCreateOptions` as the second argument, instead of `pubSubTopic`
21+
- `Relay` class now takes in `options` of type `Partial<RealyCreateOptions>` as the second argument, instead of `pubSubTopic`
22+
1823
## [@waku/core@0.0.10] - 2023-01-25
1924

2025
### Changed

packages/core/src/lib/relay/index.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type RelayCreateOptions = ProtocolCreateOptions & GossipsubOpts;
4040
* @implements {require('libp2p-interfaces/src/pubsub')}
4141
*/
4242
class Relay extends GossipSub implements IRelay {
43-
options: Partial<RelayCreateOptions>;
43+
private pubSubTopic: string;
4444
defaultDecoder: IDecoder<IDecodedMessage>;
4545
public static multicodec: string = constants.RelayCodecs[0];
4646

@@ -63,9 +63,9 @@ class Relay extends GossipSub implements IRelay {
6363
super(components, options);
6464
this.multicodecs = constants.RelayCodecs;
6565

66-
this.observers = new Map();
66+
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
6767

68-
this.options = options ?? {};
68+
this.observers = new Map();
6969

7070
// TODO: User might want to decide what decoder should be used (e.g. for RLN)
7171
this.defaultDecoder = new TopicOnlyDecoder();
@@ -79,24 +79,21 @@ class Relay extends GossipSub implements IRelay {
7979
* @returns {void}
8080
*/
8181
public async start(): Promise<void> {
82-
const { pubSubTopic = DefaultPubSubTopic } = this.options;
8382
await super.start();
84-
this.subscribe(pubSubTopic);
83+
this.subscribe(this.pubSubTopic);
8584
}
8685

8786
/**
8887
* Send Waku message.
8988
*/
9089
public async send(encoder: IEncoder, message: IMessage): Promise<SendResult> {
91-
const { pubSubTopic = DefaultPubSubTopic } = this.options;
92-
9390
const msg = await encoder.toWire(message);
9491
if (!msg) {
9592
log("Failed to encode message, aborting publish");
9693
return { recipients: [] };
9794
}
9895

99-
return this.publish(pubSubTopic, msg);
96+
return this.publish(this.pubSubTopic, msg);
10097
}
10198

10299
/**
@@ -172,8 +169,7 @@ class Relay extends GossipSub implements IRelay {
172169
}
173170

174171
getMeshPeers(topic?: TopicStr): PeerIdStr[] {
175-
const { pubSubTopic = DefaultPubSubTopic } = this.options;
176-
return super.getMeshPeers(topic ?? pubSubTopic);
172+
return super.getMeshPeers(topic ?? this.pubSubTopic);
177173
}
178174
}
179175

packages/create/src/index.ts

+10-37
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ import {
1414
} from "@waku/core";
1515
import { DefaultUserAgent } from "@waku/core";
1616
import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery";
17-
import type { FullNode, IRelay, LightNode, RelayNode } from "@waku/interfaces";
17+
import type {
18+
FullNode,
19+
IRelay,
20+
LightNode,
21+
ProtocolCreateOptions,
22+
RelayNode,
23+
} from "@waku/interfaces";
1824
import { wakuPeerExchange } from "@waku/peer-exchange";
1925
import type { Libp2p } from "libp2p";
2026
import { createLibp2p, Libp2pOptions } from "libp2p";
@@ -29,39 +35,6 @@ const DEFAULT_NODE_REQUIREMENTS = {
2935

3036
export { Libp2pComponents };
3137

32-
export interface CreateOptions {
33-
/**
34-
* The PubSub Topic to use.
35-
*
36-
* One and only one pubsub topic is used by Waku. This is used by:
37-
* - WakuRelay to receive, route and send messages,
38-
* - WakuLightPush to send messages,
39-
* - WakuStore to retrieve messages.
40-
*
41-
* The usage of the default pubsub topic is recommended.
42-
* See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
43-
*/
44-
pubSubTopic?: string;
45-
/**
46-
* You can pass options to the `Libp2p` instance used by {@link @waku/core.WakuNode} using the {@link CreateOptions.libp2p} property.
47-
* 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)
48-
* apart that we made the `modules` property optional and partial,
49-
* allowing its omission and letting Waku set good defaults.
50-
* Notes that some values are overridden by {@link @waku/core.WakuNode} to ensure it implements the Waku protocol.
51-
*/
52-
libp2p?: Partial<Libp2pOptions>;
53-
/**
54-
* Byte array used as key for the noise protocol used for connection encryption
55-
* by [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
56-
* This is only used for test purposes to not run out of entropy during CI runs.
57-
*/
58-
staticNoiseKey?: Uint8Array;
59-
/**
60-
* Use recommended bootstrap method to discovery and connect to new nodes.
61-
*/
62-
defaultBootstrap?: boolean;
63-
}
64-
6538
/**
6639
* Create a Waku node that uses Waku Light Push, Filter and Store to send and
6740
* receive messages, enabling low resource consumption.
@@ -70,7 +43,7 @@ export interface CreateOptions {
7043
* @see https://github.com/status-im/nwaku/issues/1085
7144
*/
7245
export async function createLightNode(
73-
options?: CreateOptions & WakuOptions
46+
options?: ProtocolCreateOptions & WakuOptions
7447
): Promise<LightNode> {
7548
const libp2pOptions = options?.libp2p ?? {};
7649
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
@@ -106,7 +79,7 @@ export async function createLightNode(
10679
* enabling some privacy preserving properties.
10780
*/
10881
export async function createRelayNode(
109-
options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions>
82+
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
11083
): Promise<RelayNode> {
11184
const libp2pOptions = options?.libp2p ?? {};
11285
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
@@ -138,7 +111,7 @@ export async function createRelayNode(
138111
* @internal
139112
*/
140113
export async function createFullNode(
141-
options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions>
114+
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
142115
): Promise<FullNode> {
143116
const libp2pOptions = options?.libp2p ?? {};
144117
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];

packages/interfaces/src/protocols.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { PeerId } from "@libp2p/interface-peer-id";
22
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
3+
import type { Libp2pOptions } from "libp2p";
34

45
import type { IMessage } from "./message.js";
56

@@ -19,7 +20,7 @@ export interface PointToPointProtocol {
1920

2021
export type ProtocolCreateOptions = {
2122
/**
22-
* The PubSub Topic to use. Defaults to {@link @waku/core/DefaultPubSubTopic }.
23+
* The PubSub Topic to use. Defaults to {@link @waku/core.DefaultPubSubTopic }.
2324
*
2425
* One and only one pubsub topic is used by Waku. This is used by:
2526
* - WakuRelay to receive, route and send messages,
@@ -31,11 +32,26 @@ export type ProtocolCreateOptions = {
3132
*
3233
*/
3334
pubSubTopic?: string;
35+
/**
36+
* You can pass options to the `Libp2p` instance used by {@link @waku/core.WakuNode} using the `libp2p` property.
37+
* 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)
38+
* apart that we made the `modules` property optional and partial,
39+
* allowing its omission and letting Waku set good defaults.
40+
* Notes that some values are overridden by {@link @waku/core.WakuNode} to ensure it implements the Waku protocol.
41+
*/
42+
libp2p?: Partial<Libp2pOptions>;
43+
/**
44+
* Byte array used as key for the noise protocol used for connection encryption
45+
* by [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
46+
* This is only used for test purposes to not run out of entropy during CI runs.
47+
*/
48+
staticNoiseKey?: Uint8Array;
49+
/**
50+
* Use recommended bootstrap method to discovery and connect to new nodes.
51+
*/
52+
defaultBootstrap?: boolean;
3453
};
3554

36-
//TODO
37-
// we can probably move `peerId` into `ProtocolCreateOptions` and remove `ProtocolOptions` and pass it in the constructor
38-
// however, filter protocol can use multiple peers, so we need to think about this
3955
export type ProtocolOptions = {
4056
/**
4157
* Optionally specify an PeerId for the protocol request. If not included, will use a random peer.

packages/message-encryption/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- `createEncoder` now take an object of type `EncoderOptions` instead of `contentTopic` and `ephemeral`
13+
- For Ecies, `createEncoder` now take an object of type `EncoderOptions` instead of `contentTopic`, `ephemeral`, `publicKey` and `sigPrivKey`
14+
- For Symmetric, `createEncoder` now take an object of type `EncoderOptions` instead of `contentTopic`, `ephemeral`, `symKey` and `sigPrivKey`
15+
1016
## [0.0.9] - 2023-01-25
1117

1218
### Fixed

packages/message-encryption/src/ecies.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
22
import type {
3-
EncoderOptions,
3+
EncoderOptions as BaseEncoderOptions,
44
IDecoder,
55
IEncoder,
66
IMessage,
@@ -64,7 +64,7 @@ export class Encoder implements IEncoder {
6464
}
6565
}
6666

67-
export interface EciesEncoderOptions extends EncoderOptions {
67+
export interface EncoderOptions extends BaseEncoderOptions {
6868
/** The public key to encrypt the payload for. */
6969
publicKey: Uint8Array;
7070
/** An optional private key to be used to sign the payload before encryption. */
@@ -88,7 +88,7 @@ export function createEncoder({
8888
publicKey,
8989
sigPrivKey,
9090
ephemeral = false,
91-
}: EciesEncoderOptions): Encoder {
91+
}: EncoderOptions): Encoder {
9292
return new Encoder(contentTopic, publicKey, sigPrivKey, ephemeral);
9393
}
9494

packages/message-encryption/src/symmetric.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
22
import type {
3-
EncoderOptions,
3+
EncoderOptions as BaseEncoderOptions,
44
IDecoder,
55
IEncoder,
66
IMessage,
@@ -62,7 +62,7 @@ export class Encoder implements IEncoder {
6262
}
6363
}
6464

65-
export interface SymmetricEncoderOptions extends EncoderOptions {
65+
export interface EncoderOptions extends BaseEncoderOptions {
6666
/** The symmetric key to encrypt the payload with. */
6767
symKey: Uint8Array;
6868
/** An optional private key to be used to sign the payload before encryption. */
@@ -87,7 +87,7 @@ export function createEncoder({
8787
symKey,
8888
sigPrivKey,
8989
ephemeral = false,
90-
}: SymmetricEncoderOptions): Encoder {
90+
}: EncoderOptions): Encoder {
9191
return new Encoder(contentTopic, symKey, sigPrivKey, ephemeral);
9292
}
9393

0 commit comments

Comments
 (0)