@waku/interfaces 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.0.6] - 2022-12-15
11
+
12
+ ### Changed
13
+
14
+ - Add `I` prefix to protocol and messages interfaces.
15
+ - Renamed node interfaces to include `Node`.
16
+ - Renamed `WakuPrivacy` to `RelayNode`.
17
+
18
+ ## [0.0.5] - 2022-11-18
19
+
20
+ ### Added
21
+
22
+ - Alpha version of `@waku/interfaces`.
23
+
24
+ [unreleased]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.6...HEAD
25
+ [0.0.6]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.5...@waku/interfaces@0.0.6
26
+ [0.0.5]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.4...@waku/interfaces@0.0.5
27
+ [0.0.4]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.3...@waku/interfaces@0.0.4
28
+ [0.0.3]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.2...%40waku/create@0.0.3
29
+ [0.0.2]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.1...%40waku/create@0.0.2
30
+ [0.0.1]: https://github.com/status-im/js-waku/compare/a20b7809d61ff9a9732aba82b99bbe99f229b935...%40waku/create%400.0.2
@@ -0,0 +1,5 @@
1
+ import type { IDecodedMessage, IDecoder } from "./message.js";
2
+ import type { Callback, PointToPointProtocol, ProtocolOptions } from "./protocols.js";
3
+ export interface IFilter extends PointToPointProtocol {
4
+ subscribe: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: Callback<T>, opts?: ProtocolOptions) => Promise<() => Promise<void>>;
5
+ }
package/dist/filter.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,146 +1,8 @@
1
- import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
2
- import type { Stream } from "@libp2p/interface-connection";
3
- import type { PeerId } from "@libp2p/interface-peer-id";
4
- import type { Peer } from "@libp2p/interface-peer-store";
5
- import type { Multiaddr } from "@multiformats/multiaddr";
6
- import type { Libp2p } from "libp2p";
7
- export declare enum Protocols {
8
- Relay = "relay",
9
- Store = "store",
10
- LightPush = "lightpush",
11
- Filter = "filter"
12
- }
13
- export interface PointToPointProtocol {
14
- libp2p: Libp2p;
15
- peers: () => Promise<Peer[]>;
16
- }
17
- export declare type ProtocolOptions = {
18
- pubSubTopic?: string;
19
- /**
20
- * Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
21
- */
22
- peerId?: PeerId;
23
- };
24
- export declare type Callback<T extends Message> = (msg: T) => void | Promise<void>;
25
- export interface Filter extends PointToPointProtocol {
26
- subscribe: <T extends DecodedMessage>(decoders: Decoder<T>[], callback: Callback<T>, opts?: ProtocolOptions) => Promise<() => Promise<void>>;
27
- }
28
- export interface LightPush extends PointToPointProtocol {
29
- push: (encoder: Encoder, message: Message, opts?: ProtocolOptions) => Promise<SendResult>;
30
- }
31
- export declare enum PageDirection {
32
- BACKWARD = "backward",
33
- FORWARD = "forward"
34
- }
35
- export interface TimeFilter {
36
- startTime: Date;
37
- endTime: Date;
38
- }
39
- export declare type StoreQueryOptions = {
40
- /**
41
- * The direction in which pages are retrieved:
42
- * - { @link PageDirection.BACKWARD }: Most recent page first.
43
- * - { @link PageDirection.FORWARD }: Oldest page first.
44
- *
45
- * Note: This does not affect the ordering of messages with the page
46
- * (the oldest message is always first).
47
- *
48
- * @default { @link PageDirection.BACKWARD }
49
- */
50
- pageDirection?: PageDirection;
51
- /**
52
- * The number of message per page.
53
- */
54
- pageSize?: number;
55
- /**
56
- * Retrieve messages with a timestamp within the provided values.
57
- */
58
- timeFilter?: TimeFilter;
59
- } & ProtocolOptions;
60
- export interface Store extends PointToPointProtocol {
61
- queryOrderedCallback: <T extends DecodedMessage>(decoders: Decoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
62
- queryCallbackOnPromise: <T extends DecodedMessage>(decoders: Decoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
63
- queryGenerator: <T extends DecodedMessage>(decoders: Decoder<T>[], options?: StoreQueryOptions) => AsyncGenerator<Promise<T | undefined>[]>;
64
- }
65
- export interface Relay extends GossipSub {
66
- send: (encoder: Encoder, message: Message) => Promise<SendResult>;
67
- addObserver: <T extends DecodedMessage>(decoder: Decoder<T>, callback: Callback<T>) => () => void;
68
- getMeshPeers: () => string[];
69
- }
70
- export interface Waku {
71
- libp2p: Libp2p;
72
- relay?: Relay;
73
- store?: Store;
74
- filter?: Filter;
75
- lightPush?: LightPush;
76
- dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
77
- addPeerToAddressBook(peerId: PeerId | string, multiaddrs: Multiaddr[] | string[]): void;
78
- start(): Promise<void>;
79
- stop(): Promise<void>;
80
- isStarted(): boolean;
81
- }
82
- export interface WakuLight extends Waku {
83
- relay: undefined;
84
- store: Store;
85
- filter: Filter;
86
- lightPush: LightPush;
87
- }
88
- export interface WakuPrivacy extends Waku {
89
- relay: Relay;
90
- store: undefined;
91
- filter: undefined;
92
- lightPush: undefined;
93
- }
94
- export interface WakuFull extends Waku {
95
- relay: Relay;
96
- store: Store;
97
- filter: Filter;
98
- lightPush: LightPush;
99
- }
100
- export interface RateLimitProof {
101
- proof: Uint8Array;
102
- merkleRoot: Uint8Array;
103
- epoch: Uint8Array;
104
- shareX: Uint8Array;
105
- shareY: Uint8Array;
106
- nullifier: Uint8Array;
107
- rlnIdentifier: Uint8Array;
108
- }
109
- /**
110
- * Interface matching the protobuf library.
111
- * Field types matches the protobuf type over the wire
112
- */
113
- export interface ProtoMessage {
114
- payload: Uint8Array | undefined;
115
- contentTopic: string | undefined;
116
- version: number | undefined;
117
- timestamp: bigint | undefined;
118
- rateLimitProof: RateLimitProof | undefined;
119
- }
120
- /**
121
- * Interface for messages to encode and send.
122
- */
123
- export interface Message {
124
- payload?: Uint8Array;
125
- timestamp?: Date;
126
- rateLimitProof?: RateLimitProof;
127
- }
128
- export interface Encoder {
129
- contentTopic: string;
130
- toWire: (message: Message) => Promise<Uint8Array | undefined>;
131
- toProtoObj: (message: Message) => Promise<ProtoMessage | undefined>;
132
- }
133
- export interface DecodedMessage {
134
- payload: Uint8Array | undefined;
135
- contentTopic: string | undefined;
136
- timestamp: Date | undefined;
137
- rateLimitProof: RateLimitProof | undefined;
138
- }
139
- export interface Decoder<T extends DecodedMessage> {
140
- contentTopic: string;
141
- fromWireToProtoObj: (bytes: Uint8Array) => Promise<ProtoMessage | undefined>;
142
- fromProtoObj: (proto: ProtoMessage) => Promise<T | undefined>;
143
- }
144
- export interface SendResult {
145
- recipients: PeerId[];
146
- }
1
+ export * from "./filter.js";
2
+ export * from "./light_push.js";
3
+ export * from "./message.js";
4
+ export * from "./peer_exchange.js";
5
+ export * from "./protocols.js";
6
+ export * from "./relay.js";
7
+ export * from "./store.js";
8
+ export * from "./waku.js";
package/dist/index.js CHANGED
@@ -1,13 +1,9 @@
1
- export var Protocols;
2
- (function (Protocols) {
3
- Protocols["Relay"] = "relay";
4
- Protocols["Store"] = "store";
5
- Protocols["LightPush"] = "lightpush";
6
- Protocols["Filter"] = "filter";
7
- })(Protocols || (Protocols = {}));
8
- export var PageDirection;
9
- (function (PageDirection) {
10
- PageDirection["BACKWARD"] = "backward";
11
- PageDirection["FORWARD"] = "forward";
12
- })(PageDirection || (PageDirection = {}));
1
+ export * from "./filter.js";
2
+ export * from "./light_push.js";
3
+ export * from "./message.js";
4
+ export * from "./peer_exchange.js";
5
+ export * from "./protocols.js";
6
+ export * from "./relay.js";
7
+ export * from "./store.js";
8
+ export * from "./waku.js";
13
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB;AAiCD,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;AACrB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { IEncoder, IMessage } from "./message.js";
2
+ import type { PointToPointProtocol, ProtocolOptions, SendResult } from "./protocols.js";
3
+ export interface ILightPush extends PointToPointProtocol {
4
+ push: (encoder: IEncoder, message: IMessage, opts?: ProtocolOptions) => Promise<SendResult>;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=light_push.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light_push.js","sourceRoot":"","sources":["../src/light_push.ts"],"names":[],"mappings":""}
@@ -0,0 +1,47 @@
1
+ export interface IRateLimitProof {
2
+ proof: Uint8Array;
3
+ merkleRoot: Uint8Array;
4
+ epoch: Uint8Array;
5
+ shareX: Uint8Array;
6
+ shareY: Uint8Array;
7
+ nullifier: Uint8Array;
8
+ rlnIdentifier: Uint8Array;
9
+ }
10
+ /**
11
+ * Interface matching the protobuf library.
12
+ * Field types matches the protobuf type over the wire
13
+ */
14
+ export interface IProtoMessage {
15
+ payload: Uint8Array | undefined;
16
+ contentTopic: string | undefined;
17
+ version: number | undefined;
18
+ timestamp: bigint | undefined;
19
+ rateLimitProof: IRateLimitProof | undefined;
20
+ ephemeral: boolean | undefined;
21
+ }
22
+ /**
23
+ * Interface for messages to encode and send.
24
+ */
25
+ export interface IMessage {
26
+ payload?: Uint8Array;
27
+ timestamp?: Date;
28
+ rateLimitProof?: IRateLimitProof;
29
+ }
30
+ export interface IEncoder {
31
+ contentTopic: string;
32
+ ephemeral: boolean;
33
+ toWire: (message: IMessage) => Promise<Uint8Array | undefined>;
34
+ toProtoObj: (message: IMessage) => Promise<IProtoMessage | undefined>;
35
+ }
36
+ export interface IDecodedMessage {
37
+ payload: Uint8Array | undefined;
38
+ contentTopic: string | undefined;
39
+ timestamp: Date | undefined;
40
+ rateLimitProof: IRateLimitProof | undefined;
41
+ ephemeral: boolean | undefined;
42
+ }
43
+ export interface IDecoder<T extends IDecodedMessage> {
44
+ contentTopic: string;
45
+ fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>;
46
+ fromProtoObj: (proto: IProtoMessage) => Promise<T | undefined>;
47
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import type { ConnectionManager } from "@libp2p/interface-connection-manager";
2
+ import type { PeerStore } from "@libp2p/interface-peer-store";
3
+ import type { Registrar } from "@libp2p/interface-registrar";
4
+ import { ENR } from "@waku/enr";
5
+ import { PointToPointProtocol } from "./protocols.js";
6
+ export interface IPeerExchange extends PointToPointProtocol {
7
+ query(params: PeerExchangeQueryParams, callback: (response: PeerExchangeResponse) => Promise<void> | void): Promise<void>;
8
+ }
9
+ export interface PeerExchangeQueryParams {
10
+ numPeers: number;
11
+ }
12
+ export interface PeerExchangeResponse {
13
+ peerInfos: PeerInfo[];
14
+ }
15
+ export interface PeerInfo {
16
+ ENR?: ENR;
17
+ }
18
+ export interface PeerExchangeComponents {
19
+ connectionManager: ConnectionManager;
20
+ peerStore: PeerStore;
21
+ registrar: Registrar;
22
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=peer_exchange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peer_exchange.js","sourceRoot":"","sources":["../src/peer_exchange.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import type { PeerId } from "@libp2p/interface-peer-id";
2
+ import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
3
+ import type { IMessage } from "./message.js";
4
+ export declare enum Protocols {
5
+ Relay = "relay",
6
+ Store = "store",
7
+ LightPush = "lightpush",
8
+ Filter = "filter",
9
+ PeerExchange = "peer-exchange"
10
+ }
11
+ export interface PointToPointProtocol {
12
+ peerStore: PeerStore;
13
+ peers: () => Promise<Peer[]>;
14
+ }
15
+ export declare type ProtocolOptions = {
16
+ pubSubTopic?: string;
17
+ /**
18
+ * Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
19
+ */
20
+ peerId?: PeerId;
21
+ };
22
+ export declare type Callback<T extends IMessage> = (msg: T) => void | Promise<void>;
23
+ export interface SendResult {
24
+ recipients: PeerId[];
25
+ }
@@ -0,0 +1,9 @@
1
+ export var Protocols;
2
+ (function (Protocols) {
3
+ Protocols["Relay"] = "relay";
4
+ Protocols["Store"] = "store";
5
+ Protocols["LightPush"] = "lightpush";
6
+ Protocols["Filter"] = "filter";
7
+ Protocols["PeerExchange"] = "peer-exchange";
8
+ })(Protocols || (Protocols = {}));
9
+ //# sourceMappingURL=protocols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AAKA,MAAM,CAAN,IAAY,SAMX;AAND,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,8BAAiB,CAAA;IACjB,2CAA8B,CAAA;AAChC,CAAC,EANW,SAAS,KAAT,SAAS,QAMpB"}
@@ -0,0 +1,8 @@
1
+ import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
2
+ import type { IDecodedMessage, IDecoder, IEncoder, IMessage } from "./message.js";
3
+ import type { Callback, SendResult } from "./protocols.js";
4
+ export interface IRelay extends GossipSub {
5
+ send: (encoder: IEncoder, message: IMessage) => Promise<SendResult>;
6
+ addObserver: <T extends IDecodedMessage>(decoder: IDecoder<T>, callback: Callback<T>) => () => void;
7
+ getMeshPeers: () => string[];
8
+ }
package/dist/relay.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=relay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.js","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":""}
@@ -0,0 +1,51 @@
1
+ import type { IDecodedMessage, IDecoder } from "./message.js";
2
+ import type { PointToPointProtocol, ProtocolOptions } from "./protocols.js";
3
+ export declare enum PageDirection {
4
+ BACKWARD = "backward",
5
+ FORWARD = "forward"
6
+ }
7
+ export interface TimeFilter {
8
+ startTime: Date;
9
+ endTime: Date;
10
+ }
11
+ export interface Index {
12
+ digest?: Uint8Array;
13
+ receivedTime?: bigint;
14
+ senderTime?: bigint;
15
+ pubsubTopic?: string;
16
+ }
17
+ export declare type Cursor = {
18
+ digest?: Uint8Array;
19
+ senderTime?: bigint;
20
+ pubsubTopic?: string;
21
+ };
22
+ export declare type StoreQueryOptions = {
23
+ /**
24
+ * The direction in which pages are retrieved:
25
+ * - { @link PageDirection.BACKWARD }: Most recent page first.
26
+ * - { @link PageDirection.FORWARD }: Oldest page first.
27
+ *
28
+ * Note: This does not affect the ordering of messages with the page
29
+ * (the oldest message is always first).
30
+ *
31
+ * @default { @link PageDirection.BACKWARD }
32
+ */
33
+ pageDirection?: PageDirection;
34
+ /**
35
+ * The number of message per page.
36
+ */
37
+ pageSize?: number;
38
+ /**
39
+ * Retrieve messages with a timestamp within the provided values.
40
+ */
41
+ timeFilter?: TimeFilter;
42
+ /**
43
+ * Cursor as an index to start a query from.
44
+ */
45
+ cursor?: Cursor;
46
+ } & ProtocolOptions;
47
+ export interface IStore extends PointToPointProtocol {
48
+ queryOrderedCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
49
+ queryCallbackOnPromise: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
50
+ queryGenerator: <T extends IDecodedMessage>(decoders: IDecoder<T>[], options?: StoreQueryOptions) => AsyncGenerator<Promise<T | undefined>[]>;
51
+ }
package/dist/store.js ADDED
@@ -0,0 +1,6 @@
1
+ export var PageDirection;
2
+ (function (PageDirection) {
3
+ PageDirection["BACKWARD"] = "backward";
4
+ PageDirection["FORWARD"] = "forward";
5
+ })(PageDirection || (PageDirection = {}));
6
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAGA,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;AACrB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB"}
package/dist/waku.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import type { Stream } from "@libp2p/interface-connection";
2
+ import type { PeerId } from "@libp2p/interface-peer-id";
3
+ import type { Multiaddr } from "@multiformats/multiaddr";
4
+ import type { Libp2p } from "libp2p";
5
+ import type { IFilter } from "./filter.js";
6
+ import type { ILightPush } from "./light_push.js";
7
+ import type { IPeerExchange } from "./peer_exchange.js";
8
+ import { Protocols } from "./protocols.js";
9
+ import type { IRelay } from "./relay.js";
10
+ import type { IStore } from "./store.js";
11
+ export interface Waku {
12
+ libp2p: Libp2p;
13
+ relay?: IRelay;
14
+ store?: IStore;
15
+ filter?: IFilter;
16
+ lightPush?: ILightPush;
17
+ peerExchange?: IPeerExchange;
18
+ dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
19
+ start(): Promise<void>;
20
+ stop(): Promise<void>;
21
+ isStarted(): boolean;
22
+ }
23
+ export interface LightNode extends Waku {
24
+ relay: undefined;
25
+ store: IStore;
26
+ filter: IFilter;
27
+ lightPush: ILightPush;
28
+ peerExchange: IPeerExchange;
29
+ }
30
+ export interface RelayNode extends Waku {
31
+ relay: IRelay;
32
+ store: undefined;
33
+ filter: undefined;
34
+ lightPush: undefined;
35
+ peerExchange: undefined;
36
+ }
37
+ export interface FullNode extends Waku {
38
+ relay: IRelay;
39
+ store: IStore;
40
+ filter: IFilter;
41
+ lightPush: ILightPush;
42
+ peerExchange: IPeerExchange;
43
+ }
package/dist/waku.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=waku.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"waku.js","sourceRoot":"","sources":["../src/waku.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waku/interfaces",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Definition of Waku interfaces",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/index.js",
@@ -48,17 +48,17 @@
48
48
  "node": ">=16"
49
49
  },
50
50
  "dependencies": {
51
- "@chainsafe/libp2p-gossipsub": "^4.1.1",
51
+ "@chainsafe/libp2p-gossipsub": "^5.2.1",
52
52
  "@libp2p/interface-connection": "^3.0.2",
53
53
  "@libp2p/interface-peer-id": "^1.0.5",
54
- "@libp2p/interface-peer-store": "^1.2.2",
54
+ "@libp2p/interface-peer-store": "^1.2.3",
55
55
  "@multiformats/multiaddr": "^11.0.6",
56
- "libp2p": "0.39.5"
56
+ "libp2p": "0.40.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@typescript-eslint/eslint-plugin": "^5.8.1",
60
60
  "@typescript-eslint/parser": "^5.8.1",
61
- "cspell": "^5.14.0",
61
+ "cspell": "^6.17.0",
62
62
  "eslint": "^8.6.0",
63
63
  "eslint-config-prettier": "^8.3.0",
64
64
  "eslint-plugin-eslint-comments": "^3.2.0",
package/src/filter.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { IDecodedMessage, IDecoder } from "./message.js";
2
+ import type {
3
+ Callback,
4
+ PointToPointProtocol,
5
+ ProtocolOptions,
6
+ } from "./protocols.js";
7
+
8
+ export interface IFilter extends PointToPointProtocol {
9
+ subscribe: <T extends IDecodedMessage>(
10
+ decoders: IDecoder<T>[],
11
+ callback: Callback<T>,
12
+ opts?: ProtocolOptions
13
+ ) => Promise<() => Promise<void>>;
14
+ }
package/src/index.ts CHANGED
@@ -1,200 +1,8 @@
1
- import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
2
- import type { Stream } from "@libp2p/interface-connection";
3
- import type { PeerId } from "@libp2p/interface-peer-id";
4
- import type { Peer } from "@libp2p/interface-peer-store";
5
- import type { Multiaddr } from "@multiformats/multiaddr";
6
- import type { Libp2p } from "libp2p";
7
-
8
- export enum Protocols {
9
- Relay = "relay",
10
- Store = "store",
11
- LightPush = "lightpush",
12
- Filter = "filter",
13
- }
14
-
15
- export interface PointToPointProtocol {
16
- libp2p: Libp2p;
17
- peers: () => Promise<Peer[]>;
18
- }
19
-
20
- export type ProtocolOptions = {
21
- pubSubTopic?: string;
22
- /**
23
- * Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
24
- */
25
- peerId?: PeerId;
26
- };
27
-
28
- export type Callback<T extends Message> = (msg: T) => void | Promise<void>;
29
-
30
- export interface Filter extends PointToPointProtocol {
31
- subscribe: <T extends DecodedMessage>(
32
- decoders: Decoder<T>[],
33
- callback: Callback<T>,
34
- opts?: ProtocolOptions
35
- ) => Promise<() => Promise<void>>;
36
- }
37
-
38
- export interface LightPush extends PointToPointProtocol {
39
- push: (
40
- encoder: Encoder,
41
- message: Message,
42
- opts?: ProtocolOptions
43
- ) => Promise<SendResult>;
44
- }
45
-
46
- export enum PageDirection {
47
- BACKWARD = "backward",
48
- FORWARD = "forward",
49
- }
50
-
51
- export interface TimeFilter {
52
- startTime: Date;
53
- endTime: Date;
54
- }
55
-
56
- export type StoreQueryOptions = {
57
- /**
58
- * The direction in which pages are retrieved:
59
- * - { @link PageDirection.BACKWARD }: Most recent page first.
60
- * - { @link PageDirection.FORWARD }: Oldest page first.
61
- *
62
- * Note: This does not affect the ordering of messages with the page
63
- * (the oldest message is always first).
64
- *
65
- * @default { @link PageDirection.BACKWARD }
66
- */
67
- pageDirection?: PageDirection;
68
- /**
69
- * The number of message per page.
70
- */
71
- pageSize?: number;
72
- /**
73
- * Retrieve messages with a timestamp within the provided values.
74
- */
75
- timeFilter?: TimeFilter;
76
- } & ProtocolOptions;
77
-
78
- export interface Store extends PointToPointProtocol {
79
- queryOrderedCallback: <T extends DecodedMessage>(
80
- decoders: Decoder<T>[],
81
- callback: (message: T) => Promise<void | boolean> | boolean | void,
82
- options?: StoreQueryOptions
83
- ) => Promise<void>;
84
- queryCallbackOnPromise: <T extends DecodedMessage>(
85
- decoders: Decoder<T>[],
86
- callback: (
87
- message: Promise<T | undefined>
88
- ) => Promise<void | boolean> | boolean | void,
89
- options?: StoreQueryOptions
90
- ) => Promise<void>;
91
- queryGenerator: <T extends DecodedMessage>(
92
- decoders: Decoder<T>[],
93
- options?: StoreQueryOptions
94
- ) => AsyncGenerator<Promise<T | undefined>[]>;
95
- }
96
-
97
- export interface Relay extends GossipSub {
98
- send: (encoder: Encoder, message: Message) => Promise<SendResult>;
99
- addObserver: <T extends DecodedMessage>(
100
- decoder: Decoder<T>,
101
- callback: Callback<T>
102
- ) => () => void;
103
- getMeshPeers: () => string[];
104
- }
105
-
106
- export interface Waku {
107
- libp2p: Libp2p;
108
- relay?: Relay;
109
- store?: Store;
110
- filter?: Filter;
111
- lightPush?: LightPush;
112
-
113
- dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
114
-
115
- addPeerToAddressBook(
116
- peerId: PeerId | string,
117
- multiaddrs: Multiaddr[] | string[]
118
- ): void;
119
-
120
- start(): Promise<void>;
121
-
122
- stop(): Promise<void>;
123
-
124
- isStarted(): boolean;
125
- }
126
-
127
- export interface WakuLight extends Waku {
128
- relay: undefined;
129
- store: Store;
130
- filter: Filter;
131
- lightPush: LightPush;
132
- }
133
-
134
- export interface WakuPrivacy extends Waku {
135
- relay: Relay;
136
- store: undefined;
137
- filter: undefined;
138
- lightPush: undefined;
139
- }
140
-
141
- export interface WakuFull extends Waku {
142
- relay: Relay;
143
- store: Store;
144
- filter: Filter;
145
- lightPush: LightPush;
146
- }
147
-
148
- export interface RateLimitProof {
149
- proof: Uint8Array;
150
- merkleRoot: Uint8Array;
151
- epoch: Uint8Array;
152
- shareX: Uint8Array;
153
- shareY: Uint8Array;
154
- nullifier: Uint8Array;
155
- rlnIdentifier: Uint8Array;
156
- }
157
-
158
- /**
159
- * Interface matching the protobuf library.
160
- * Field types matches the protobuf type over the wire
161
- */
162
- export interface ProtoMessage {
163
- payload: Uint8Array | undefined;
164
- contentTopic: string | undefined;
165
- version: number | undefined;
166
- timestamp: bigint | undefined;
167
- rateLimitProof: RateLimitProof | undefined;
168
- }
169
-
170
- /**
171
- * Interface for messages to encode and send.
172
- */
173
- export interface Message {
174
- payload?: Uint8Array;
175
- timestamp?: Date;
176
- rateLimitProof?: RateLimitProof;
177
- }
178
-
179
- export interface Encoder {
180
- contentTopic: string;
181
- toWire: (message: Message) => Promise<Uint8Array | undefined>;
182
- toProtoObj: (message: Message) => Promise<ProtoMessage | undefined>;
183
- }
184
-
185
- export interface DecodedMessage {
186
- payload: Uint8Array | undefined;
187
- contentTopic: string | undefined;
188
- timestamp: Date | undefined;
189
- rateLimitProof: RateLimitProof | undefined;
190
- }
191
-
192
- export interface Decoder<T extends DecodedMessage> {
193
- contentTopic: string;
194
- fromWireToProtoObj: (bytes: Uint8Array) => Promise<ProtoMessage | undefined>;
195
- fromProtoObj: (proto: ProtoMessage) => Promise<T | undefined>;
196
- }
197
-
198
- export interface SendResult {
199
- recipients: PeerId[];
200
- }
1
+ export * from "./filter.js";
2
+ export * from "./light_push.js";
3
+ export * from "./message.js";
4
+ export * from "./peer_exchange.js";
5
+ export * from "./protocols.js";
6
+ export * from "./relay.js";
7
+ export * from "./store.js";
8
+ export * from "./waku.js";
@@ -0,0 +1,14 @@
1
+ import type { IEncoder, IMessage } from "./message.js";
2
+ import type {
3
+ PointToPointProtocol,
4
+ ProtocolOptions,
5
+ SendResult,
6
+ } from "./protocols.js";
7
+
8
+ export interface ILightPush extends PointToPointProtocol {
9
+ push: (
10
+ encoder: IEncoder,
11
+ message: IMessage,
12
+ opts?: ProtocolOptions
13
+ ) => Promise<SendResult>;
14
+ }
package/src/message.ts ADDED
@@ -0,0 +1,52 @@
1
+ export interface IRateLimitProof {
2
+ proof: Uint8Array;
3
+ merkleRoot: Uint8Array;
4
+ epoch: Uint8Array;
5
+ shareX: Uint8Array;
6
+ shareY: Uint8Array;
7
+ nullifier: Uint8Array;
8
+ rlnIdentifier: Uint8Array;
9
+ }
10
+
11
+ /**
12
+ * Interface matching the protobuf library.
13
+ * Field types matches the protobuf type over the wire
14
+ */
15
+ export interface IProtoMessage {
16
+ payload: Uint8Array | undefined;
17
+ contentTopic: string | undefined;
18
+ version: number | undefined;
19
+ timestamp: bigint | undefined;
20
+ rateLimitProof: IRateLimitProof | undefined;
21
+ ephemeral: boolean | undefined;
22
+ }
23
+
24
+ /**
25
+ * Interface for messages to encode and send.
26
+ */
27
+ export interface IMessage {
28
+ payload?: Uint8Array;
29
+ timestamp?: Date;
30
+ rateLimitProof?: IRateLimitProof;
31
+ }
32
+
33
+ export interface IEncoder {
34
+ contentTopic: string;
35
+ ephemeral: boolean;
36
+ toWire: (message: IMessage) => Promise<Uint8Array | undefined>;
37
+ toProtoObj: (message: IMessage) => Promise<IProtoMessage | undefined>;
38
+ }
39
+
40
+ export interface IDecodedMessage {
41
+ payload: Uint8Array | undefined;
42
+ contentTopic: string | undefined;
43
+ timestamp: Date | undefined;
44
+ rateLimitProof: IRateLimitProof | undefined;
45
+ ephemeral: boolean | undefined;
46
+ }
47
+
48
+ export interface IDecoder<T extends IDecodedMessage> {
49
+ contentTopic: string;
50
+ fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>;
51
+ fromProtoObj: (proto: IProtoMessage) => Promise<T | undefined>;
52
+ }
@@ -0,0 +1,31 @@
1
+ import type { ConnectionManager } from "@libp2p/interface-connection-manager";
2
+ import type { PeerStore } from "@libp2p/interface-peer-store";
3
+ import type { Registrar } from "@libp2p/interface-registrar";
4
+ import { ENR } from "@waku/enr";
5
+
6
+ import { PointToPointProtocol } from "./protocols.js";
7
+
8
+ export interface IPeerExchange extends PointToPointProtocol {
9
+ query(
10
+ params: PeerExchangeQueryParams,
11
+ callback: (response: PeerExchangeResponse) => Promise<void> | void
12
+ ): Promise<void>;
13
+ }
14
+
15
+ export interface PeerExchangeQueryParams {
16
+ numPeers: number;
17
+ }
18
+
19
+ export interface PeerExchangeResponse {
20
+ peerInfos: PeerInfo[];
21
+ }
22
+
23
+ export interface PeerInfo {
24
+ ENR?: ENR;
25
+ }
26
+
27
+ export interface PeerExchangeComponents {
28
+ connectionManager: ConnectionManager;
29
+ peerStore: PeerStore;
30
+ registrar: Registrar;
31
+ }
@@ -0,0 +1,31 @@
1
+ import type { PeerId } from "@libp2p/interface-peer-id";
2
+ import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
3
+
4
+ import type { IMessage } from "./message.js";
5
+
6
+ export enum Protocols {
7
+ Relay = "relay",
8
+ Store = "store",
9
+ LightPush = "lightpush",
10
+ Filter = "filter",
11
+ PeerExchange = "peer-exchange",
12
+ }
13
+
14
+ export interface PointToPointProtocol {
15
+ peerStore: PeerStore;
16
+ peers: () => Promise<Peer[]>;
17
+ }
18
+
19
+ export type ProtocolOptions = {
20
+ pubSubTopic?: string;
21
+ /**
22
+ * Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
23
+ */
24
+ peerId?: PeerId;
25
+ };
26
+
27
+ export type Callback<T extends IMessage> = (msg: T) => void | Promise<void>;
28
+
29
+ export interface SendResult {
30
+ recipients: PeerId[];
31
+ }
package/src/relay.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
2
+
3
+ import type {
4
+ IDecodedMessage,
5
+ IDecoder,
6
+ IEncoder,
7
+ IMessage,
8
+ } from "./message.js";
9
+ import type { Callback, SendResult } from "./protocols.js";
10
+
11
+ export interface IRelay extends GossipSub {
12
+ send: (encoder: IEncoder, message: IMessage) => Promise<SendResult>;
13
+ addObserver: <T extends IDecodedMessage>(
14
+ decoder: IDecoder<T>,
15
+ callback: Callback<T>
16
+ ) => () => void;
17
+ getMeshPeers: () => string[];
18
+ }
package/src/store.ts ADDED
@@ -0,0 +1,70 @@
1
+ import type { IDecodedMessage, IDecoder } from "./message.js";
2
+ import type { PointToPointProtocol, ProtocolOptions } from "./protocols.js";
3
+
4
+ export enum PageDirection {
5
+ BACKWARD = "backward",
6
+ FORWARD = "forward",
7
+ }
8
+
9
+ export interface TimeFilter {
10
+ startTime: Date;
11
+ endTime: Date;
12
+ }
13
+
14
+ export interface Index {
15
+ digest?: Uint8Array;
16
+ receivedTime?: bigint;
17
+ senderTime?: bigint;
18
+ pubsubTopic?: string;
19
+ }
20
+
21
+ export type Cursor = {
22
+ digest?: Uint8Array;
23
+ senderTime?: bigint;
24
+ pubsubTopic?: string;
25
+ };
26
+
27
+ export type StoreQueryOptions = {
28
+ /**
29
+ * The direction in which pages are retrieved:
30
+ * - { @link PageDirection.BACKWARD }: Most recent page first.
31
+ * - { @link PageDirection.FORWARD }: Oldest page first.
32
+ *
33
+ * Note: This does not affect the ordering of messages with the page
34
+ * (the oldest message is always first).
35
+ *
36
+ * @default { @link PageDirection.BACKWARD }
37
+ */
38
+ pageDirection?: PageDirection;
39
+ /**
40
+ * The number of message per page.
41
+ */
42
+ pageSize?: number;
43
+ /**
44
+ * Retrieve messages with a timestamp within the provided values.
45
+ */
46
+ timeFilter?: TimeFilter;
47
+ /**
48
+ * Cursor as an index to start a query from.
49
+ */
50
+ cursor?: Cursor;
51
+ } & ProtocolOptions;
52
+
53
+ export interface IStore extends PointToPointProtocol {
54
+ queryOrderedCallback: <T extends IDecodedMessage>(
55
+ decoders: IDecoder<T>[],
56
+ callback: (message: T) => Promise<void | boolean> | boolean | void,
57
+ options?: StoreQueryOptions
58
+ ) => Promise<void>;
59
+ queryCallbackOnPromise: <T extends IDecodedMessage>(
60
+ decoders: IDecoder<T>[],
61
+ callback: (
62
+ message: Promise<T | undefined>
63
+ ) => Promise<void | boolean> | boolean | void,
64
+ options?: StoreQueryOptions
65
+ ) => Promise<void>;
66
+ queryGenerator: <T extends IDecodedMessage>(
67
+ decoders: IDecoder<T>[],
68
+ options?: StoreQueryOptions
69
+ ) => AsyncGenerator<Promise<T | undefined>[]>;
70
+ }
package/src/waku.ts ADDED
@@ -0,0 +1,52 @@
1
+ import type { Stream } from "@libp2p/interface-connection";
2
+ import type { PeerId } from "@libp2p/interface-peer-id";
3
+ import type { Multiaddr } from "@multiformats/multiaddr";
4
+ import type { Libp2p } from "libp2p";
5
+
6
+ import type { IFilter } from "./filter.js";
7
+ import type { ILightPush } from "./light_push.js";
8
+ import type { IPeerExchange } from "./peer_exchange.js";
9
+ import { Protocols } from "./protocols.js";
10
+ import type { IRelay } from "./relay.js";
11
+ import type { IStore } from "./store.js";
12
+
13
+ export interface Waku {
14
+ libp2p: Libp2p;
15
+ relay?: IRelay;
16
+ store?: IStore;
17
+ filter?: IFilter;
18
+ lightPush?: ILightPush;
19
+ peerExchange?: IPeerExchange;
20
+
21
+ dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
22
+
23
+ start(): Promise<void>;
24
+
25
+ stop(): Promise<void>;
26
+
27
+ isStarted(): boolean;
28
+ }
29
+
30
+ export interface LightNode extends Waku {
31
+ relay: undefined;
32
+ store: IStore;
33
+ filter: IFilter;
34
+ lightPush: ILightPush;
35
+ peerExchange: IPeerExchange;
36
+ }
37
+
38
+ export interface RelayNode extends Waku {
39
+ relay: IRelay;
40
+ store: undefined;
41
+ filter: undefined;
42
+ lightPush: undefined;
43
+ peerExchange: undefined;
44
+ }
45
+
46
+ export interface FullNode extends Waku {
47
+ relay: IRelay;
48
+ store: IStore;
49
+ filter: IFilter;
50
+ lightPush: ILightPush;
51
+ peerExchange: IPeerExchange;
52
+ }