chore: update changelog & minor improvements (#1153)

* address comments from https://github.com/waku-org/js-waku/pull/1145

* fix: typedoc

* address comments in https://github.com/waku-org/js-waku/pull/1146#pullrequestreview-1286307508

- update changelog
- change naming for `EciesEncoderOptions` and
`SymmetricEncoderOptions`
This commit is contained in:
Danish Arora 2023-02-09 13:15:23 +05:30 committed by GitHub
parent 598c8d3b93
commit 3b4bc8b25b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 57 deletions

View File

@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Dependency on `@waku/peer-exchange`.
### Changed
- `Filter`, `LightPush` and `Store` classes now takes in `options` of type `ProtocolCreateOptions` as the second argument, instead of `pubSubTopic`
- `Relay` class now takes in `options` of type `Partial<RealyCreateOptions>` as the second argument, instead of `pubSubTopic`
## [@waku/core@0.0.10] - 2023-01-25
### Changed

View File

@ -40,7 +40,7 @@ export type RelayCreateOptions = ProtocolCreateOptions & GossipsubOpts;
* @implements {require('libp2p-interfaces/src/pubsub')}
*/
class Relay extends GossipSub implements IRelay {
options: Partial<RelayCreateOptions>;
private pubSubTopic: string;
defaultDecoder: IDecoder<IDecodedMessage>;
public static multicodec: string = constants.RelayCodecs[0];
@ -63,9 +63,9 @@ class Relay extends GossipSub implements IRelay {
super(components, options);
this.multicodecs = constants.RelayCodecs;
this.observers = new Map();
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
this.options = options ?? {};
this.observers = new Map();
// TODO: User might want to decide what decoder should be used (e.g. for RLN)
this.defaultDecoder = new TopicOnlyDecoder();
@ -79,24 +79,21 @@ class Relay extends GossipSub implements IRelay {
* @returns {void}
*/
public async start(): Promise<void> {
const { pubSubTopic = DefaultPubSubTopic } = this.options;
await super.start();
this.subscribe(pubSubTopic);
this.subscribe(this.pubSubTopic);
}
/**
* Send Waku message.
*/
public async send(encoder: IEncoder, message: IMessage): Promise<SendResult> {
const { pubSubTopic = DefaultPubSubTopic } = this.options;
const msg = await encoder.toWire(message);
if (!msg) {
log("Failed to encode message, aborting publish");
return { recipients: [] };
}
return this.publish(pubSubTopic, msg);
return this.publish(this.pubSubTopic, msg);
}
/**
@ -172,8 +169,7 @@ class Relay extends GossipSub implements IRelay {
}
getMeshPeers(topic?: TopicStr): PeerIdStr[] {
const { pubSubTopic = DefaultPubSubTopic } = this.options;
return super.getMeshPeers(topic ?? pubSubTopic);
return super.getMeshPeers(topic ?? this.pubSubTopic);
}
}

View File

@ -14,7 +14,13 @@ import {
} from "@waku/core";
import { DefaultUserAgent } from "@waku/core";
import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery";
import type { FullNode, IRelay, LightNode, RelayNode } from "@waku/interfaces";
import type {
FullNode,
IRelay,
LightNode,
ProtocolCreateOptions,
RelayNode,
} from "@waku/interfaces";
import { wakuPeerExchange } from "@waku/peer-exchange";
import type { Libp2p } from "libp2p";
import { createLibp2p, Libp2pOptions } from "libp2p";
@ -29,39 +35,6 @@ const DEFAULT_NODE_REQUIREMENTS = {
export { Libp2pComponents };
export interface CreateOptions {
/**
* The PubSub Topic to use.
*
* One and only one pubsub topic is used by Waku. This is used by:
* - WakuRelay to receive, route and send messages,
* - WakuLightPush to send messages,
* - WakuStore to retrieve messages.
*
* The usage of the default pubsub topic is recommended.
* See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
*/
pubSubTopic?: string;
/**
* You can pass options to the `Libp2p` instance used by {@link @waku/core.WakuNode} using the {@link CreateOptions.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)
* apart that we made the `modules` property optional and partial,
* allowing its omission and letting Waku set good defaults.
* Notes that some values are overridden by {@link @waku/core.WakuNode} to ensure it implements the Waku protocol.
*/
libp2p?: Partial<Libp2pOptions>;
/**
* Byte array used as key for the noise protocol used for connection encryption
* by [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
* This is only used for test purposes to not run out of entropy during CI runs.
*/
staticNoiseKey?: Uint8Array;
/**
* Use recommended bootstrap method to discovery and connect to new nodes.
*/
defaultBootstrap?: boolean;
}
/**
* Create a Waku node that uses Waku Light Push, Filter and Store to send and
* receive messages, enabling low resource consumption.
@ -70,7 +43,7 @@ export interface CreateOptions {
* @see https://github.com/status-im/nwaku/issues/1085
*/
export async function createLightNode(
options?: CreateOptions & WakuOptions
options?: ProtocolCreateOptions & WakuOptions
): Promise<LightNode> {
const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
@ -106,7 +79,7 @@ export async function createLightNode(
* enabling some privacy preserving properties.
*/
export async function createRelayNode(
options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions>
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
): Promise<RelayNode> {
const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
@ -138,7 +111,7 @@ export async function createRelayNode(
* @internal
*/
export async function createFullNode(
options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions>
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
): Promise<FullNode> {
const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];

View File

@ -1,5 +1,6 @@
import type { PeerId } from "@libp2p/interface-peer-id";
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
import type { Libp2pOptions } from "libp2p";
import type { IMessage } from "./message.js";
@ -19,7 +20,7 @@ export interface PointToPointProtocol {
export type ProtocolCreateOptions = {
/**
* The PubSub Topic to use. Defaults to {@link @waku/core/DefaultPubSubTopic }.
* The PubSub Topic to use. Defaults to {@link @waku/core.DefaultPubSubTopic }.
*
* One and only one pubsub topic is used by Waku. This is used by:
* - WakuRelay to receive, route and send messages,
@ -31,11 +32,26 @@ export type ProtocolCreateOptions = {
*
*/
pubSubTopic?: string;
/**
* 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)
* apart that we made the `modules` property optional and partial,
* allowing its omission and letting Waku set good defaults.
* Notes that some values are overridden by {@link @waku/core.WakuNode} to ensure it implements the Waku protocol.
*/
libp2p?: Partial<Libp2pOptions>;
/**
* Byte array used as key for the noise protocol used for connection encryption
* by [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
* This is only used for test purposes to not run out of entropy during CI runs.
*/
staticNoiseKey?: Uint8Array;
/**
* Use recommended bootstrap method to discovery and connect to new nodes.
*/
defaultBootstrap?: boolean;
};
//TODO
// we can probably move `peerId` into `ProtocolCreateOptions` and remove `ProtocolOptions` and pass it in the constructor
// however, filter protocol can use multiple peers, so we need to think about this
export type ProtocolOptions = {
/**
* Optionally specify an PeerId for the protocol request. If not included, will use a random peer.

View File

@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- `createEncoder` now take an object of type `EncoderOptions` instead of `contentTopic` and `ephemeral`
- For Ecies, `createEncoder` now take an object of type `EncoderOptions` instead of `contentTopic`, `ephemeral`, `publicKey` and `sigPrivKey`
- For Symmetric, `createEncoder` now take an object of type `EncoderOptions` instead of `contentTopic`, `ephemeral`, `symKey` and `sigPrivKey`
## [0.0.9] - 2023-01-25
### Fixed

View File

@ -1,6 +1,6 @@
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
import type {
EncoderOptions,
EncoderOptions as BaseEncoderOptions,
IDecoder,
IEncoder,
IMessage,
@ -64,7 +64,7 @@ export class Encoder implements IEncoder {
}
}
export interface EciesEncoderOptions extends EncoderOptions {
export interface EncoderOptions extends BaseEncoderOptions {
/** The public key to encrypt the payload for. */
publicKey: Uint8Array;
/** An optional private key to be used to sign the payload before encryption. */
@ -88,7 +88,7 @@ export function createEncoder({
publicKey,
sigPrivKey,
ephemeral = false,
}: EciesEncoderOptions): Encoder {
}: EncoderOptions): Encoder {
return new Encoder(contentTopic, publicKey, sigPrivKey, ephemeral);
}

View File

@ -1,6 +1,6 @@
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
import type {
EncoderOptions,
EncoderOptions as BaseEncoderOptions,
IDecoder,
IEncoder,
IMessage,
@ -62,7 +62,7 @@ export class Encoder implements IEncoder {
}
}
export interface SymmetricEncoderOptions extends EncoderOptions {
export interface EncoderOptions extends BaseEncoderOptions {
/** The symmetric key to encrypt the payload with. */
symKey: Uint8Array;
/** An optional private key to be used to sign the payload before encryption. */
@ -87,7 +87,7 @@ export function createEncoder({
symKey,
sigPrivKey,
ephemeral = false,
}: SymmetricEncoderOptions): Encoder {
}: EncoderOptions): Encoder {
return new Encoder(contentTopic, symKey, sigPrivKey, ephemeral);
}