mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-23 01:28:16 +00:00
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:
parent
598c8d3b93
commit
3b4bc8b25b
@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- Dependency on `@waku/peer-exchange`.
|
- 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
|
## [@waku/core@0.0.10] - 2023-01-25
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -40,7 +40,7 @@ export type RelayCreateOptions = ProtocolCreateOptions & GossipsubOpts;
|
|||||||
* @implements {require('libp2p-interfaces/src/pubsub')}
|
* @implements {require('libp2p-interfaces/src/pubsub')}
|
||||||
*/
|
*/
|
||||||
class Relay extends GossipSub implements IRelay {
|
class Relay extends GossipSub implements IRelay {
|
||||||
options: Partial<RelayCreateOptions>;
|
private pubSubTopic: string;
|
||||||
defaultDecoder: IDecoder<IDecodedMessage>;
|
defaultDecoder: IDecoder<IDecodedMessage>;
|
||||||
public static multicodec: string = constants.RelayCodecs[0];
|
public static multicodec: string = constants.RelayCodecs[0];
|
||||||
|
|
||||||
@ -63,9 +63,9 @@ class Relay extends GossipSub implements IRelay {
|
|||||||
super(components, options);
|
super(components, options);
|
||||||
this.multicodecs = constants.RelayCodecs;
|
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)
|
// TODO: User might want to decide what decoder should be used (e.g. for RLN)
|
||||||
this.defaultDecoder = new TopicOnlyDecoder();
|
this.defaultDecoder = new TopicOnlyDecoder();
|
||||||
@ -79,24 +79,21 @@ class Relay extends GossipSub implements IRelay {
|
|||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
public async start(): Promise<void> {
|
public async start(): Promise<void> {
|
||||||
const { pubSubTopic = DefaultPubSubTopic } = this.options;
|
|
||||||
await super.start();
|
await super.start();
|
||||||
this.subscribe(pubSubTopic);
|
this.subscribe(this.pubSubTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send Waku message.
|
* Send Waku message.
|
||||||
*/
|
*/
|
||||||
public async send(encoder: IEncoder, message: IMessage): Promise<SendResult> {
|
public async send(encoder: IEncoder, message: IMessage): Promise<SendResult> {
|
||||||
const { pubSubTopic = DefaultPubSubTopic } = this.options;
|
|
||||||
|
|
||||||
const msg = await encoder.toWire(message);
|
const msg = await encoder.toWire(message);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
log("Failed to encode message, aborting publish");
|
log("Failed to encode message, aborting publish");
|
||||||
return { recipients: [] };
|
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[] {
|
getMeshPeers(topic?: TopicStr): PeerIdStr[] {
|
||||||
const { pubSubTopic = DefaultPubSubTopic } = this.options;
|
return super.getMeshPeers(topic ?? this.pubSubTopic);
|
||||||
return super.getMeshPeers(topic ?? pubSubTopic);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,13 @@ import {
|
|||||||
} from "@waku/core";
|
} from "@waku/core";
|
||||||
import { DefaultUserAgent } from "@waku/core";
|
import { DefaultUserAgent } from "@waku/core";
|
||||||
import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery";
|
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 { wakuPeerExchange } from "@waku/peer-exchange";
|
||||||
import type { Libp2p } from "libp2p";
|
import type { Libp2p } from "libp2p";
|
||||||
import { createLibp2p, Libp2pOptions } from "libp2p";
|
import { createLibp2p, Libp2pOptions } from "libp2p";
|
||||||
@ -29,39 +35,6 @@ const DEFAULT_NODE_REQUIREMENTS = {
|
|||||||
|
|
||||||
export { Libp2pComponents };
|
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
|
* Create a Waku node that uses Waku Light Push, Filter and Store to send and
|
||||||
* receive messages, enabling low resource consumption.
|
* receive messages, enabling low resource consumption.
|
||||||
@ -70,7 +43,7 @@ export interface CreateOptions {
|
|||||||
* @see https://github.com/status-im/nwaku/issues/1085
|
* @see https://github.com/status-im/nwaku/issues/1085
|
||||||
*/
|
*/
|
||||||
export async function createLightNode(
|
export async function createLightNode(
|
||||||
options?: CreateOptions & WakuOptions
|
options?: ProtocolCreateOptions & WakuOptions
|
||||||
): Promise<LightNode> {
|
): Promise<LightNode> {
|
||||||
const libp2pOptions = options?.libp2p ?? {};
|
const libp2pOptions = options?.libp2p ?? {};
|
||||||
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
|
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
|
||||||
@ -106,7 +79,7 @@ export async function createLightNode(
|
|||||||
* enabling some privacy preserving properties.
|
* enabling some privacy preserving properties.
|
||||||
*/
|
*/
|
||||||
export async function createRelayNode(
|
export async function createRelayNode(
|
||||||
options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions>
|
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
|
||||||
): Promise<RelayNode> {
|
): Promise<RelayNode> {
|
||||||
const libp2pOptions = options?.libp2p ?? {};
|
const libp2pOptions = options?.libp2p ?? {};
|
||||||
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
|
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
|
||||||
@ -138,7 +111,7 @@ export async function createRelayNode(
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export async function createFullNode(
|
export async function createFullNode(
|
||||||
options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions>
|
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
|
||||||
): Promise<FullNode> {
|
): Promise<FullNode> {
|
||||||
const libp2pOptions = options?.libp2p ?? {};
|
const libp2pOptions = options?.libp2p ?? {};
|
||||||
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
|
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import type { PeerId } from "@libp2p/interface-peer-id";
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
|
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
|
||||||
|
import type { Libp2pOptions } from "libp2p";
|
||||||
|
|
||||||
import type { IMessage } from "./message.js";
|
import type { IMessage } from "./message.js";
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ export interface PointToPointProtocol {
|
|||||||
|
|
||||||
export type ProtocolCreateOptions = {
|
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:
|
* One and only one pubsub topic is used by Waku. This is used by:
|
||||||
* - WakuRelay to receive, route and send messages,
|
* - WakuRelay to receive, route and send messages,
|
||||||
@ -31,11 +32,26 @@ export type ProtocolCreateOptions = {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
pubSubTopic?: string;
|
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 = {
|
export type ProtocolOptions = {
|
||||||
/**
|
/**
|
||||||
* Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
|
* Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
|
||||||
|
@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [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
|
## [0.0.9] - 2023-01-25
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
||||||
import type {
|
import type {
|
||||||
EncoderOptions,
|
EncoderOptions as BaseEncoderOptions,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
IEncoder,
|
IEncoder,
|
||||||
IMessage,
|
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. */
|
/** The public key to encrypt the payload for. */
|
||||||
publicKey: Uint8Array;
|
publicKey: Uint8Array;
|
||||||
/** An optional private key to be used to sign the payload before encryption. */
|
/** An optional private key to be used to sign the payload before encryption. */
|
||||||
@ -88,7 +88,7 @@ export function createEncoder({
|
|||||||
publicKey,
|
publicKey,
|
||||||
sigPrivKey,
|
sigPrivKey,
|
||||||
ephemeral = false,
|
ephemeral = false,
|
||||||
}: EciesEncoderOptions): Encoder {
|
}: EncoderOptions): Encoder {
|
||||||
return new Encoder(contentTopic, publicKey, sigPrivKey, ephemeral);
|
return new Encoder(contentTopic, publicKey, sigPrivKey, ephemeral);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
||||||
import type {
|
import type {
|
||||||
EncoderOptions,
|
EncoderOptions as BaseEncoderOptions,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
IEncoder,
|
IEncoder,
|
||||||
IMessage,
|
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. */
|
/** The symmetric key to encrypt the payload with. */
|
||||||
symKey: Uint8Array;
|
symKey: Uint8Array;
|
||||||
/** An optional private key to be used to sign the payload before encryption. */
|
/** An optional private key to be used to sign the payload before encryption. */
|
||||||
@ -87,7 +87,7 @@ export function createEncoder({
|
|||||||
symKey,
|
symKey,
|
||||||
sigPrivKey,
|
sigPrivKey,
|
||||||
ephemeral = false,
|
ephemeral = false,
|
||||||
}: SymmetricEncoderOptions): Encoder {
|
}: EncoderOptions): Encoder {
|
||||||
return new Encoder(contentTopic, symKey, sigPrivKey, ephemeral);
|
return new Encoder(contentTopic, symKey, sigPrivKey, ephemeral);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user