Merge pull request #1054 from waku-org/feat/protocol-interfaces

This commit is contained in:
fryorcraken.eth 2022-12-13 11:07:32 +11:00 committed by GitHub
commit 2ff4ac16ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 207 additions and 166 deletions

View File

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `waitForRemotePeer` must now be directly imported from `@waku/core`. - `waitForRemotePeer` must now be directly imported from `@waku/core`.
- `V0` suffix removed from the version 0 objects. - `V0` suffix removed from the version 0 objects.
- `createEncoder`/`createDecoder`/`DecodedMessage` for Waku Message Version 0 (no Waku level encryption) can now be imported directly from `@waku/core`. - `createEncoder`/`createDecoder`/`DecodedMessage` for Waku Message Version 0 (no Waku level encryption) can now be imported directly from `@waku/core`.
- Removed `Waku` and `waku_` prefixed on protocol implementations.
## [@waku/core@0.0.6] - 2022-11-18 ## [@waku/core@0.0.6] - 2022-11-18

View File

@ -13,13 +13,13 @@
"types": "./dist/lib/predefined_bootstrap_nodes.d.ts", "types": "./dist/lib/predefined_bootstrap_nodes.d.ts",
"import": "./dist/lib/predefined_bootstrap_nodes.js" "import": "./dist/lib/predefined_bootstrap_nodes.js"
}, },
"./lib/waku_message/version_0": { "./lib/message/version_0": {
"types": "./dist/lib/waku_message/version_0.d.ts", "types": "./dist/lib/message/version_0.d.ts",
"import": "./dist/lib/waku_message/version_0.js" "import": "./dist/lib/message/version_0.js"
}, },
"./lib/waku_message/topic_only_message": { "./lib/message/topic_only_message": {
"types": "./dist/lib/waku_message/topic_only_message.d.ts", "types": "./dist/lib/message/topic_only_message.d.ts",
"import": "./dist/lib/waku_message/topic_only_message.js" "import": "./dist/lib/message/topic_only_message.js"
} }
}, },
"typesVersions": { "typesVersions": {

View File

@ -6,9 +6,8 @@ export default {
input: { input: {
index: "dist/index.js", index: "dist/index.js",
"lib/predefined_bootstrap_nodes": "dist/lib/predefined_bootstrap_nodes.js", "lib/predefined_bootstrap_nodes": "dist/lib/predefined_bootstrap_nodes.js",
"lib/waku_message/version_0": "dist/lib/waku_message/version_0.js", "lib/message/version_0": "dist/lib/message/version_0.js",
"lib/waku_message/topic_only_message": "lib/message/topic_only_message": "dist/lib/message/topic_only_message.js",
"dist/lib/waku_message/topic_only_message.js",
}, },
output: { output: {
dir: "bundle", dir: "bundle",

View File

@ -5,30 +5,30 @@ export {
createEncoder, createEncoder,
createDecoder, createDecoder,
DecodedMessage, DecodedMessage,
} from "./lib/waku_message/version_0.js"; } from "./lib/message/version_0.js";
export * as waku from "./lib/waku.js"; export * as waku from "./lib/waku.js";
export { WakuNode } from "./lib/waku.js"; export { WakuNode } from "./lib/waku.js";
export * as waku_filter from "./lib/waku_filter/index.js"; export * as waku_filter from "./lib/filter/index.js";
export { wakuFilter } from "./lib/waku_filter/index.js"; export { wakuFilter } from "./lib/filter/index.js";
export * as waku_light_push from "./lib/waku_light_push/index.js"; export * as waku_light_push from "./lib/light_push/index.js";
export { export {
wakuLightPush, wakuLightPush,
LightPushCodec, LightPushCodec,
PushResponse, PushResponse,
} from "./lib/waku_light_push/index.js"; } from "./lib/light_push/index.js";
export * as waku_relay from "./lib/waku_relay/index.js"; export * as waku_relay from "./lib/relay/index.js";
export { wakuRelay } from "./lib/waku_relay/index.js"; export { wakuRelay } from "./lib/relay/index.js";
export * as waku_store from "./lib/waku_store/index.js"; export * as waku_store from "./lib/store/index.js";
export { export {
PageDirection, PageDirection,
wakuStore, wakuStore,
StoreCodec, StoreCodec,
createCursor, createCursor,
} from "./lib/waku_store/index.js"; } from "./lib/store/index.js";
export { waitForRemotePeer } from "./lib/wait_for_remote_peer.js"; export { waitForRemotePeer } from "./lib/wait_for_remote_peer.js";

View File

@ -7,9 +7,9 @@ import type { IncomingStreamData } from "@libp2p/interface-registrar";
import type { Registrar } from "@libp2p/interface-registrar"; import type { Registrar } from "@libp2p/interface-registrar";
import type { import type {
Callback, Callback,
Filter,
IDecodedMessage, IDecodedMessage,
IDecoder, IDecoder,
IFilter,
IMessage, IMessage,
ProtocolOptions, ProtocolOptions,
} from "@waku/interfaces"; } from "@waku/interfaces";
@ -64,7 +64,7 @@ export type UnsubscribeFunction = () => Promise<void>;
* - https://github.com/status-im/go-waku/issues/245 * - https://github.com/status-im/go-waku/issues/245
* - https://github.com/status-im/nwaku/issues/948 * - https://github.com/status-im/nwaku/issues/948
*/ */
class WakuFilter implements Filter { class Filter implements IFilter {
pubSubTopic: string; pubSubTopic: string;
private subscriptions: Map<string, Callback<any>>; private subscriptions: Map<string, Callback<any>>;
private decoders: Map< private decoders: Map<
@ -308,6 +308,6 @@ class WakuFilter implements Filter {
export function wakuFilter( export function wakuFilter(
init: Partial<CreateOptions> = {} init: Partial<CreateOptions> = {}
): (components: FilterComponents) => Filter { ): (components: FilterComponents) => IFilter {
return (components: FilterComponents) => new WakuFilter(components, init); return (components: FilterComponents) => new Filter(components, init);
} }

View File

@ -4,8 +4,8 @@ import type { Peer } from "@libp2p/interface-peer-store";
import type { PeerStore } from "@libp2p/interface-peer-store"; import type { PeerStore } from "@libp2p/interface-peer-store";
import type { import type {
IEncoder, IEncoder,
ILightPush,
IMessage, IMessage,
LightPush,
ProtocolOptions, ProtocolOptions,
SendResult, SendResult,
} from "@waku/interfaces"; } from "@waku/interfaces";
@ -51,7 +51,7 @@ export interface CreateOptions {
/** /**
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/). * Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
*/ */
class WakuLightPush implements LightPush { class LightPush implements ILightPush {
pubSubTopic: string; pubSubTopic: string;
constructor(public components: LightPushComponents, options?: CreateOptions) { constructor(public components: LightPushComponents, options?: CreateOptions) {
@ -151,7 +151,6 @@ class WakuLightPush implements LightPush {
export function wakuLightPush( export function wakuLightPush(
init: Partial<CreateOptions> = {} init: Partial<CreateOptions> = {}
): (components: LightPushComponents) => LightPush { ): (components: LightPushComponents) => ILightPush {
return (components: LightPushComponents) => return (components: LightPushComponents) => new LightPush(components, init);
new WakuLightPush(components, init);
} }

View File

@ -11,15 +11,15 @@ import type {
IDecoder, IDecoder,
IEncoder, IEncoder,
IMessage, IMessage,
Relay, IRelay,
SendResult, SendResult,
} from "@waku/interfaces"; } from "@waku/interfaces";
import { IDecodedMessage } from "@waku/interfaces"; import { IDecodedMessage } from "@waku/interfaces";
import debug from "debug"; import debug from "debug";
import { DefaultPubSubTopic } from "../constants.js"; import { DefaultPubSubTopic } from "../constants.js";
import { TopicOnlyDecoder } from "../message/topic_only_message.js";
import { pushOrInitMapSet } from "../push_or_init_map.js"; import { pushOrInitMapSet } from "../push_or_init_map.js";
import { TopicOnlyDecoder } from "../waku_message/topic_only_message.js";
import * as constants from "./constants.js"; import * as constants from "./constants.js";
@ -53,7 +53,7 @@ export type CreateOptions = {
* *
* @implements {require('libp2p-interfaces/src/pubsub')} * @implements {require('libp2p-interfaces/src/pubsub')}
*/ */
class WakuRelay extends GossipSub implements Relay { class Relay extends GossipSub implements IRelay {
pubSubTopic: string; pubSubTopic: string;
defaultDecoder: IDecoder<IDecodedMessage>; defaultDecoder: IDecoder<IDecodedMessage>;
public static multicodec: string = constants.RelayCodecs[0]; public static multicodec: string = constants.RelayCodecs[0];
@ -185,10 +185,10 @@ class WakuRelay extends GossipSub implements Relay {
} }
} }
WakuRelay.multicodec = constants.RelayCodecs[constants.RelayCodecs.length - 1]; Relay.multicodec = constants.RelayCodecs[constants.RelayCodecs.length - 1];
export function wakuRelay( export function wakuRelay(
init: Partial<CreateOptions> = {} init: Partial<CreateOptions> = {}
): (components: GossipSubComponents) => Relay { ): (components: GossipSubComponents) => IRelay {
return (components: GossipSubComponents) => new WakuRelay(components, init); return (components: GossipSubComponents) => new Relay(components, init);
} }

View File

@ -9,7 +9,7 @@ import {
IDecodedMessage, IDecodedMessage,
IDecoder, IDecoder,
Index, Index,
Store, IStore,
} from "@waku/interfaces"; } from "@waku/interfaces";
import { import {
getPeersForProtocol, getPeersForProtocol,
@ -104,7 +104,7 @@ export interface QueryOptions {
* *
* The Waku Store protocol can be used to retrieved historical messages. * The Waku Store protocol can be used to retrieved historical messages.
*/ */
class WakuStore implements Store { class Store implements IStore {
pubSubTopic: string; pubSubTopic: string;
constructor(public components: StoreComponents, options?: CreateOptions) { constructor(public components: StoreComponents, options?: CreateOptions) {
@ -432,6 +432,6 @@ export async function createCursor(
export function wakuStore( export function wakuStore(
init: Partial<CreateOptions> = {} init: Partial<CreateOptions> = {}
): (components: StoreComponents) => Store { ): (components: StoreComponents) => IStore {
return (components: StoreComponents) => new WakuStore(components, init); return (components: StoreComponents) => new Store(components, init);
} }

View File

@ -1,13 +1,13 @@
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store"; import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
import type { PointToPointProtocol, Relay, Waku } from "@waku/interfaces"; import type { IRelay, PointToPointProtocol, Waku } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { PeerExchangeCodec } from "@waku/peer-exchange"; import { PeerExchangeCodec } from "@waku/peer-exchange";
import debug from "debug"; import debug from "debug";
import { pEvent } from "p-event"; import { pEvent } from "p-event";
import { FilterCodec } from "./waku_filter/index.js"; import { FilterCodec } from "./filter/index.js";
import { LightPushCodec } from "./waku_light_push/index.js"; import { LightPushCodec } from "./light_push/index.js";
import { StoreCodec } from "./waku_store/index.js"; import { StoreCodec } from "./store/index.js";
const log = debug("waku:wait-for-remote-peer"); const log = debug("waku:wait-for-remote-peer");
@ -117,7 +117,7 @@ async function waitForConnectedPeer(
* Wait for a peer with the given protocol to be connected and in the gossipsub * Wait for a peer with the given protocol to be connected and in the gossipsub
* mesh. * mesh.
*/ */
async function waitForGossipSubPeerInMesh(waku: Relay): Promise<void> { async function waitForGossipSubPeerInMesh(waku: IRelay): Promise<void> {
let peers = waku.getMeshPeers(); let peers = waku.getMeshPeers();
while (peers.length == 0) { while (peers.length == 0) {

View File

@ -3,12 +3,12 @@ import type { PeerId } from "@libp2p/interface-peer-id";
import type { PubSub } from "@libp2p/interface-pubsub"; import type { PubSub } from "@libp2p/interface-pubsub";
import type { Multiaddr } from "@multiformats/multiaddr"; import type { Multiaddr } from "@multiformats/multiaddr";
import type { import type {
Filter, IFilter,
LightPush, ILightPush,
PeerExchange, IPeerExchange,
IRelay,
IStore,
PeerExchangeComponents, PeerExchangeComponents,
Relay,
Store,
Waku, Waku,
} from "@waku/interfaces"; } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
@ -16,15 +16,12 @@ import { PeerExchangeCodec } from "@waku/peer-exchange";
import debug from "debug"; import debug from "debug";
import type { Libp2p } from "libp2p"; import type { Libp2p } from "libp2p";
import { FilterCodec, FilterComponents } from "./waku_filter/index.js"; import { FilterCodec, FilterComponents } from "./filter/index.js";
import { import { LightPushCodec, LightPushComponents } from "./light_push/index.js";
LightPushCodec, import { createEncoder } from "./message/version_0.js";
LightPushComponents, import * as relayConstants from "./relay/constants.js";
} from "./waku_light_push/index.js"; import { RelayCodecs, RelayPingContentTopic } from "./relay/constants.js";
import { createEncoder } from "./waku_message/version_0.js"; import { StoreCodec, StoreComponents } from "./store/index.js";
import * as relayConstants from "./waku_relay/constants.js";
import { RelayCodecs, RelayPingContentTopic } from "./waku_relay/constants.js";
import { StoreCodec, StoreComponents } from "./waku_store/index.js";
export const DefaultPingKeepAliveValueSecs = 0; export const DefaultPingKeepAliveValueSecs = 0;
export const DefaultRelayKeepAliveValueSecs = 5 * 60; export const DefaultRelayKeepAliveValueSecs = 5 * 60;
@ -56,11 +53,11 @@ export interface WakuOptions {
export class WakuNode implements Waku { export class WakuNode implements Waku {
public libp2p: Libp2p; public libp2p: Libp2p;
public relay?: Relay; public relay?: IRelay;
public store?: Store; public store?: IStore;
public filter?: Filter; public filter?: IFilter;
public lightPush?: LightPush; public lightPush?: ILightPush;
public peerExchange?: PeerExchange; public peerExchange?: IPeerExchange;
private pingKeepAliveTimers: { private pingKeepAliveTimers: {
[peer: string]: ReturnType<typeof setInterval>; [peer: string]: ReturnType<typeof setInterval>;
@ -72,10 +69,10 @@ export class WakuNode implements Waku {
constructor( constructor(
options: WakuOptions, options: WakuOptions,
libp2p: Libp2p, libp2p: Libp2p,
store?: (components: StoreComponents) => Store, store?: (components: StoreComponents) => IStore,
lightPush?: (components: LightPushComponents) => LightPush, lightPush?: (components: LightPushComponents) => ILightPush,
filter?: (components: FilterComponents) => Filter, filter?: (components: FilterComponents) => IFilter,
peerExchange?: (components: PeerExchangeComponents) => PeerExchange peerExchange?: (components: PeerExchangeComponents) => IPeerExchange
) { ) {
this.libp2p = libp2p; this.libp2p = libp2p;
@ -274,7 +271,7 @@ export class WakuNode implements Waku {
} }
} }
function isRelay(pubsub: PubSub): pubsub is Relay { function isRelay(pubsub: PubSub): pubsub is IRelay {
if (pubsub) { if (pubsub) {
try { try {
return pubsub.multicodecs.includes( return pubsub.multicodecs.includes(

View File

@ -0,0 +1,24 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- Renamed `createPrivacyNode` to `createRelayNode`.
## [0.0.4] - 2022-11-18
### Added
- Alpha version of `@waku/create`.
[unreleased]: https://github.com/waku-org/js-waku/compare/@waku/create@0.0.4...HEAD
[0.0.4]: https://github.com/waku-org/js-waku/compare/@waku/create@0.0.3...@waku/create@0.0.4
[0.0.3]: https://github.com/waku-org/js-waku/compare/@waku/create@0.0.2...%40waku/create@0.0.3
[0.0.2]: https://github.com/waku-org/js-waku/compare/@waku/create@0.0.1...%40waku/create@0.0.2
[0.0.1]: https://github.com/status-im/js-waku/compare/a20b7809d61ff9a9732aba82b99bbe99f229b935...%40waku/create%400.0.2

View File

@ -15,7 +15,7 @@ import {
} from "@waku/core"; } from "@waku/core";
import { DefaultUserAgent } from "@waku/core"; import { DefaultUserAgent } from "@waku/core";
import { getPredefinedBootstrapNodes } from "@waku/core/lib/predefined_bootstrap_nodes"; import { getPredefinedBootstrapNodes } from "@waku/core/lib/predefined_bootstrap_nodes";
import type { Relay, WakuFull, WakuLight, WakuPrivacy } from "@waku/interfaces"; import type { FullNode, IRelay, LightNode, 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";
@ -69,7 +69,7 @@ export interface CreateOptions {
*/ */
export async function createLightNode( export async function createLightNode(
options?: CreateOptions & WakuOptions options?: CreateOptions & WakuOptions
): Promise<WakuLight> { ): Promise<LightNode> {
const libp2pOptions = options?.libp2p ?? {}; const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? []; const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
if (options?.defaultBootstrap) { if (options?.defaultBootstrap) {
@ -95,16 +95,16 @@ export async function createLightNode(
lightPush, lightPush,
filter, filter,
peerExchange peerExchange
) as WakuLight; ) as LightNode;
} }
/** /**
* Create a Waku node that uses Waku Relay to send and receive messages, * Create a Waku node that uses Waku Relay to send and receive messages,
* enabling some privacy preserving properties. * enabling some privacy preserving properties.
*/ */
export async function createPrivacyNode( export async function createRelayNode(
options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions> options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions>
): Promise<WakuPrivacy> { ): Promise<RelayNode> {
const libp2pOptions = options?.libp2p ?? {}; const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? []; const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
if (options?.defaultBootstrap) { if (options?.defaultBootstrap) {
@ -118,7 +118,7 @@ export async function createPrivacyNode(
options?.userAgent options?.userAgent
); );
return new WakuNode(options ?? {}, libp2p) as WakuPrivacy; return new WakuNode(options ?? {}, libp2p) as RelayNode;
} }
/** /**
@ -136,7 +136,7 @@ export async function createPrivacyNode(
*/ */
export async function createFullNode( export async function createFullNode(
options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions> options?: CreateOptions & WakuOptions & Partial<RelayCreateOptions>
): Promise<WakuFull> { ): Promise<FullNode> {
const libp2pOptions = options?.libp2p ?? {}; const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? []; const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
if (options?.defaultBootstrap) { if (options?.defaultBootstrap) {
@ -162,7 +162,7 @@ export async function createFullNode(
lightPush, lightPush,
filter, filter,
peerExchange peerExchange
) as WakuFull; ) as FullNode;
} }
export function defaultPeerDiscovery(): ( export function defaultPeerDiscovery(): (
@ -172,7 +172,7 @@ export function defaultPeerDiscovery(): (
} }
export async function defaultLibp2p( export async function defaultLibp2p(
wakuRelay?: (components: Libp2pComponents) => Relay, wakuRelay?: (components: Libp2pComponents) => IRelay,
options?: Partial<Libp2pOptions>, options?: Partial<Libp2pOptions>,
userAgent?: string userAgent?: string
): Promise<Libp2p> { ): Promise<Libp2p> {

View File

@ -0,0 +1,27 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- Add `I` prefix to protocol and messages interfaces.
- Renamed node interfaces to include `Node`.
- Renamed `WakuPrivacy` to `RelayNode`.
## [0.0.5] - 2022-11-18
### Added
- Alpha version of `@waku/interfaces`.
[unreleased]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.5...HEAD
[0.0.5]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.4...@waku/interfaces@0.0.5
[0.0.4]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.3...@waku/interfaces@0.0.4
[0.0.3]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.2...%40waku/create@0.0.3
[0.0.2]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.1...%40waku/create@0.0.2
[0.0.1]: https://github.com/status-im/js-waku/compare/a20b7809d61ff9a9732aba82b99bbe99f229b935...%40waku/create%400.0.2

View File

@ -5,7 +5,7 @@ import type {
ProtocolOptions, ProtocolOptions,
} from "./protocols.js"; } from "./protocols.js";
export interface Filter extends PointToPointProtocol { export interface IFilter extends PointToPointProtocol {
subscribe: <T extends IDecodedMessage>( subscribe: <T extends IDecodedMessage>(
decoders: IDecoder<T>[], decoders: IDecoder<T>[],
callback: Callback<T>, callback: Callback<T>,

View File

@ -5,7 +5,7 @@ import type {
SendResult, SendResult,
} from "./protocols.js"; } from "./protocols.js";
export interface LightPush extends PointToPointProtocol { export interface ILightPush extends PointToPointProtocol {
push: ( push: (
encoder: IEncoder, encoder: IEncoder,
message: IMessage, message: IMessage,

View File

@ -5,7 +5,7 @@ import { ENR } from "@waku/enr";
import { PointToPointProtocol } from "./protocols.js"; import { PointToPointProtocol } from "./protocols.js";
export interface PeerExchange extends PointToPointProtocol { export interface IPeerExchange extends PointToPointProtocol {
query( query(
params: PeerExchangeQueryParams, params: PeerExchangeQueryParams,
callback: (response: PeerExchangeResponse) => Promise<void> | void callback: (response: PeerExchangeResponse) => Promise<void> | void

View File

@ -8,7 +8,7 @@ import type {
} from "./message.js"; } from "./message.js";
import type { Callback, SendResult } from "./protocols.js"; import type { Callback, SendResult } from "./protocols.js";
export interface Relay extends GossipSub { export interface IRelay extends GossipSub {
send: (encoder: IEncoder, message: IMessage) => Promise<SendResult>; send: (encoder: IEncoder, message: IMessage) => Promise<SendResult>;
addObserver: <T extends IDecodedMessage>( addObserver: <T extends IDecodedMessage>(
decoder: IDecoder<T>, decoder: IDecoder<T>,

View File

@ -50,7 +50,7 @@ export type StoreQueryOptions = {
cursor?: Cursor; cursor?: Cursor;
} & ProtocolOptions; } & ProtocolOptions;
export interface Store extends PointToPointProtocol { export interface IStore extends PointToPointProtocol {
queryOrderedCallback: <T extends IDecodedMessage>( queryOrderedCallback: <T extends IDecodedMessage>(
decoders: IDecoder<T>[], decoders: IDecoder<T>[],
callback: (message: T) => Promise<void | boolean> | boolean | void, callback: (message: T) => Promise<void | boolean> | boolean | void,

View File

@ -3,20 +3,20 @@ import type { PeerId } from "@libp2p/interface-peer-id";
import type { Multiaddr } from "@multiformats/multiaddr"; import type { Multiaddr } from "@multiformats/multiaddr";
import type { Libp2p } from "libp2p"; import type { Libp2p } from "libp2p";
import type { Filter } from "./filter.js"; import type { IFilter } from "./filter.js";
import type { LightPush } from "./light_push.js"; import type { ILightPush } from "./light_push.js";
import type { PeerExchange } from "./peer_exchange.js"; import type { IPeerExchange } from "./peer_exchange.js";
import { Protocols } from "./protocols.js"; import { Protocols } from "./protocols.js";
import type { Relay } from "./relay.js"; import type { IRelay } from "./relay.js";
import type { Store } from "./store.js"; import type { IStore } from "./store.js";
export interface Waku { export interface Waku {
libp2p: Libp2p; libp2p: Libp2p;
relay?: Relay; relay?: IRelay;
store?: Store; store?: IStore;
filter?: Filter; filter?: IFilter;
lightPush?: LightPush; lightPush?: ILightPush;
peerExchange?: PeerExchange; peerExchange?: IPeerExchange;
dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>; dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
@ -27,26 +27,26 @@ export interface Waku {
isStarted(): boolean; isStarted(): boolean;
} }
export interface WakuLight extends Waku { export interface LightNode extends Waku {
relay: undefined; relay: undefined;
store: Store; store: IStore;
filter: Filter; filter: IFilter;
lightPush: LightPush; lightPush: ILightPush;
peerExchange: PeerExchange; peerExchange: IPeerExchange;
} }
export interface WakuPrivacy extends Waku { export interface RelayNode extends Waku {
relay: Relay; relay: IRelay;
store: undefined; store: undefined;
filter: undefined; filter: undefined;
lightPush: undefined; lightPush: undefined;
peerExchange: undefined; peerExchange: undefined;
} }
export interface WakuFull extends Waku { export interface FullNode extends Waku {
relay: Relay; relay: IRelay;
store: Store; store: IStore;
filter: Filter; filter: IFilter;
lightPush: LightPush; lightPush: ILightPush;
peerExchange: PeerExchange; peerExchange: IPeerExchange;
} }

View File

@ -1,7 +1,4 @@
import { import { Decoder as DecoderV0, proto } from "@waku/core/lib/message/version_0";
Decoder as DecoderV0,
proto,
} from "@waku/core/lib/waku_message/version_0";
import type { import type {
IDecoder, IDecoder,
IEncoder, IEncoder,

View File

@ -1,7 +1,7 @@
import { import {
DecodedMessage as DecodedMessageV0, DecodedMessage as DecodedMessageV0,
proto, proto,
} from "@waku/core/lib/waku_message/version_0"; } from "@waku/core/lib/message/version_0";
import type { IDecodedMessage } from "@waku/interfaces"; import type { IDecodedMessage } from "@waku/interfaces";
import { import {

View File

@ -1,7 +1,4 @@
import { import { Decoder as DecoderV0, proto } from "@waku/core/lib/message/version_0";
Decoder as DecoderV0,
proto,
} from "@waku/core/lib/waku_message/version_0";
import type { import type {
IDecoder, IDecoder,
IEncoder, IEncoder,

View File

@ -4,7 +4,7 @@ import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
import type { IncomingStreamData } from "@libp2p/interface-registrar"; import type { IncomingStreamData } from "@libp2p/interface-registrar";
import { ENR } from "@waku/enr"; import { ENR } from "@waku/enr";
import type { import type {
PeerExchange, IPeerExchange,
PeerExchangeComponents, PeerExchangeComponents,
PeerExchangeQueryParams, PeerExchangeQueryParams,
PeerExchangeResponse, PeerExchangeResponse,
@ -26,7 +26,7 @@ export const PeerExchangeCodec = "/vac/waku/peer-exchange/2.0.0-alpha1";
const log = debug("waku:peer-exchange"); const log = debug("waku:peer-exchange");
export class WakuPeerExchange implements PeerExchange { export class WakuPeerExchange implements IPeerExchange {
private callback: private callback:
| ((response: PeerExchangeResponse) => Promise<void>) | ((response: PeerExchangeResponse) => Promise<void>)
| undefined; | undefined;

View File

@ -1,14 +1,14 @@
import { waitForRemotePeer } from "@waku/core"; import { waitForRemotePeer } from "@waku/core";
import { createPrivacyNode } from "@waku/create"; import { createRelayNode } from "@waku/create";
import { ENR } from "@waku/enr"; import { ENR } from "@waku/enr";
import type { WakuPrivacy } from "@waku/interfaces"; import type { RelayNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../src/index.js"; import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../src/index.js";
describe("ENR Interop: nwaku", function () { describe("ENR Interop: nwaku", function () {
let waku: WakuPrivacy; let waku: RelayNode;
let nwaku: Nwaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {
@ -27,7 +27,7 @@ describe("ENR Interop: nwaku", function () {
}); });
const multiAddrWithId = await nwaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createPrivacyNode({ waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.start(); await waku.start();
@ -59,7 +59,7 @@ describe("ENR Interop: nwaku", function () {
}); });
const multiAddrWithId = await nwaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createPrivacyNode({ waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.start(); await waku.start();
@ -91,7 +91,7 @@ describe("ENR Interop: nwaku", function () {
}); });
const multiAddrWithId = await nwaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createPrivacyNode({ waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.start(); await waku.start();

View File

@ -7,7 +7,7 @@ import {
} from "@waku/core"; } from "@waku/core";
import { createLightNode } from "@waku/create"; import { createLightNode } from "@waku/create";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import type { WakuLight } from "@waku/interfaces"; import type { LightNode } from "@waku/interfaces";
import { import {
createDecoder as eciesDecoder, createDecoder as eciesDecoder,
createEncoder as eciesEncoder, createEncoder as eciesEncoder,
@ -37,7 +37,7 @@ const TestEncoder = createEncoder(TestContentTopic);
const TestDecoder = createDecoder(TestContentTopic); const TestDecoder = createDecoder(TestContentTopic);
describe("Waku Message Ephemeral field", () => { describe("Waku Message Ephemeral field", () => {
let waku: WakuLight; let waku: LightNode;
let nwaku: Nwaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {

View File

@ -6,7 +6,7 @@ import {
waitForRemotePeer, waitForRemotePeer,
} from "@waku/core"; } from "@waku/core";
import { createLightNode } from "@waku/create"; import { createLightNode } from "@waku/create";
import type { WakuLight } from "@waku/interfaces"; import type { LightNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import debug from "debug"; import debug from "debug";
@ -20,7 +20,7 @@ const TestEncoder = createEncoder(TestContentTopic);
const TestDecoder = createDecoder(TestContentTopic); const TestDecoder = createDecoder(TestContentTopic);
describe("Waku Filter", () => { describe("Waku Filter", () => {
let waku: WakuLight; let waku: LightNode;
let nwaku: Nwaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {

View File

@ -1,7 +1,7 @@
import { bytesToUtf8, utf8ToBytes } from "@waku/byte-utils"; import { bytesToUtf8, utf8ToBytes } from "@waku/byte-utils";
import { createEncoder, waitForRemotePeer } from "@waku/core"; import { createEncoder, waitForRemotePeer } from "@waku/core";
import { createLightNode } from "@waku/create"; import { createLightNode } from "@waku/create";
import type { WakuLight } from "@waku/interfaces"; import type { LightNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import debug from "debug"; import debug from "debug";
@ -20,7 +20,7 @@ const TestContentTopic = "/test/1/waku-light-push/utf8";
const TestEncoder = createEncoder(TestContentTopic); const TestEncoder = createEncoder(TestContentTopic);
describe("Waku Light Push [node only]", () => { describe("Waku Light Push [node only]", () => {
let waku: WakuLight; let waku: LightNode;
let nwaku: Nwaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {

View File

@ -5,12 +5,12 @@ import {
getPredefinedBootstrapNodes, getPredefinedBootstrapNodes,
} from "@waku/core/lib/predefined_bootstrap_nodes"; } from "@waku/core/lib/predefined_bootstrap_nodes";
import { createLightNode } from "@waku/create"; import { createLightNode } from "@waku/create";
import type { PeerExchangeResponse, WakuFull } from "@waku/interfaces"; import type { LightNode, PeerExchangeResponse } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
describe("Peer Exchange: Node", () => { describe("Peer Exchange: Node", () => {
let waku: WakuFull; let waku: LightNode;
afterEach(async function () { afterEach(async function () {
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });

View File

@ -7,8 +7,8 @@ import {
DefaultPubSubTopic, DefaultPubSubTopic,
waitForRemotePeer, waitForRemotePeer,
} from "@waku/core"; } from "@waku/core";
import { createPrivacyNode } from "@waku/create"; import { createRelayNode } from "@waku/create";
import type { WakuPrivacy } from "@waku/interfaces"; import type { RelayNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { import {
createDecoder as createEciesDecoder, createDecoder as createEciesDecoder,
@ -50,17 +50,17 @@ describe("Waku Relay [node only]", () => {
} }
}); });
let waku1: WakuPrivacy; let waku1: RelayNode;
let waku2: WakuPrivacy; let waku2: RelayNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(10000); this.timeout(10000);
log("Starting JS Waku instances"); log("Starting JS Waku instances");
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createPrivacyNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) => createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) =>
waku.start().then(() => waku) waku.start().then(() => waku)
), ),
createPrivacyNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }, libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
@ -250,9 +250,9 @@ describe("Waku Relay [node only]", () => {
}); });
describe("Custom pubsub topic", () => { describe("Custom pubsub topic", () => {
let waku1: WakuPrivacy; let waku1: RelayNode;
let waku2: WakuPrivacy; let waku2: RelayNode;
let waku3: WakuPrivacy; let waku3: RelayNode;
afterEach(async function () { afterEach(async function () {
!!waku1 && !!waku1 &&
waku1.stop().catch((e) => console.log("Waku failed to stop", e)); waku1.stop().catch((e) => console.log("Waku failed to stop", e));
@ -270,16 +270,16 @@ describe("Waku Relay [node only]", () => {
// 1 and 2 uses a custom pubsub // 1 and 2 uses a custom pubsub
// 3 uses the default pubsub // 3 uses the default pubsub
[waku1, waku2, waku3] = await Promise.all([ [waku1, waku2, waku3] = await Promise.all([
createPrivacyNode({ createRelayNode({
pubSubTopic: pubSubTopic, pubSubTopic: pubSubTopic,
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
createPrivacyNode({ createRelayNode({
pubSubTopic: pubSubTopic, pubSubTopic: pubSubTopic,
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }, libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
createPrivacyNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_3, staticNoiseKey: NOISE_KEY_3,
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
]); ]);
@ -331,12 +331,12 @@ describe("Waku Relay [node only]", () => {
}); });
describe("Interop: nwaku", function () { describe("Interop: nwaku", function () {
let waku: WakuPrivacy; let waku: RelayNode;
let nwaku: Nwaku; let nwaku: Nwaku;
beforeEach(async function () { beforeEach(async function () {
this.timeout(30_000); this.timeout(30_000);
waku = await createPrivacyNode({ waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku.start(); await waku.start();
@ -416,8 +416,8 @@ describe("Waku Relay [node only]", () => {
}); });
describe.skip("Two nodes connected to nwaku", function () { describe.skip("Two nodes connected to nwaku", function () {
let waku1: WakuPrivacy; let waku1: RelayNode;
let waku2: WakuPrivacy; let waku2: RelayNode;
let nwaku: Nwaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {
@ -431,11 +431,11 @@ describe("Waku Relay [node only]", () => {
it("Js publishes, other Js receives", async function () { it("Js publishes, other Js receives", async function () {
this.timeout(60_000); this.timeout(60_000);
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createPrivacyNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
emitSelf: true, emitSelf: true,
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
createPrivacyNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
]); ]);

View File

@ -7,7 +7,7 @@ import {
waitForRemotePeer, waitForRemotePeer,
} from "@waku/core"; } from "@waku/core";
import { createLightNode } from "@waku/create"; import { createLightNode } from "@waku/create";
import type { IDecodedMessage, IMessage, WakuLight } from "@waku/interfaces"; import type { IDecodedMessage, IMessage, LightNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { import {
createDecoder as createEciesDecoder, createDecoder as createEciesDecoder,
@ -38,7 +38,7 @@ const TestEncoder = createEncoder(TestContentTopic);
const TestDecoder = createDecoder(TestContentTopic); const TestDecoder = createDecoder(TestContentTopic);
describe("Waku Store", () => { describe("Waku Store", () => {
let waku: WakuLight; let waku: LightNode;
let nwaku: Nwaku; let nwaku: Nwaku;
beforeEach(async function () { beforeEach(async function () {
@ -559,7 +559,7 @@ describe("Waku Store", () => {
describe("Waku Store, custom pubsub topic", () => { describe("Waku Store, custom pubsub topic", () => {
const customPubSubTopic = "/waku/2/custom-dapp/proto"; const customPubSubTopic = "/waku/2/custom-dapp/proto";
let waku: WakuLight; let waku: LightNode;
let nwaku: Nwaku; let nwaku: Nwaku;
beforeEach(async function () { beforeEach(async function () {

View File

@ -1,14 +1,14 @@
import { waitForRemotePeer } from "@waku/core"; import { waitForRemotePeer } from "@waku/core";
import { createLightNode, createPrivacyNode } from "@waku/create"; import { createLightNode, createRelayNode } from "@waku/create";
import type { WakuLight, WakuPrivacy } from "@waku/interfaces"; import type { LightNode, RelayNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { delay, makeLogFileName, NOISE_KEY_1, Nwaku } from "../src/index.js"; import { delay, makeLogFileName, NOISE_KEY_1, Nwaku } from "../src/index.js";
describe("Wait for remote peer", function () { describe("Wait for remote peer", function () {
let waku1: WakuPrivacy; let waku1: RelayNode;
let waku2: WakuLight; let waku2: LightNode;
let nwaku: Nwaku | undefined; let nwaku: Nwaku | undefined;
afterEach(async function () { afterEach(async function () {
@ -31,7 +31,7 @@ describe("Wait for remote peer", function () {
}); });
const multiAddrWithId = await nwaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku1 = await createPrivacyNode({ waku1 = await createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku1.start(); await waku1.start();
@ -56,7 +56,7 @@ describe("Wait for remote peer", function () {
}); });
const multiAddrWithId = await nwaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku1 = await createPrivacyNode({ waku1 = await createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku1.start(); await waku1.start();
@ -75,7 +75,7 @@ describe("Wait for remote peer", function () {
it("Relay - times out", function (done) { it("Relay - times out", function (done) {
this.timeout(5000); this.timeout(5000);
createPrivacyNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}) })
.then((waku1) => waku1.start().then(() => waku1)) .then((waku1) => waku1.start().then(() => waku1))
@ -253,7 +253,7 @@ describe("Wait for remote peer", function () {
}); });
const multiAddrWithId = await nwaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku1 = await createPrivacyNode({ waku1 = await createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
}); });
await waku1.start(); await waku1.start();

View File

@ -6,8 +6,8 @@ import {
DefaultUserAgent, DefaultUserAgent,
waitForRemotePeer, waitForRemotePeer,
} from "@waku/core"; } from "@waku/core";
import { createLightNode, createPrivacyNode } from "@waku/create"; import { createLightNode, createRelayNode } from "@waku/create";
import type { Waku, WakuLight, WakuPrivacy } from "@waku/interfaces"; import type { LightNode, RelayNode, Waku } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { import {
createDecoder, createDecoder,
@ -62,7 +62,7 @@ describe("Waku Dial [node only]", function () {
}); });
describe("Bootstrap", function () { describe("Bootstrap", function () {
let waku: WakuLight; let waku: LightNode;
let nwaku: Nwaku; let nwaku: Nwaku;
afterEach(async function () { afterEach(async function () {
@ -134,15 +134,15 @@ describe("Decryption Keys", () => {
} }
}); });
let waku1: WakuPrivacy; let waku1: RelayNode;
let waku2: WakuPrivacy; let waku2: RelayNode;
beforeEach(async function () { beforeEach(async function () {
this.timeout(5000); this.timeout(5000);
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createPrivacyNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) => createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) =>
waku.start().then(() => waku) waku.start().then(() => waku)
), ),
createPrivacyNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }, libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
@ -210,11 +210,11 @@ describe("User Agent", () => {
const waku1UserAgent = "test-user-agent"; const waku1UserAgent = "test-user-agent";
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createPrivacyNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_1, staticNoiseKey: NOISE_KEY_1,
userAgent: waku1UserAgent, userAgent: waku1UserAgent,
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),
createPrivacyNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }, libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
}).then((waku) => waku.start().then(() => waku)), }).then((waku) => waku.start().then(() => waku)),