@waku/interfaces 0.0.5 → 0.0.7

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,38 @@
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.7] - 2023-01-18
11
+
12
+ ### Added
13
+
14
+ - `IPeerExchange` interface.
15
+ - `IEnr` interface.
16
+
17
+ ## [0.0.6] - 2022-12-15
18
+
19
+ ### Changed
20
+
21
+ - Add `I` prefix to protocol and messages interfaces.
22
+ - Renamed node interfaces to include `Node`.
23
+ - Renamed `WakuPrivacy` to `RelayNode`.
24
+
25
+ ## [0.0.5] - 2022-11-18
26
+
27
+ ### Added
28
+
29
+ - Alpha version of `@waku/interfaces`.
30
+
31
+ [unreleased]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.7...HEAD
32
+ [0.0.7]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.6...@waku/interfaces@0.0.7
33
+ [0.0.6]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.5...@waku/interfaces@0.0.6
34
+ [0.0.5]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.4...@waku/interfaces@0.0.5
35
+ [0.0.4]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.3...@waku/interfaces@0.0.4
36
+ [0.0.3]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.2...%40waku/create@0.0.3
37
+ [0.0.2]: https://github.com/waku-org/js-waku/compare/@waku/interfaces@0.0.1...%40waku/create@0.0.2
38
+ [0.0.1]: https://github.com/status-im/js-waku/compare/a20b7809d61ff9a9732aba82b99bbe99f229b935...%40waku/create%400.0.2
package/dist/enr.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type { PeerId } from "@libp2p/interface-peer-id";
2
+ import type { Multiaddr } from "@multiformats/multiaddr";
3
+ export declare type ENRKey = string;
4
+ export declare type ENRValue = Uint8Array;
5
+ /**
6
+ * We represent NodeId as a hex string, since node equality is used very heavily
7
+ * and it is convenient to index data by NodeId
8
+ */
9
+ export declare type NodeId = string;
10
+ export declare type SequenceNumber = bigint;
11
+ export interface Waku2 {
12
+ relay: boolean;
13
+ store: boolean;
14
+ filter: boolean;
15
+ lightPush: boolean;
16
+ }
17
+ export interface IEnr extends Map<ENRKey, ENRValue> {
18
+ nodeId?: NodeId;
19
+ peerId?: PeerId;
20
+ id: string;
21
+ seq: SequenceNumber;
22
+ publicKey?: Uint8Array;
23
+ signature?: Uint8Array;
24
+ ip?: string;
25
+ tcp?: number;
26
+ udp?: number;
27
+ ip6?: string;
28
+ tcp6?: number;
29
+ udp6?: number;
30
+ multiaddrs?: Multiaddr[];
31
+ waku2?: Waku2;
32
+ encode(privateKey?: Uint8Array): Promise<Uint8Array>;
33
+ getFullMultiaddrs(): Multiaddr[];
34
+ }
package/dist/enr.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=enr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enr.js","sourceRoot":"","sources":["../src/enr.ts"],"names":[],"mappings":""}
@@ -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,159 +1,9 @@
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 { PeerStore } from "@libp2p/interface-peer-store";
6
- import type { Multiaddr } from "@multiformats/multiaddr";
7
- import type { Libp2p } from "libp2p";
8
- export declare enum Protocols {
9
- Relay = "relay",
10
- Store = "store",
11
- LightPush = "lightpush",
12
- Filter = "filter"
13
- }
14
- export interface PointToPointProtocol {
15
- peerStore: PeerStore;
16
- peers: () => Promise<Peer[]>;
17
- }
18
- export interface Index {
19
- digest?: Uint8Array;
20
- receivedTime?: bigint;
21
- senderTime?: bigint;
22
- pubsubTopic?: string;
23
- }
24
- export declare type ProtocolOptions = {
25
- pubSubTopic?: string;
26
- /**
27
- * Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
28
- */
29
- peerId?: PeerId;
30
- };
31
- export declare type Callback<T extends Message> = (msg: T) => void | Promise<void>;
32
- export interface Filter extends PointToPointProtocol {
33
- subscribe: <T extends DecodedMessage>(decoders: Decoder<T>[], callback: Callback<T>, opts?: ProtocolOptions) => Promise<() => Promise<void>>;
34
- }
35
- export interface LightPush extends PointToPointProtocol {
36
- push: (encoder: Encoder, message: Message, opts?: ProtocolOptions) => Promise<SendResult>;
37
- }
38
- export declare enum PageDirection {
39
- BACKWARD = "backward",
40
- FORWARD = "forward"
41
- }
42
- export interface TimeFilter {
43
- startTime: Date;
44
- endTime: Date;
45
- }
46
- export declare type StoreQueryOptions = {
47
- /**
48
- * The direction in which pages are retrieved:
49
- * - { @link PageDirection.BACKWARD }: Most recent page first.
50
- * - { @link PageDirection.FORWARD }: Oldest page first.
51
- *
52
- * Note: This does not affect the ordering of messages with the page
53
- * (the oldest message is always first).
54
- *
55
- * @default { @link PageDirection.BACKWARD }
56
- */
57
- pageDirection?: PageDirection;
58
- /**
59
- * The number of message per page.
60
- */
61
- pageSize?: number;
62
- /**
63
- * Retrieve messages with a timestamp within the provided values.
64
- */
65
- timeFilter?: TimeFilter;
66
- /**
67
- * Cursor as an index to start a query from.
68
- */
69
- cursor?: Index;
70
- } & ProtocolOptions;
71
- export interface Store extends PointToPointProtocol {
72
- queryOrderedCallback: <T extends DecodedMessage>(decoders: Decoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
73
- queryCallbackOnPromise: <T extends DecodedMessage>(decoders: Decoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
74
- queryGenerator: <T extends DecodedMessage>(decoders: Decoder<T>[], options?: StoreQueryOptions) => AsyncGenerator<Promise<T | undefined>[]>;
75
- }
76
- export interface Relay extends GossipSub {
77
- send: (encoder: Encoder, message: Message) => Promise<SendResult>;
78
- addObserver: <T extends DecodedMessage>(decoder: Decoder<T>, callback: Callback<T>) => () => void;
79
- getMeshPeers: () => string[];
80
- }
81
- export interface Waku {
82
- libp2p: Libp2p;
83
- relay?: Relay;
84
- store?: Store;
85
- filter?: Filter;
86
- lightPush?: LightPush;
87
- dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
88
- start(): Promise<void>;
89
- stop(): Promise<void>;
90
- isStarted(): boolean;
91
- }
92
- export interface WakuLight extends Waku {
93
- relay: undefined;
94
- store: Store;
95
- filter: Filter;
96
- lightPush: LightPush;
97
- }
98
- export interface WakuPrivacy extends Waku {
99
- relay: Relay;
100
- store: undefined;
101
- filter: undefined;
102
- lightPush: undefined;
103
- }
104
- export interface WakuFull extends Waku {
105
- relay: Relay;
106
- store: Store;
107
- filter: Filter;
108
- lightPush: LightPush;
109
- }
110
- export interface RateLimitProof {
111
- proof: Uint8Array;
112
- merkleRoot: Uint8Array;
113
- epoch: Uint8Array;
114
- shareX: Uint8Array;
115
- shareY: Uint8Array;
116
- nullifier: Uint8Array;
117
- rlnIdentifier: Uint8Array;
118
- }
119
- /**
120
- * Interface matching the protobuf library.
121
- * Field types matches the protobuf type over the wire
122
- */
123
- export interface ProtoMessage {
124
- payload: Uint8Array | undefined;
125
- contentTopic: string | undefined;
126
- version: number | undefined;
127
- timestamp: bigint | undefined;
128
- rateLimitProof: RateLimitProof | undefined;
129
- ephemeral: boolean | undefined;
130
- }
131
- /**
132
- * Interface for messages to encode and send.
133
- */
134
- export interface Message {
135
- payload?: Uint8Array;
136
- timestamp?: Date;
137
- rateLimitProof?: RateLimitProof;
138
- }
139
- export interface Encoder {
140
- contentTopic: string;
141
- ephemeral: boolean;
142
- toWire: (message: Message) => Promise<Uint8Array | undefined>;
143
- toProtoObj: (message: Message) => Promise<ProtoMessage | undefined>;
144
- }
145
- export interface DecodedMessage {
146
- payload: Uint8Array | undefined;
147
- contentTopic: string | undefined;
148
- timestamp: Date | undefined;
149
- rateLimitProof: RateLimitProof | undefined;
150
- ephemeral: boolean | undefined;
151
- }
152
- export interface Decoder<T extends DecodedMessage> {
153
- contentTopic: string;
154
- fromWireToProtoObj: (bytes: Uint8Array) => Promise<ProtoMessage | undefined>;
155
- fromProtoObj: (proto: ProtoMessage) => Promise<T | undefined>;
156
- }
157
- export interface SendResult {
158
- recipients: PeerId[];
159
- }
1
+ export * from "./enr.js";
2
+ export * from "./filter.js";
3
+ export * from "./light_push.js";
4
+ export * from "./message.js";
5
+ export * from "./peer_exchange.js";
6
+ export * from "./protocols.js";
7
+ export * from "./relay.js";
8
+ export * from "./store.js";
9
+ export * from "./waku.js";
package/dist/index.js CHANGED
@@ -1,13 +1,10 @@
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 "./enr.js";
2
+ export * from "./filter.js";
3
+ export * from "./light_push.js";
4
+ export * from "./message.js";
5
+ export * from "./peer_exchange.js";
6
+ export * from "./protocols.js";
7
+ export * from "./relay.js";
8
+ export * from "./store.js";
9
+ export * from "./waku.js";
13
10
  //# 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":"AAQA,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;AAuCD,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,UAAU,CAAC;AACzB,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,24 @@
1
+ import type { ConnectionManager } from "@libp2p/interface-connection-manager";
2
+ import type { PeerId } from "@libp2p/interface-peer-id";
3
+ import type { PeerStore } from "@libp2p/interface-peer-store";
4
+ import type { Registrar } from "@libp2p/interface-registrar";
5
+ import { IEnr } from "./enr.js";
6
+ import { PointToPointProtocol } from "./protocols.js";
7
+ export interface IPeerExchange extends PointToPointProtocol {
8
+ query(params: PeerExchangeQueryParams, callback: (response: PeerExchangeResponse) => Promise<void> | void): Promise<void>;
9
+ }
10
+ export interface PeerExchangeQueryParams {
11
+ numPeers: number;
12
+ peerId?: PeerId;
13
+ }
14
+ export interface PeerExchangeResponse {
15
+ peerInfos: PeerInfo[];
16
+ }
17
+ export interface PeerInfo {
18
+ ENR?: IEnr;
19
+ }
20
+ export interface PeerExchangeComponents {
21
+ connectionManager: ConnectionManager;
22
+ peerStore: PeerStore;
23
+ registrar: Registrar;
24
+ }
@@ -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.5",
3
+ "version": "0.0.7",
4
4
  "description": "Definition of Waku interfaces",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/index.js",
@@ -58,7 +58,7 @@
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/enr.ts ADDED
@@ -0,0 +1,38 @@
1
+ import type { PeerId } from "@libp2p/interface-peer-id";
2
+ import type { Multiaddr } from "@multiformats/multiaddr";
3
+
4
+ export type ENRKey = string;
5
+ export type ENRValue = Uint8Array;
6
+ /**
7
+ * We represent NodeId as a hex string, since node equality is used very heavily
8
+ * and it is convenient to index data by NodeId
9
+ */
10
+ export type NodeId = string;
11
+ export type SequenceNumber = bigint;
12
+
13
+ export interface Waku2 {
14
+ relay: boolean;
15
+ store: boolean;
16
+ filter: boolean;
17
+ lightPush: boolean;
18
+ }
19
+
20
+ export interface IEnr extends Map<ENRKey, ENRValue> {
21
+ nodeId?: NodeId;
22
+ peerId?: PeerId;
23
+ id: string;
24
+ seq: SequenceNumber;
25
+ publicKey?: Uint8Array;
26
+ signature?: Uint8Array;
27
+ ip?: string;
28
+ tcp?: number;
29
+ udp?: number;
30
+ ip6?: string;
31
+ tcp6?: number;
32
+ udp6?: number;
33
+ multiaddrs?: Multiaddr[];
34
+ waku2?: Waku2;
35
+
36
+ encode(privateKey?: Uint8Array): Promise<Uint8Array>;
37
+ getFullMultiaddrs(): Multiaddr[];
38
+ }
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,209 +1,9 @@
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 { PeerStore } from "@libp2p/interface-peer-store";
6
- import type { Multiaddr } from "@multiformats/multiaddr";
7
- import type { Libp2p } from "libp2p";
8
-
9
- export enum Protocols {
10
- Relay = "relay",
11
- Store = "store",
12
- LightPush = "lightpush",
13
- Filter = "filter",
14
- }
15
-
16
- export interface PointToPointProtocol {
17
- peerStore: PeerStore;
18
- peers: () => Promise<Peer[]>;
19
- }
20
- export interface Index {
21
- digest?: Uint8Array;
22
- receivedTime?: bigint;
23
- senderTime?: bigint;
24
- pubsubTopic?: string;
25
- }
26
-
27
- export type ProtocolOptions = {
28
- pubSubTopic?: string;
29
- /**
30
- * Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
31
- */
32
- peerId?: PeerId;
33
- };
34
-
35
- export type Callback<T extends Message> = (msg: T) => void | Promise<void>;
36
-
37
- export interface Filter extends PointToPointProtocol {
38
- subscribe: <T extends DecodedMessage>(
39
- decoders: Decoder<T>[],
40
- callback: Callback<T>,
41
- opts?: ProtocolOptions
42
- ) => Promise<() => Promise<void>>;
43
- }
44
-
45
- export interface LightPush extends PointToPointProtocol {
46
- push: (
47
- encoder: Encoder,
48
- message: Message,
49
- opts?: ProtocolOptions
50
- ) => Promise<SendResult>;
51
- }
52
-
53
- export enum PageDirection {
54
- BACKWARD = "backward",
55
- FORWARD = "forward",
56
- }
57
-
58
- export interface TimeFilter {
59
- startTime: Date;
60
- endTime: Date;
61
- }
62
-
63
- export type StoreQueryOptions = {
64
- /**
65
- * The direction in which pages are retrieved:
66
- * - { @link PageDirection.BACKWARD }: Most recent page first.
67
- * - { @link PageDirection.FORWARD }: Oldest page first.
68
- *
69
- * Note: This does not affect the ordering of messages with the page
70
- * (the oldest message is always first).
71
- *
72
- * @default { @link PageDirection.BACKWARD }
73
- */
74
- pageDirection?: PageDirection;
75
- /**
76
- * The number of message per page.
77
- */
78
- pageSize?: number;
79
- /**
80
- * Retrieve messages with a timestamp within the provided values.
81
- */
82
- timeFilter?: TimeFilter;
83
- /**
84
- * Cursor as an index to start a query from.
85
- */
86
- cursor?: Index;
87
- } & ProtocolOptions;
88
-
89
- export interface Store extends PointToPointProtocol {
90
- queryOrderedCallback: <T extends DecodedMessage>(
91
- decoders: Decoder<T>[],
92
- callback: (message: T) => Promise<void | boolean> | boolean | void,
93
- options?: StoreQueryOptions
94
- ) => Promise<void>;
95
- queryCallbackOnPromise: <T extends DecodedMessage>(
96
- decoders: Decoder<T>[],
97
- callback: (
98
- message: Promise<T | undefined>
99
- ) => Promise<void | boolean> | boolean | void,
100
- options?: StoreQueryOptions
101
- ) => Promise<void>;
102
- queryGenerator: <T extends DecodedMessage>(
103
- decoders: Decoder<T>[],
104
- options?: StoreQueryOptions
105
- ) => AsyncGenerator<Promise<T | undefined>[]>;
106
- }
107
-
108
- export interface Relay extends GossipSub {
109
- send: (encoder: Encoder, message: Message) => Promise<SendResult>;
110
- addObserver: <T extends DecodedMessage>(
111
- decoder: Decoder<T>,
112
- callback: Callback<T>
113
- ) => () => void;
114
- getMeshPeers: () => string[];
115
- }
116
-
117
- export interface Waku {
118
- libp2p: Libp2p;
119
- relay?: Relay;
120
- store?: Store;
121
- filter?: Filter;
122
- lightPush?: LightPush;
123
-
124
- dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
125
-
126
- start(): Promise<void>;
127
-
128
- stop(): Promise<void>;
129
-
130
- isStarted(): boolean;
131
- }
132
-
133
- export interface WakuLight extends Waku {
134
- relay: undefined;
135
- store: Store;
136
- filter: Filter;
137
- lightPush: LightPush;
138
- }
139
-
140
- export interface WakuPrivacy extends Waku {
141
- relay: Relay;
142
- store: undefined;
143
- filter: undefined;
144
- lightPush: undefined;
145
- }
146
-
147
- export interface WakuFull extends Waku {
148
- relay: Relay;
149
- store: Store;
150
- filter: Filter;
151
- lightPush: LightPush;
152
- }
153
-
154
- export interface RateLimitProof {
155
- proof: Uint8Array;
156
- merkleRoot: Uint8Array;
157
- epoch: Uint8Array;
158
- shareX: Uint8Array;
159
- shareY: Uint8Array;
160
- nullifier: Uint8Array;
161
- rlnIdentifier: Uint8Array;
162
- }
163
-
164
- /**
165
- * Interface matching the protobuf library.
166
- * Field types matches the protobuf type over the wire
167
- */
168
- export interface ProtoMessage {
169
- payload: Uint8Array | undefined;
170
- contentTopic: string | undefined;
171
- version: number | undefined;
172
- timestamp: bigint | undefined;
173
- rateLimitProof: RateLimitProof | undefined;
174
- ephemeral: boolean | undefined;
175
- }
176
-
177
- /**
178
- * Interface for messages to encode and send.
179
- */
180
- export interface Message {
181
- payload?: Uint8Array;
182
- timestamp?: Date;
183
- rateLimitProof?: RateLimitProof;
184
- }
185
-
186
- export interface Encoder {
187
- contentTopic: string;
188
- ephemeral: boolean;
189
- toWire: (message: Message) => Promise<Uint8Array | undefined>;
190
- toProtoObj: (message: Message) => Promise<ProtoMessage | undefined>;
191
- }
192
-
193
- export interface DecodedMessage {
194
- payload: Uint8Array | undefined;
195
- contentTopic: string | undefined;
196
- timestamp: Date | undefined;
197
- rateLimitProof: RateLimitProof | undefined;
198
- ephemeral: boolean | undefined;
199
- }
200
-
201
- export interface Decoder<T extends DecodedMessage> {
202
- contentTopic: string;
203
- fromWireToProtoObj: (bytes: Uint8Array) => Promise<ProtoMessage | undefined>;
204
- fromProtoObj: (proto: ProtoMessage) => Promise<T | undefined>;
205
- }
206
-
207
- export interface SendResult {
208
- recipients: PeerId[];
209
- }
1
+ export * from "./enr.js";
2
+ export * from "./filter.js";
3
+ export * from "./light_push.js";
4
+ export * from "./message.js";
5
+ export * from "./peer_exchange.js";
6
+ export * from "./protocols.js";
7
+ export * from "./relay.js";
8
+ export * from "./store.js";
9
+ 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,33 @@
1
+ import type { ConnectionManager } from "@libp2p/interface-connection-manager";
2
+ import type { PeerId } from "@libp2p/interface-peer-id";
3
+ import type { PeerStore } from "@libp2p/interface-peer-store";
4
+ import type { Registrar } from "@libp2p/interface-registrar";
5
+
6
+ import { IEnr } from "./enr.js";
7
+ import { PointToPointProtocol } from "./protocols.js";
8
+
9
+ export interface IPeerExchange extends PointToPointProtocol {
10
+ query(
11
+ params: PeerExchangeQueryParams,
12
+ callback: (response: PeerExchangeResponse) => Promise<void> | void
13
+ ): Promise<void>;
14
+ }
15
+
16
+ export interface PeerExchangeQueryParams {
17
+ numPeers: number;
18
+ peerId?: PeerId;
19
+ }
20
+
21
+ export interface PeerExchangeResponse {
22
+ peerInfos: PeerInfo[];
23
+ }
24
+
25
+ export interface PeerInfo {
26
+ ENR?: IEnr;
27
+ }
28
+
29
+ export interface PeerExchangeComponents {
30
+ connectionManager: ConnectionManager;
31
+ peerStore: PeerStore;
32
+ registrar: Registrar;
33
+ }
@@ -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
+ }