2022-12-05 17:00:24 +11:00
|
|
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
|
|
|
|
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
|
2023-02-09 13:15:23 +05:30
|
|
|
import type { Libp2pOptions } from "libp2p";
|
2022-12-05 17:00:24 +11:00
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
import type { IMessage } from "./message.js";
|
2022-12-05 17:00:24 +11:00
|
|
|
|
|
|
|
|
export enum Protocols {
|
|
|
|
|
Relay = "relay",
|
|
|
|
|
Store = "store",
|
|
|
|
|
LightPush = "lightpush",
|
|
|
|
|
Filter = "filter",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface PointToPointProtocol {
|
2023-01-25 16:36:30 +11:00
|
|
|
multicodec: string;
|
2022-12-05 17:00:24 +11:00
|
|
|
peerStore: PeerStore;
|
|
|
|
|
peers: () => Promise<Peer[]>;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 08:02:06 +05:30
|
|
|
export type ProtocolCreateOptions = {
|
|
|
|
|
/**
|
2023-02-09 13:15:23 +05:30
|
|
|
* The PubSub Topic to use. Defaults to {@link @waku/core.DefaultPubSubTopic }.
|
2023-02-02 08:02:06 +05:30
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2022-12-05 17:00:24 +11:00
|
|
|
pubSubTopic?: string;
|
2023-02-09 13:15:23 +05:30
|
|
|
/**
|
|
|
|
|
* 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;
|
2023-02-02 08:02:06 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type ProtocolOptions = {
|
2022-12-05 17:00:24 +11:00
|
|
|
/**
|
|
|
|
|
* Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
|
|
|
|
|
*/
|
|
|
|
|
peerId?: PeerId;
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
export type Callback<T extends IMessage> = (msg: T) => void | Promise<void>;
|
2022-12-05 17:00:24 +11:00
|
|
|
|
|
|
|
|
export interface SendResult {
|
|
|
|
|
recipients: PeerId[];
|
|
|
|
|
}
|