@waku/discovery 0.0.9-f7c290d.0 → 0.0.9

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/package.json CHANGED
@@ -1 +1,91 @@
1
- {"name":"@waku/discovery","version":"0.0.9-f7c290d.0","description":"Contains various discovery mechanisms: DNS Discovery (EIP-1459, Peer Exchange, Local Peer Cache Discovery.","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","author":"Waku Team","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/discovery#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralized","secure","communication","web3","ethereum","dapps","privacy"],"scripts":{"build":"run-s build:**","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:lint":"eslint src --ext .ts","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","check:tsc":"tsc -p tsconfig.dev.json","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build","test":"NODE_ENV=test run-s test:*","test:node":"NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha 'src/**/*.spec.ts'","test:browser":"NODE_ENV=test karma start karma.conf.cjs"},"engines":{"node":">=20"},"dependencies":{"@waku/core":"0.0.36-f7c290d.0","@waku/enr":"0.0.30-f7c290d.0","@waku/interfaces":"0.0.31-f7c290d.0","@waku/proto":"0.0.11-f7c290d.0","@waku/utils":"0.0.24-f7c290d.0","debug":"^4.3.4","dns-over-http-resolver":"^3.0.8","hi-base32":"^0.5.1","uint8arrays":"^5.0.1"},"devDependencies":{"@libp2p/interface":"^2.1.3","@libp2p/peer-id":"5.0.1","@multiformats/multiaddr":"^12.3.0","@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^4.3.11","@types/node-localstorage":"^1.3.3","@waku/build-utils":"*","chai":"^4.3.10","chai-as-promised":"^7.1.1","cspell":"^8.6.1","mocha":"^10.3.0","node-localstorage":"^3.0.5","npm-run-all":"^4.1.5","rollup":"^4.12.0","sinon":"^18.0.0"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
1
+ {
2
+ "name": "@waku/discovery",
3
+ "version": "0.0.9",
4
+ "description": "Contains various discovery mechanisms: DNS Discovery (EIP-1459, Peer Exchange, Local Peer Cache Discovery.",
5
+ "types": "./dist/index.d.ts",
6
+ "module": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "type": "module",
14
+ "author": "Waku Team",
15
+ "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/discovery#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/waku-org/js-waku.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/waku-org/js-waku/issues"
22
+ },
23
+ "license": "MIT OR Apache-2.0",
24
+ "keywords": [
25
+ "waku",
26
+ "decentralized",
27
+ "secure",
28
+ "communication",
29
+ "web3",
30
+ "ethereum",
31
+ "dapps",
32
+ "privacy"
33
+ ],
34
+ "scripts": {
35
+ "build": "run-s build:**",
36
+ "build:esm": "tsc",
37
+ "build:bundle": "rollup --config rollup.config.js",
38
+ "fix": "run-s fix:*",
39
+ "fix:lint": "eslint src *.js --fix",
40
+ "check": "run-s check:*",
41
+ "check:lint": "eslint src --ext .ts",
42
+ "check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
43
+ "check:tsc": "tsc -p tsconfig.dev.json",
44
+ "prepublish": "npm run build",
45
+ "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build",
46
+ "test": "NODE_ENV=test run-s test:*",
47
+ "test:node": "NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha 'src/**/*.spec.ts'",
48
+ "test:browser": "NODE_ENV=test karma start karma.conf.cjs"
49
+ },
50
+ "engines": {
51
+ "node": ">=22"
52
+ },
53
+ "dependencies": {
54
+ "@waku/core": "0.0.36",
55
+ "@waku/enr": "0.0.30",
56
+ "@waku/interfaces": "0.0.31",
57
+ "@waku/proto": "^0.0.11",
58
+ "@waku/utils": "0.0.24",
59
+ "debug": "^4.3.4",
60
+ "dns-over-http-resolver": "^3.0.8",
61
+ "hi-base32": "^0.5.1",
62
+ "uint8arrays": "^5.0.1"
63
+ },
64
+ "devDependencies": {
65
+ "@libp2p/interface": "2.10.4",
66
+ "@libp2p/peer-id": "5.1.7",
67
+ "@multiformats/multiaddr": "^12.3.0",
68
+ "@rollup/plugin-commonjs": "^25.0.7",
69
+ "@rollup/plugin-json": "^6.0.0",
70
+ "@rollup/plugin-node-resolve": "^15.2.3",
71
+ "@types/chai": "^4.3.11",
72
+ "@waku/build-utils": "*",
73
+ "chai": "^4.3.10",
74
+ "chai-as-promised": "^7.1.1",
75
+ "cspell": "^8.6.1",
76
+ "mocha": "^10.3.0",
77
+ "npm-run-all": "^4.1.5",
78
+ "rollup": "^4.12.0",
79
+ "sinon": "^18.0.0"
80
+ },
81
+ "files": [
82
+ "dist",
83
+ "bundle",
84
+ "src/**/*.ts",
85
+ "!**/*.spec.*",
86
+ "!**/*.json",
87
+ "CHANGELOG.md",
88
+ "LICENSE",
89
+ "README.md"
90
+ ]
91
+ }
@@ -1,12 +1,11 @@
1
- import { BaseProtocol } from "@waku/core/lib/base_protocol";
1
+ import { StreamManager } from "@waku/core";
2
2
  import { EnrDecoder } from "@waku/enr";
