@libp2p/interface-compliance-tests 2.0.3 → 3.0.2

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.
Files changed (192) hide show
  1. package/README.md +23 -11
  2. package/dist/src/{utils/is-valid-tick.d.ts → is-valid-tick.d.ts} +0 -0
  3. package/dist/src/is-valid-tick.d.ts.map +1 -0
  4. package/dist/src/{utils/is-valid-tick.js → is-valid-tick.js} +0 -0
  5. package/dist/src/is-valid-tick.js.map +1 -0
  6. package/dist/src/{utils/peers.d.ts → peers.d.ts} +0 -0
  7. package/dist/src/peers.d.ts.map +1 -0
  8. package/dist/src/{utils/peers.js → peers.js} +0 -0
  9. package/dist/src/peers.js.map +1 -0
  10. package/package.json +11 -89
  11. package/src/{utils/is-valid-tick.ts → is-valid-tick.ts} +0 -0
  12. package/src/{utils/peers.ts → peers.ts} +0 -0
  13. package/dist/src/connection/connection.d.ts +0 -5
  14. package/dist/src/connection/connection.d.ts.map +0 -1
  15. package/dist/src/connection/connection.js +0 -146
  16. package/dist/src/connection/connection.js.map +0 -1
  17. package/dist/src/connection/index.d.ts +0 -5
  18. package/dist/src/connection/index.d.ts.map +0 -1
  19. package/dist/src/connection/index.js +0 -5
  20. package/dist/src/connection/index.js.map +0 -1
  21. package/dist/src/connection-encrypter/index.d.ts +0 -5
  22. package/dist/src/connection-encrypter/index.d.ts.map +0 -1
  23. package/dist/src/connection-encrypter/index.js +0 -77
  24. package/dist/src/connection-encrypter/index.js.map +0 -1
  25. package/dist/src/connection-encrypter/utils/index.d.ts +0 -3
  26. package/dist/src/connection-encrypter/utils/index.d.ts.map +0 -1
  27. package/dist/src/connection-encrypter/utils/index.js +0 -18
  28. package/dist/src/connection-encrypter/utils/index.js.map +0 -1
  29. package/dist/src/mocks/connection-encrypter.d.ts +0 -3
  30. package/dist/src/mocks/connection-encrypter.d.ts.map +0 -1
  31. package/dist/src/mocks/connection-encrypter.js +0 -93
  32. package/dist/src/mocks/connection-encrypter.js.map +0 -1
  33. package/dist/src/mocks/connection-gater.d.ts +0 -12
  34. package/dist/src/mocks/connection-gater.d.ts.map +0 -1
  35. package/dist/src/mocks/connection-gater.js +0 -14
  36. package/dist/src/mocks/connection-gater.js.map +0 -1
  37. package/dist/src/mocks/connection-manager.d.ts +0 -28
  38. package/dist/src/mocks/connection-manager.d.ts.map +0 -1
  39. package/dist/src/mocks/connection-manager.js +0 -107
  40. package/dist/src/mocks/connection-manager.js.map +0 -1
  41. package/dist/src/mocks/connection.d.ts +0 -18
  42. package/dist/src/mocks/connection.d.ts.map +0 -1
  43. package/dist/src/mocks/connection.js +0 -138
  44. package/dist/src/mocks/connection.js.map +0 -1
  45. package/dist/src/mocks/duplex.d.ts +0 -3
  46. package/dist/src/mocks/duplex.d.ts.map +0 -1
  47. package/dist/src/mocks/duplex.js +0 -7
  48. package/dist/src/mocks/duplex.js.map +0 -1
  49. package/dist/src/mocks/index.d.ts +0 -10
  50. package/dist/src/mocks/index.d.ts.map +0 -1
  51. package/dist/src/mocks/index.js +0 -9
  52. package/dist/src/mocks/index.js.map +0 -1
  53. package/dist/src/mocks/multiaddr-connection.d.ts +0 -17
  54. package/dist/src/mocks/multiaddr-connection.d.ts.map +0 -1
  55. package/dist/src/mocks/multiaddr-connection.js +0 -51
  56. package/dist/src/mocks/multiaddr-connection.js.map +0 -1
  57. package/dist/src/mocks/muxer.d.ts +0 -9
  58. package/dist/src/mocks/muxer.d.ts.map +0 -1
  59. package/dist/src/mocks/muxer.js +0 -302
  60. package/dist/src/mocks/muxer.js.map +0 -1
  61. package/dist/src/mocks/registrar.d.ts +0 -18
  62. package/dist/src/mocks/registrar.d.ts.map +0 -1
  63. package/dist/src/mocks/registrar.js +0 -73
  64. package/dist/src/mocks/registrar.js.map +0 -1
  65. package/dist/src/mocks/upgrader.d.ts +0 -15
  66. package/dist/src/mocks/upgrader.d.ts.map +0 -1
  67. package/dist/src/mocks/upgrader.js +0 -33
  68. package/dist/src/mocks/upgrader.js.map +0 -1
  69. package/dist/src/peer-discovery/index.d.ts +0 -6
  70. package/dist/src/peer-discovery/index.d.ts.map +0 -1
  71. package/dist/src/peer-discovery/index.js +0 -64
  72. package/dist/src/peer-discovery/index.js.map +0 -1
  73. package/dist/src/pubsub/api.d.ts +0 -6
  74. package/dist/src/pubsub/api.d.ts.map +0 -1
  75. package/dist/src/pubsub/api.js +0 -87
  76. package/dist/src/pubsub/api.js.map +0 -1
  77. package/dist/src/pubsub/connection-handlers.d.ts +0 -6
  78. package/dist/src/pubsub/connection-handlers.d.ts.map +0 -1
  79. package/dist/src/pubsub/connection-handlers.js +0 -329
  80. package/dist/src/pubsub/connection-handlers.js.map +0 -1
  81. package/dist/src/pubsub/emit-self.d.ts +0 -6
  82. package/dist/src/pubsub/emit-self.d.ts.map +0 -1
  83. package/dist/src/pubsub/emit-self.js +0 -86
  84. package/dist/src/pubsub/emit-self.js.map +0 -1
  85. package/dist/src/pubsub/index.d.ts +0 -10
  86. package/dist/src/pubsub/index.d.ts.map +0 -1
  87. package/dist/src/pubsub/index.js +0 -17
  88. package/dist/src/pubsub/index.js.map +0 -1
  89. package/dist/src/pubsub/messages.d.ts +0 -6
  90. package/dist/src/pubsub/messages.d.ts.map +0 -1
  91. package/dist/src/pubsub/messages.js +0 -46
  92. package/dist/src/pubsub/messages.js.map +0 -1
  93. package/dist/src/pubsub/multiple-nodes.d.ts +0 -6
  94. package/dist/src/pubsub/multiple-nodes.d.ts.map +0 -1
  95. package/dist/src/pubsub/multiple-nodes.js +0 -350
  96. package/dist/src/pubsub/multiple-nodes.js.map +0 -1
  97. package/dist/src/pubsub/two-nodes.d.ts +0 -6
  98. package/dist/src/pubsub/two-nodes.d.ts.map +0 -1
  99. package/dist/src/pubsub/two-nodes.js +0 -185
  100. package/dist/src/pubsub/two-nodes.js.map +0 -1
  101. package/dist/src/pubsub/utils.d.ts +0 -6
  102. package/dist/src/pubsub/utils.d.ts.map +0 -1
  103. package/dist/src/pubsub/utils.js +0 -22
  104. package/dist/src/pubsub/utils.js.map +0 -1
  105. package/dist/src/record/index.d.ts +0 -5
  106. package/dist/src/record/index.d.ts.map +0 -1
  107. package/dist/src/record/index.js +0 -25
  108. package/dist/src/record/index.js.map +0 -1
  109. package/dist/src/stream-muxer/base-test.d.ts +0 -5
  110. package/dist/src/stream-muxer/base-test.d.ts.map +0 -1
  111. package/dist/src/stream-muxer/base-test.js +0 -147
  112. package/dist/src/stream-muxer/base-test.js.map +0 -1
  113. package/dist/src/stream-muxer/close-test.d.ts +0 -5
  114. package/dist/src/stream-muxer/close-test.d.ts.map +0 -1
  115. package/dist/src/stream-muxer/close-test.js +0 -180
  116. package/dist/src/stream-muxer/close-test.js.map +0 -1
  117. package/dist/src/stream-muxer/index.d.ts +0 -5
  118. package/dist/src/stream-muxer/index.d.ts.map +0 -1
  119. package/dist/src/stream-muxer/index.js +0 -13
  120. package/dist/src/stream-muxer/index.js.map +0 -1
  121. package/dist/src/stream-muxer/mega-stress-test.d.ts +0 -5
  122. package/dist/src/stream-muxer/mega-stress-test.d.ts.map +0 -1
  123. package/dist/src/stream-muxer/mega-stress-test.js +0 -12
  124. package/dist/src/stream-muxer/mega-stress-test.js.map +0 -1
  125. package/dist/src/stream-muxer/spawner.d.ts +0 -4
  126. package/dist/src/stream-muxer/spawner.d.ts.map +0 -1
  127. package/dist/src/stream-muxer/spawner.js +0 -34
  128. package/dist/src/stream-muxer/spawner.js.map +0 -1
  129. package/dist/src/stream-muxer/stress-test.d.ts +0 -5
  130. package/dist/src/stream-muxer/stress-test.d.ts.map +0 -1
  131. package/dist/src/stream-muxer/stress-test.js +0 -26
  132. package/dist/src/stream-muxer/stress-test.js.map +0 -1
  133. package/dist/src/topology/topology.d.ts +0 -5
  134. package/dist/src/topology/topology.d.ts.map +0 -1
  135. package/dist/src/topology/topology.js +0 -20
  136. package/dist/src/topology/topology.js.map +0 -1
  137. package/dist/src/transport/dial-test.d.ts +0 -5
  138. package/dist/src/transport/dial-test.d.ts.map +0 -1
  139. package/dist/src/transport/dial-test.js +0 -97
  140. package/dist/src/transport/dial-test.js.map +0 -1
  141. package/dist/src/transport/filter-test.d.ts +0 -5
  142. package/dist/src/transport/filter-test.d.ts.map +0 -1
  143. package/dist/src/transport/filter-test.js +0 -18
  144. package/dist/src/transport/filter-test.js.map +0 -1
  145. package/dist/src/transport/index.d.ts +0 -15
  146. package/dist/src/transport/index.d.ts.map +0 -1
  147. package/dist/src/transport/index.js +0 -11
  148. package/dist/src/transport/index.js.map +0 -1
  149. package/dist/src/transport/listen-test.d.ts +0 -5
  150. package/dist/src/transport/listen-test.d.ts.map +0 -1
  151. package/dist/src/transport/listen-test.js +0 -152
  152. package/dist/src/transport/listen-test.js.map +0 -1
  153. package/dist/src/utils/is-valid-tick.d.ts.map +0 -1
  154. package/dist/src/utils/is-valid-tick.js.map +0 -1
  155. package/dist/src/utils/peers.d.ts.map +0 -1
  156. package/dist/src/utils/peers.js.map +0 -1
  157. package/src/connection/README.md +0 -256
  158. package/src/connection/connection.ts +0 -176
  159. package/src/connection/index.ts +0 -7
  160. package/src/connection-encrypter/index.ts +0 -104
  161. package/src/connection-encrypter/utils/index.ts +0 -23
  162. package/src/mocks/connection-encrypter.ts +0 -110
  163. package/src/mocks/connection-gater.ts +0 -14
  164. package/src/mocks/connection-manager.ts +0 -141
  165. package/src/mocks/connection.ts +0 -205
  166. package/src/mocks/duplex.ts +0 -8
  167. package/src/mocks/index.ts +0 -10
  168. package/src/mocks/multiaddr-connection.ts +0 -66
  169. package/src/mocks/muxer.ts +0 -424
  170. package/src/mocks/registrar.ts +0 -96
  171. package/src/mocks/upgrader.ts +0 -46
  172. package/src/peer-discovery/index.ts +0 -89
  173. package/src/pubsub/api.ts +0 -115
  174. package/src/pubsub/connection-handlers.ts +0 -413
  175. package/src/pubsub/emit-self.ts +0 -105
  176. package/src/pubsub/index.ts +0 -25
  177. package/src/pubsub/messages.ts +0 -58
  178. package/src/pubsub/multiple-nodes.ts +0 -429
  179. package/src/pubsub/two-nodes.ts +0 -235
  180. package/src/pubsub/utils.ts +0 -28
  181. package/src/record/index.ts +0 -32
  182. package/src/stream-muxer/base-test.ts +0 -190
  183. package/src/stream-muxer/close-test.ts +0 -227
  184. package/src/stream-muxer/index.ts +0 -15
  185. package/src/stream-muxer/mega-stress-test.ts +0 -15
  186. package/src/stream-muxer/spawner.ts +0 -52
  187. package/src/stream-muxer/stress-test.ts +0 -29
  188. package/src/topology/topology.ts +0 -25
  189. package/src/transport/dial-test.ts +0 -123
  190. package/src/transport/filter-test.ts +0 -25
  191. package/src/transport/index.ts +0 -25
  192. package/src/transport/listen-test.ts +0 -191