3
3
  import {
4
4
  IPeerExchange,
5
5
  Libp2pComponents,
6
6
  PeerExchangeQueryParams,
7
7
  PeerExchangeQueryResult,
8
- ProtocolError,
9
- PubsubTopic
8
+ ProtocolError
10
9
  } from "@waku/interfaces";
11
10
  import { isDefined } from "@waku/utils";
12
11
  import { Logger } from "@waku/utils";
@@ -24,15 +23,14 @@ const log = new Logger("peer-exchange");
24
23
  /**
25
24
  * Implementation of the Peer Exchange protocol (https://rfc.vac.dev/spec/34/)
26
25
  */
27
- export class WakuPeerExchange extends BaseProtocol implements IPeerExchange {
26
+ export class WakuPeerExchange implements IPeerExchange {
27
+ private readonly streamManager: StreamManager;
28
+
28
29
  /**
29
30
  * @param components - libp2p components
30
31
  */
31
- public constructor(
32
- components: Libp2pComponents,
33
- pubsubTopics: PubsubTopic[]
34
- ) {
35
- super(PeerExchangeCodec, components, pubsubTopics);
32
+ public constructor(private readonly components: Libp2pComponents) {
33
+ this.streamManager = new StreamManager(PeerExchangeCodec, components);
36
34
  }
37
35
 
38
36
  /**
@@ -57,7 +55,7 @@ export class WakuPeerExchange extends BaseProtocol implements IPeerExchange {
57
55
 
58
56
  let stream;
59
57
  try {
60
- stream = await this.getStream(peerId);
58
+ stream = await this.streamManager.getStream(peerId);
61
59
  } catch (err) {
62
60
  log.error("Failed to get stream", err);
63
61
  return {
@@ -118,9 +116,8 @@ export class WakuPeerExchange extends BaseProtocol implements IPeerExchange {
118
116
  *
119
117
  * @returns A function that creates a new peer exchange protocol
120
118
  */
121
- export function wakuPeerExchange(
122
- pubsubTopics: PubsubTopic[]
123
- ): (components: Libp2pComponents) => WakuPeerExchange {
124
- return (components: Libp2pComponents) =>
125
- new WakuPeerExchange(components, pubsubTopics);
119
+ export function wakuPeerExchange(): (
120
+ components: Libp2pComponents
121
+ ) => WakuPeerExchange {
122
+ return (components: Libp2pComponents) => new WakuPeerExchange(components);
126
123
  }
@@ -10,7 +10,6 @@ import type {
10
10
  import {
11
11
  type Libp2pComponents,
12
12
  type PeerExchangeQueryResult,
13
- PubsubTopic,
14
13
  ShardInfo,
15
14
  Tags
16
15
  } from "@waku/interfaces";
@@ -87,14 +86,10 @@ export class PeerExchangeDiscovery
87
86
  );
88
87
  };
89
88
 
90
- public constructor(
91
- components: Libp2pComponents,
92
- pubsubTopics: PubsubTopic[],
93
- options: Options = {}
94
- ) {
89
+ public constructor(components: Libp2pComponents, options: Options = {}) {
95
90
  super();
96
91
  this.components = components;
97
- this.peerExchange = new WakuPeerExchange(components, pubsubTopics);
92
+ this.peerExchange = new WakuPeerExchange(components);
98
93
  this.options = options;
99
94
  this.isStarted = false;
100
95
  }
@@ -314,9 +309,9 @@ export class PeerExchangeDiscovery
314
309
  }
315
310
  }
316
311
 
317
- export function wakuPeerExchangeDiscovery(
318
- pubsubTopics: PubsubTopic[]
319
- ): (components: Libp2pComponents) => PeerExchangeDiscovery {
312
+ export function wakuPeerExchangeDiscovery(): (
313
+ components: Libp2pComponents
314
+ ) => PeerExchangeDiscovery {
320
315
  return (components: Libp2pComponents) =>
321
- new PeerExchangeDiscovery(components, pubsubTopics);
316
+ new PeerExchangeDiscovery(components);
322
317
  }