package/README.md CHANGED
@@ -1,25 +1,37 @@
1
- # libp2p-interfaces-compliance-tests <!-- omit in toc -->
1
+ # @libp2p/interface-compliance-tests <!-- omit in toc -->
2
2
 
3
- > Contains test suites you should use to implement the various components of libp2p
3
+ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
+ [![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
5
+ [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
6
+ [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces)
7
+ [![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml)
8
+
9
+ > Compliance tests for JS libp2p interfaces
4
10
 
5
11
  ## Table of contents <!-- omit in toc -->
6
12
 
13
+ - [Install](#install)
7
14
  - [Usage](#usage)
8
- - [Contribute](#contribute)
9
15
  - [License](#license)
16
+ - [Contribution](#contribution)
17
+
18
+ ## Install
19
+
20
+ ```console
21
+ $ npm i @libp2p/interface-compliance-tests
22
+ ```
10
23
 
11
24
  ## Usage
12
25
 
13
- Each [interface](../interfaces) has its documentation on how to use the compliance tests and should be used as the source of truth.
26
+ Each [interface](https://npmjs.org/packages/@libp2p/interfaces) has its documentation on how to use the compliance tests and should be used as the source of truth.
14
27
 
15
- ## Contribute
28
+ ## License
16
29
 
17
- The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:
30
+ Licensed under either of
18
31
 
19
- - Go through the modules and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
20
- - **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
21
- - **Add tests**. There can never be enough tests.
32
+ - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
33
+ - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
22
34
 
23
- ## License
35
+ ## Contribution
24
36
 
25
- [Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) © Protocol Labs
37
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-valid-tick.d.ts","sourceRoot":"","sources":["../../src/is-valid-tick.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,wBAAgB,WAAW,CAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAE,MAAa,WAY5D"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-valid-tick.js","sourceRoot":"","sources":["../../src/is-valid-tick.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAE,IAAa,EAAE,KAAa,IAAI;IAC3D,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACzC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAEtB,IAAI,IAAI,GAAG,GAAG,GAAG,EAAE,IAAI,IAAI,IAAI,GAAG,EAAE;QAClC,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peers.d.ts","sourceRoot":"","sources":["../../src/peers.ts"],"names":[],"mappings":";;;;;AAAA,wBAwBE"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peers.js","sourceRoot":"","sources":["../../src/peers.ts"],"names":[],"mappings":"AAAA,eAAe,CAAC;QACd,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,0jDAA0jD;QACnkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@libp2p/interface-compliance-tests",
3
- "version": "2.0.3",
3
+ "version": "3.0.2",
4
4
  "description": "Compliance tests for JS libp2p interfaces",
5
5
  "license": "Apache-2.0 OR MIT",
6
- "homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interface-compliance-tests#readme",
6
+ "homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interface-compliance-tests#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/libp2p/js-libp2p-interfaces.git"
@@ -45,56 +45,16 @@
45
45
  ],
46
46
  "exports": {
47
47
  ".": {
48
- "import": "./dist/src/index.js",
49
- "types": "./dist/src/index.d.ts"
48
+ "types": "./dist/src/index.d.ts",
49
+ "import": "./dist/src/index.js"
50
50
  },
51
- "./connection": {
52
- "import": "./dist/src/connection/index.js",
53
- "types": "./dist/src/connection/index.d.ts"
51
+ "./is-valid-tick": {
52
+ "types": "./dist/src/is-valid-tick.d.ts",
53
+ "import": "./dist/src/is-valid-tick.js"
54
54
  },
55
- "./connection-encrypter": {
56
- "import": "./dist/src/connection-encrypter/index.js",
57
- "types": "./dist/src/connection-encrypter/index.d.ts"
58
- },
59
- "./mocks": {
60
- "import": "./dist/src/mocks/index.js",
61
- "types": "./dist/src/mocks/index.d.ts"
62
- },
63
- "./peer-discovery": {
64
- "import": "./dist/src/peer-discovery/index.js",
65
- "types": "./dist/src/peer-discovery/index.d.ts"
66
- },
67
- "./pubsub": {
68
- "import": "./dist/src/pubsub/index.js",
69
- "types": "./dist/src/pubsub/index.d.ts"
70
- },
71
- "./record": {
72
- "import": "./dist/src/record/index.js",
73
- "types": "./dist/src/record/index.d.ts"
74
- },
75
- "./stream-muxer": {
76
- "import": "./dist/src/stream-muxer/index.js",
77
- "types": "./dist/src/stream-muxer/index.d.ts"
78
- },
79
- "./topology": {
80
- "import": "./dist/src/topology/topology.js",
81
- "types": "./dist/src/topology/topology.d.ts"
82
- },
83
- "./topology/multicodec-toplogy": {
84
- "import": "./dist/src/topology/multicodec-toplogy.js",
85
- "types": "./dist/src/topology/multicodec-toplogy.d.ts"
86
- },
87
- "./transport": {
88
- "import": "./dist/src/transport/index.js",
89
- "types": "./dist/src/transport/index.d.ts"
90
- },
91
- "./transport/utils": {
92
- "import": "./dist/src/transport/utils/index.js",
93
- "types": "./dist/src/transport/utils/index.d.ts"
94
- },
95
- "./utils/peers": {
96
- "import": "./dist/src/utils/peers.js",
97
- "types": "./dist/src/utils/peers.d.ts"
55
+ "./peers": {
56
+ "types": "./dist/src/peers.d.ts",
57
+ "import": "./dist/src/peers.js"
98
58
  }
99
59
  },
100
60
  "eslintConfig": {
@@ -189,47 +149,9 @@
189
149
  "lint": "aegir lint",
190
150
  "dep-check": "aegir dep-check",
191
151
  "build": "aegir build",
192
- "test": "aegir test",
193
- "test:chrome": "aegir test -t browser --cov",
194
- "test:chrome-webworker": "aegir test -t webworker",
195
- "test:firefox": "aegir test -t browser -- --browser firefox",
196
- "test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
197
- "test:node": "aegir test -t node --cov",
198
- "test:electron-main": "aegir test -t electron-main",
199
152
  "release": "aegir release"
200
153
  },
201
154
  "dependencies": {
202
- "@libp2p/crypto": "^0.22.8",
203
- "@libp2p/interfaces": "^2.0.0",
204
- "@libp2p/logger": "^1.1.0",
205
- "@libp2p/multistream-select": "^1.0.0",
206
- "@libp2p/peer-id": "^1.1.0",
207
- "@libp2p/peer-id-factory": "^1.0.0",
208
- "@libp2p/pubsub": "^1.2.0",
209
- "@multiformats/multiaddr": "^10.1.5",
210
- "abortable-iterator": "^4.0.2",
211
- "aegir": "^37.0.7",
212
- "any-signal": "^3.0.0",
213
- "delay": "^5.0.0",
214
- "err-code": "^3.0.1",
215
- "it-all": "^1.0.6",
216
- "it-drain": "^1.0.5",
217
- "it-goodbye": "^4.0.1",
218
- "it-handshake": "^3.0.1",
219
- "it-map": "^1.0.6",
220
- "it-ndjson": "^0.1.1",
221
- "it-pair": "^2.0.2",
222
- "it-pipe": "^2.0.3",
223
- "it-pushable": "^2.0.1",
224
- "it-stream-types": "^1.0.4",
225
- "multiformats": "^9.6.3",
226
- "p-defer": "^4.0.0",
227
- "p-event": "^5.0.1",
228
- "p-limit": "^4.0.0",
229
- "p-wait-for": "^4.1.0",
230
- "sinon": "^14.0.0",
231
- "uint8arraylist": "^1.5.1",
232
- "uint8arrays": "^3.0.0",
233
- "util": "^0.12.4"
155
+ "aegir": "^37.4.0"
234
156
  }
235
157
  }
File without changes
File without changes
@@ -1,5 +0,0 @@
1
- import type { TestSetup } from '../index.js';
2
- import type { Connection } from '@libp2p/interfaces/connection';
3
- declare const _default: (test: TestSetup<Connection>) => void;
4
- export default _default;
5
- //# sourceMappingURL=connection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/connection/connection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;+BAEzC,UAAU,UAAU,CAAC;AAA3C,wBA0KC"}
@@ -1,146 +0,0 @@
1
- import { expect } from 'aegir/chai';
2
- import sinon from 'sinon';
3
- export default (test) => {
4
- describe('connection', () => {
5
- describe('open connection', () => {
6
- let connection;
7
- beforeEach(async () => {
8
- connection = await test.setup();
9
- });
10
- afterEach(async () => {
11
- await connection.close();
12
- await test.teardown();
13
- });
14
- it('should have properties set', () => {
15
- expect(connection.id).to.exist();
16
- expect(connection.remotePeer).to.exist();
17
- expect(connection.remoteAddr).to.exist();
18
- expect(connection.stat.status).to.equal('OPEN');
19
- expect(connection.stat.timeline.open).to.exist();
20
- expect(connection.stat.timeline.upgraded).to.exist();
21
- expect(connection.stat.timeline.close).to.not.exist();
22
- expect(connection.stat.direction).to.exist();
23
- expect(connection.streams).to.eql([]);
24
- expect(connection.tags).to.eql([]);
25
- });
26
- it('should get the metadata of an open connection', () => {
27
- const stat = connection.stat;
28
- expect(stat.status).to.equal('OPEN');
29
- expect(stat.direction).to.exist();
30
- expect(stat.timeline.open).to.exist();
31
- expect(stat.timeline.upgraded).to.exist();
32
- expect(stat.timeline.close).to.not.exist();
33
- });
34
- it('should return an empty array of streams', () => {
35
- const streams = connection.streams;
36
- expect(streams).to.eql([]);
37
- });
38
- it('should be able to create a new stream', async () => {
39
- const protocolToUse = '/echo/0.0.1';
40
- const { stream, protocol } = await connection.newStream([protocolToUse]);
41
- expect(protocol).to.equal(protocolToUse);
42
- const connStreams = await connection.streams;
43
- expect(stream).to.exist();
44
- expect(connStreams).to.exist();
45
- expect(connStreams).to.have.lengthOf(1);
46
- expect(connStreams[0]).to.equal(stream);
47
- });
48
- });
49
- describe('close connection', () => {
50
- let connection;
51
- let timelineProxy;
52
- const proxyHandler = {
53
- set() {
54
- // @ts-expect-error - TS fails to infer here
55
- return Reflect.set(...arguments);
56
- }
57
- };
58
- beforeEach(async () => {
59
- timelineProxy = new Proxy({
60
- open: Date.now() - 10,
61
- upgraded: Date.now()
62
- }, proxyHandler);
63
- connection = await test.setup({
64
- stat: {
65
- timeline: timelineProxy,
66
- direction: 'outbound',
67
- encryption: '/crypto/1.0.0',
68
- multiplexer: '/muxer/1.0.0'
69
- }
70
- });
71
- });
72
- afterEach(async () => {
73
- await test.teardown();
74
- });
75
- it('should be able to close the connection after being created', async () => {
76
- expect(connection.stat.timeline.close).to.not.exist();
77
- await connection.close();
78
- expect(connection.stat.timeline.close).to.exist();
79
- expect(connection.stat.status).to.equal('CLOSED');
80
- });
81
- it('should be able to close the connection after opening a stream', async () => {
82
- // Open stream
83
- const protocol = '/echo/0.0.1';
84
- await connection.newStream([protocol]);
85
- // Close connection
86
- expect(connection.stat.timeline.close).to.not.exist();
87
- await connection.close();
88
- expect(connection.stat.timeline.close).to.exist();
89
- expect(connection.stat.status).to.equal('CLOSED');
90
- });
91
- it('should properly track streams', async () => {
92
- // Open stream
93
- const protocol = '/echo/0.0.1';
94
- const { stream } = await connection.newStream([protocol]);
95
- const trackedStream = connection.registry.get(stream.id);
96
- expect(trackedStream).to.have.property('protocol', protocol);
97
- // Close stream
98
- await stream.close();
99
- expect(connection.registry.get(stream.id)).to.not.exist();
100
- });
101
- it('should support a proxy on the timeline', async () => {
102
- sinon.spy(proxyHandler, 'set');
103
- expect(connection.stat.timeline.close).to.not.exist();
104
- await connection.close();
105
- // @ts-expect-error - fails to infer callCount
106
- expect(proxyHandler.set.callCount).to.equal(1);
107
- // @ts-expect-error - fails to infer getCall
108
- const [obj, key, value] = proxyHandler.set.getCall(0).args;
109
- expect(obj).to.eql(connection.stat.timeline);
110
- expect(key).to.equal('close');
111
- expect(value).to.be.a('number').that.equals(connection.stat.timeline.close);
112
- });
113
- it('should fail to create a new stream if the connection is closing', async () => {
114
- expect(connection.stat.timeline.close).to.not.exist();
115
- const p = connection.close();
116
- try {
117
- const protocol = '/echo/0.0.1';
118
- await connection.newStream([protocol]);
119
- }
120
- catch (err) {
121
- expect(err).to.exist();
122
- return;
123
- }
124
- finally {
125
- await p;
126
- }
127
- throw new Error('should fail to create a new stream if the connection is closing');
128
- });
129
- it('should fail to create a new stream if the connection is closed', async () => {
130
- expect(connection.stat.timeline.close).to.not.exist();
131
- await connection.close();
132
- try {
133
- const protocol = '/echo/0.0.1';
134
- await connection.newStream([protocol]);
135
- }
136
- catch (err) {
137
- expect(err).to.exist();
138
- expect(err.code).to.equal('ERR_CONNECTION_CLOSED');
139
- return;
140
- }
141
- throw new Error('should fail to create a new stream if the connection is closing');
142
- });
143
- });
144
- });
145
- };
146
- //# sourceMappingURL=connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/connection/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAe,CAAC,IAA2B,EAAE,EAAE;IAC7C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;YAC/B,IAAI,UAAsB,CAAA;YAE1B,UAAU,CAAC,KAAK,IAAI,EAAE;gBACpB,UAAU,GAAG,MAAM,IAAI,CAAC,K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AE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;gBACrD,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAA;gBAE5B,IAAI;oBACF,MAAM,QAAQ,GAAG,aAAa,CAAA;oBAC9B,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA;iBACvC;gBAAC,OAAO,GAAQ,EAAE;oBACjB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;oBACtB,OAAM;iBACP;wBAAS;oBACR,MAAM,CAAC,CAAA;iBACR;gBAED,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;YACpF,CAAC,CAAC,CAAA;YAEF,EAAE,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;gBAC9E,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;gBACrD,MAAM,UAAU,CAAC,KAAK,EAAE,CAAA;gBAExB,IAAI;oBACF,MAAM,QAAQ,GAAG,aAAa,CAAA;oBAC9B,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA;iBACvC;gBAAC,OAAO,GAAQ,EAAE;oBACjB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;oBACtB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;oBAClD,OAAM;iBACP;gBAED,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;YACpF,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -1,5 +0,0 @@
1
- import type { TestSetup } from '../index.js';
2
- import type { Connection } from '@libp2p/interfaces/connection';
3
- declare const _default: (test: TestSetup<Connection>) => void;
4
- export default _default;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;+BAEzC,UAAU,UAAU,CAAC;AAA3C,wBAEC"}
@@ -1,5 +0,0 @@
1
- import connectionSuite from './connection.js';
2
- export default (test) => {
3
- connectionSuite(test);
4
- };
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,iBAAiB,CAAA;AAI7C,eAAe,CAAC,IAA2B,EAAE,EAAE;IAC7C,eAAe,CAAC,IAAI,CAAC,CAAA;AACvB,CAAC,CAAA"}
@@ -1,5 +0,0 @@
1
- import type { TestSetup } from '../index.js';
2
- import type { ConnectionEncrypter } from '@libp2p/interfaces/connection-encrypter';
3
- declare const _default: (common: TestSetup<ConnectionEncrypter>) => void;
4
- export default _default;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-encrypter/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;iCAI1D,UAAU,mBAAmB,CAAC;AAAtD,wBA0FC"}
@@ -1,77 +0,0 @@
1
- import { expect } from 'aegir/chai';
2
- import { pipe } from 'it-pipe';
3
- import * as PeerIdFactory from '@libp2p/peer-id-factory';
4
- import all from 'it-all';
5
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
6
- import peers from '../utils/peers.js';
7
- import { UnexpectedPeerError } from '@libp2p/interfaces/connection-encrypter/errors';
8
- import { createMaConnPair } from './utils/index.js';
9
- export default (common) => {
10
- describe('interface-connection-encrypter compliance tests', () => {
11
- let crypto;
12
- let localPeer;
13
- let remotePeer;
14
- let mitmPeer;
15
- before(async () => {
16
- [
17
- crypto,
18
- localPeer,
19
- remotePeer,
20
- mitmPeer
21
- ] = await Promise.all([
22
- common.setup(),
23
- PeerIdFactory.createFromJSON(peers[0]),
24
- PeerIdFactory.createFromJSON(peers[1]),
25
- PeerIdFactory.createFromJSON(peers[2])
26
- ]);
27
- });
28
- after(async () => {
29
- await common.teardown();
30
- });
31
- it('has a protocol string', () => {
32
- expect(crypto.protocol).to.exist();
33
- expect(crypto.protocol).to.be.a('string');
34
- });
35
- it('it wraps the provided duplex connection', async () => {
36
- const [localConn, remoteConn] = createMaConnPair();
37
- const [inboundResult, outboundResult] = await Promise.all([
38
- crypto.secureInbound(remotePeer, localConn),
39
- crypto.secureOutbound(localPeer, remoteConn, remotePeer)
40
- ]);
41
- // Echo server
42
- void pipe(inboundResult.conn, inboundResult.conn);
43
- // Send some data and collect the result
44
- const input = uint8ArrayFromString('data to encrypt');
45
- const result = await pipe([input], outboundResult.conn,
46
- // Convert BufferList to Buffer via slice
47
- (source) => (async function* toBuffer() {
48
- for await (const chunk of source) {
49
- yield chunk.slice();
50
- }
51
- })(), async (source) => await all(source));
52
- expect(result).to.eql([input]);
53
- });
54
- it('should return the remote peer id', async () => {
55
- const [localConn, remoteConn] = createMaConnPair();
56
- const [inboundResult, outboundResult] = await Promise.all([
57
- crypto.secureInbound(remotePeer, localConn),
58
- crypto.secureOutbound(localPeer, remoteConn, remotePeer)
59
- ]);
60
- // Inbound should return the initiator (local) peer
61
- expect(inboundResult.remotePeer.toBytes()).to.equalBytes(localPeer.toBytes());
62
- // Outbound should return the receiver (remote) peer
63
- expect(outboundResult.remotePeer.toBytes()).to.equalBytes(remotePeer.toBytes());
64
- });
65
- it('inbound connections should verify peer integrity if known', async () => {
66
- const [localConn, remoteConn] = createMaConnPair();
67
- await Promise.all([
68
- crypto.secureInbound(remotePeer, localConn, mitmPeer),
69
- crypto.secureOutbound(localPeer, remoteConn, remotePeer)
70
- ]).then(() => expect.fail(), (err) => {
71
- expect(err).to.exist();
72
- expect(err).to.have.property('code', UnexpectedPeerError.code);
73
- });
74
- });
75
- });
76
- };
77
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection-encrypter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,MAAM,mBAAmB,CAAA;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAA;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAMnD,eAAe,CAAC,MAAsC,EAAE,EAAE;IACxD,QAAQ,CAAC,iDAAiD,EAAE,GAAG,EAAE;QAC/D,IAAI,MAA2B,CAAA;QAC/B,IAAI,SAAiB,CAAA;QACrB,IAAI,UAAkB,CAAA;QACtB,IAAI,QAAgB,CAAA;QAEpB,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB;gBACE,MAAM;gBACN,SAAS;gBACT,UAAU;gBACV,QAAQ;aACT,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACpB,MAAM,CAAC,KAAK,EAAE;gBACd,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACtC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACtC,aAAa,CAAC,cAAc,CAAC,K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gBACnC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;gBACtB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAA;YAChE,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { MultiaddrConnection } from '@libp2p/interfaces/transport';
2
- export declare function createMaConnPair(): [MultiaddrConnection, MultiaddrConnection];
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/connection-encrypter/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAGvE,wBAAgB,gBAAgB,IAAK,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAiB9E"}
@@ -1,18 +0,0 @@
1
- import { duplexPair } from 'it-pair/duplex';
2
- import { Multiaddr } from '@multiformats/multiaddr';
3
- export function createMaConnPair() {
4
- const [local, remote] = duplexPair();
5
- function duplexToMaConn(duplex) {
6
- const output = {
7
- ...duplex,
8
- close: async () => { },
9
- remoteAddr: new Multiaddr('/ip4/127.0.0.1/tcp/4001'),
10
- timeline: {
11
- open: Date.now()
12
- }
13
- };
14
- return output;
15
- }
16
- return [duplexToMaConn(local), duplexToMaConn(remote)];
17
- }
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/connection-encrypter/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAInD,MAAM,UAAU,gBAAgB;IAC9B,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,UAAU,EAAc,CAAA;IAEhD,SAAS,cAAc,CAAE,MAA0B;QACjD,MAAM,MAAM,GAAwB;YAClC,GAAG,MAAM;YACT,KAAK,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;YACrB,UAAU,EAAE,IAAI,SAAS,CAAC,yBAAyB,CAAC;YACpD,QAAQ,EAAE;gBACR,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;aACjB;SACF,CAAA;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAA;AACxD,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { ConnectionEncrypter } from '@libp2p/interfaces/connection-encrypter';
2
- export declare function mockConnectionEncrypter(): ConnectionEncrypter;
3
- //# sourceMappingURL=connection-encrypter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection-encrypter.d.ts","sourceRoot":"","sources":["../../../src/mocks/connection-encrypter.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;AAYlF,wBAAgB,uBAAuB,wBA2FtC"}
@@ -1,93 +0,0 @@
1
- import { peerIdFromBytes } from '@libp2p/peer-id';
2
- import { handshake } from 'it-handshake';
3
- import { duplexPair } from 'it-pair/duplex';
4
- import { pipe } from 'it-pipe';
5
- import { UnexpectedPeerError } from '@libp2p/interfaces/connection-encrypter/errors';
6
- import { Multiaddr } from '@multiformats/multiaddr';
7
- // A basic transform that does nothing to the data
8
- const transform = () => {
9
- return (source) => (async function* () {
10
- for await (const chunk of source) {
11
- yield chunk;
12
- }
13
- })();
14
- };
15
- export function mockConnectionEncrypter() {
16
- const encrypter = {
17
- protocol: 'insecure',
18
- secureInbound: async (localPeer, duplex, expectedPeer) => {
19
- // 1. Perform a basic handshake.
20
- const shake = handshake(duplex);
21
- shake.write(localPeer.toBytes());
22
- const remoteId = await shake.read();
23
- if (remoteId == null) {
24
- throw new Error('Could not read remote ID');
25
- }
26
- const remotePeer = peerIdFromBytes(remoteId.slice());
27
- shake.rest();
28
- if (expectedPeer != null && !expectedPeer.equals(remotePeer)) {
29
- throw new UnexpectedPeerError();
30
- }
31
- // 2. Create your encryption box/unbox wrapper
32
- const wrapper = duplexPair();
33
- const encrypt = transform(); // Use transform iterables to modify data
34
- const decrypt = transform();
35
- void pipe(wrapper[0], // We write to wrapper
36
- encrypt, // The data is encrypted
37
- shake.stream, // It goes to the remote peer
38
- decrypt, // Decrypt the incoming data
39
- wrapper[0] // Pipe to the wrapper
40
- );
41
- return {
42
- conn: {
43
- ...wrapper[1],
44
- close: async () => { },
45
- localAddr: new Multiaddr('/ip4/127.0.0.1/tcp/4001'),
46
- remoteAddr: new Multiaddr('/ip4/127.0.0.1/tcp/4002'),
47
- timeline: {
48
- open: Date.now()
49
- },
50
- conn: true
51
- },
52
- remotePeer,
53
- remoteEarlyData: new Uint8Array(0)
54
- };
55
- },
56
- secureOutbound: async (localPeer, duplex, remotePeer) => {
57
- // 1. Perform a basic handshake.
58
- const shake = handshake(duplex);
59
- shake.write(localPeer.toBytes());
60
- const remoteId = await shake.read();
61
- if (remoteId == null) {
62
- throw new Error('Could not read remote ID');
63
- }
64
- shake.rest();
65
- // 2. Create your encryption box/unbox wrapper
66
- const wrapper = duplexPair();
67
- const encrypt = transform();
68
- const decrypt = transform();
69
- void pipe(wrapper[0], // We write to wrapper
70
- encrypt, // The data is encrypted
71
- shake.stream, // It goes to the remote peer
72
- decrypt, // Decrypt the incoming data
73
- wrapper[0] // Pipe to the wrapper
74
- );
75
- return {
76
- conn: {
77
- ...wrapper[1],
78
- close: async () => { },
79
- localAddr: new Multiaddr('/ip4/127.0.0.1/tcp/4001'),
80
- remoteAddr: new Multiaddr('/ip4/127.0.0.1/tcp/4002'),
81
- timeline: {
82
- open: Date.now()
83
- },
84
- conn: true
85
- },
86
- remotePeer: peerIdFromBytes(remoteId.slice()),
87
- remoteEarlyData: new Uint8Array(0)
88
- };
89
- }
90
- };
91
- return encrypter;
92
- }
93
- //# sourceMappingURL=connection-encrypter.js.map