Skip to content

Commit a364d95

Browse files
committed
refactor!: extract plaintext into separate module (#2221)
BREAKING CHANGE: imports from `libp2p/plaintext` should be changed to `@libp2p/plaintext`
1 parent d2c3e72 commit a364d95

39 files changed

+252
-39
lines changed

.release-please.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"group-pull-request-title-pattern": "chore: release ${component}",
44
"packages": {
55
"interop": {},
6+
"packages/connection-encrypter-plaintext": {},
67
"packages/crypto": {},
78
"packages/interface": {},
89
"packages/interface-compliance-tests": {},

doc/migrations/v0.46-v1.0.0.md

+35
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A migration guide for refactoring your application code from libp2p `v0.46` to `
1111
- [DCUtR](#dcutr)
1212
- [KeyChain](#keychain)
1313
- [UPnPNat](#upnpnat)
14+
- [Plaintext](#plaintext)
1415
- [Pnet](#pnet)
1516
- [Metrics](#metrics)
1617

@@ -167,6 +168,8 @@ const keychain: Keychain = libp2p.services.keychain
167168

168169
The UPnPNat service module is now published in its own package.
169170

171+
**Before**
172+
170173
```ts
171174
import { createLibp2p } from 'libp2p'
172175
import { uPnPNATService } from 'libp2p/upnp-nat'
@@ -191,6 +194,38 @@ const node = await createLibp2p({
191194
})
192195
```
193196

197+
## Plaintext
198+
199+
The Plaintext connection encrypter module is now published in its own package.
200+
201+
Note that it is still insecure and should not be used in production.
202+
203+
**Before**
204+
205+
```ts
206+
import { createLibp2p } from 'libp2p'
207+
import { plaintext } from 'libp2p/insecure'
208+
209+
const node = await createLibp2p({
210+
connectionEncryption: [
211+
plaintext: plaintext()
212+
]
213+
})
214+
```
215+
216+
**After**
217+
218+
```ts
219+
import { createLibp2p } from 'libp2p'
220+
import { plaintext } from '@libp2p/plaintext'
221+
222+
const node = await createLibp2p({
223+
connectionEncryption: [
224+
plaintext: plaintext()
225+
]
226+
})
227+
```
228+
194229
## Pnet
195230

196231
The pnet module is now published in its own package.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This project is dual licensed under MIT and Apache-2.0.
2+
3+
MIT: https://www.opensource.org/licenses/mit
4+
Apache-2.0: https://www.apache.org/licenses/license-2.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
2+
3+
http://www.apache.org/licenses/LICENSE-2.0
4+
5+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
2+
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
3+
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
4+
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster)
5+
6+
> An insecure connection encrypter
7+
8+
# About
9+
10+
A connection encrypter that does no connection encryption.
11+
12+
This should not be used in production should be used for research purposes only.
13+
14+
## Example
15+
16+
```typescript
17+
import { createLibp2p } from 'libp2p'
18+
import { plaintext } from '@libp2p/plaintext'
19+
20+
const node = await createLibp2p({
21+
// ...other options
22+
connectionEncryption: [
23+
plaintext()
24+
]
25+
})
26+
```
27+
28+
# Install
29+
30+
```console
31+
$ npm i @libp2p/plaintext
32+
```
33+
34+
## Browser `<script>` tag
35+
36+
Loading this module through a script tag will make it's exports available as `Libp2pPlaintext` in the global namespace.
37+
38+
```html
39+
<script src="https://unpkg.com/@libp2p/plaintext/dist/index.min.js"></script>
40+
```
41+
42+
> Implementation of the DCUtR Protocol
43+
44+
# API Docs
45+
46+
- <https://libp2p.github.io/js-libp2p/modules/_libp2p_plaintext.html>
47+
48+
# License
49+
50+
Licensed under either of
51+
52+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
53+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
54+
55+
# Contribution
56+
57+
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"name": "@libp2p/plaintext",
3+
"version": "0.0.0",
4+
"description": "An insecure connection encrypter",
5+
"license": "Apache-2.0 OR MIT",
6+
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/connection-encrypter-plaintext#readme",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/libp2p/js-libp2p.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/libp2p/js-libp2p/issues"
13+
},
14+
"type": "module",
15+
"types": "./dist/src/index.d.ts",
16+
"files": [
17+
"src",
18+
"dist",
19+
"!dist/test",
20+
"!**/*.tsbuildinfo"
21+
],
22+
"exports": {
23+
".": {
24+
"types": "./dist/src/index.d.ts",
25+
"import": "./dist/src/index.js"
26+
}
27+
},
28+
"eslintConfig": {
29+
"extends": "ipfs",
30+
"parserOptions": {
31+
"project": true,
32+
"sourceType": "module"
33+
}
34+
},
35+
"scripts": {
36+
"start": "node dist/src/main.js",
37+
"build": "aegir build",
38+
"test": "aegir test",
39+
"clean": "aegir clean",
40+
"generate": "protons ./src/pb/index.proto",
41+
"lint": "aegir lint",
42+
"test:chrome": "aegir test -t browser --cov",
43+
"test:chrome-webworker": "aegir test -t webworker",
44+
"test:firefox": "aegir test -t browser -- --browser firefox",
45+
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
46+
"test:node": "aegir test -t node --cov",
47+
"dep-check": "aegir dep-check"
48+
},
49+
"dependencies": {
50+
"@libp2p/interface": "^0.1.2",
51+
"@libp2p/peer-id": "^3.0.6",
52+
"@multiformats/multiaddr": "^12.1.5",
53+
"it-handshake": "^4.1.3",
54+
"it-length-prefixed": "^9.0.3",
55+
"it-map": "^3.0.4",
56+
"it-stream-types": "^2.0.1",
57+
"protons-runtime": "^5.0.0",
58+
"uint8arraylist": "^2.4.3"
59+
},
60+
"devDependencies": {
61+
"@libp2p/interface-compliance-tests": "^4.1.5",
62+
"@libp2p/logger": "^3.0.2",
63+
"@libp2p/peer-id-factory": "^3.0.8",
64+
"aegir": "^41.0.2",
65+
"protons": "^7.3.0",
66+
"sinon": "^17.0.0"
67+
}
68+
}

packages/libp2p/src/insecure/index.ts renamed to packages/connection-encrypter-plaintext/src/index.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
*
1010
* ```typescript
1111
* import { createLibp2p } from 'libp2p'
12-
* import { plaintext } from 'libp2p/insecure'
13-
*
14-
* // Create a Uint8Array and write the swarm key to it
15-
* const swarmKey = new Uint8Array(95)
16-
* generateKey(swarmKey)
12+
* import { plaintext } from '@libp2p/plaintext'
1713
*
1814
* const node = await createLibp2p({
1915
* // ...other options
20-
* connectionEncryption: [plaintext()]
16+
* connectionEncryption: [
17+
* plaintext()
18+
* ]
2119
* })
2220
* ```
2321
*/

packages/libp2p/test/insecure/compliance.spec.ts renamed to packages/connection-encrypter-plaintext/test/compliance.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env mocha */
22

33
import suite from '@libp2p/interface-compliance-tests/connection-encryption'
4-
import { plaintext } from '../../src/insecure/index.js'
4+
import { plaintext } from '../src/index.js'
55

66
describe('plaintext compliance', () => {
77
suite({

packages/libp2p/test/insecure/plaintext.spec.ts renamed to packages/connection-encrypter-plaintext/test/index.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createEd25519PeerId, createRSAPeerId } from '@libp2p/peer-id-factory'
1010
import { multiaddr } from '@multiformats/multiaddr'
1111
import { expect } from 'aegir/chai'
1212
import sinon from 'sinon'
13-
import { plaintext } from '../../src/insecure/index.js'
13+
import { plaintext } from '../src/index.js'
1414
import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter'
1515
import type { PeerId } from '@libp2p/interface/peer-id'
1616

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"extends": "aegir/src/config/tsconfig.aegir.json",
3+
"compilerOptions": {
4+
"outDir": "dist"
5+
},
6+
"include": [
7+
"src",
8+
"test"
9+
],
10+
"references": [
11+
{
12+
"path": "../interface"
13+
},
14+
{
15+
"path": "../interface-compliance-tests"
16+
},
17+
{
18+
"path": "../logger"
19+
},
20+
{
21+
"path": "../peer-id"
22+
},
23+
{
24+
"path": "../peer-id-factory"
25+
}
26+
]
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"entryPoints": [
3+
"./src/index.ts"
4+
]
5+
}

packages/libp2p/.aegir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
const { yamux } = await import('@chainsafe/libp2p-yamux')
1616
const { WebSockets } = await import('@multiformats/mafmt')
1717
const { createLibp2p } = await import('./dist/src/index.js')
18-
const { plaintext } = await import('./dist/src/insecure/index.js')
18+
const { plaintext } = await import('@libp2p/plaintext')
1919
const { circuitRelayServer, circuitRelayTransport } = await import('./dist/src/circuit-relay/index.js')
2020
const { identify } = await import('@libp2p/identify')
2121
const { fetchService } = await import('./dist/src/fetch/index.js')

packages/libp2p/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@
5555
"./fetch": {
5656
"types": "./dist/src/fetch/index.d.ts",
5757
"import": "./dist/src/fetch/index.js"
58-
},
59-
"./insecure": {
60-
"types": "./dist/src/insecure/index.d.ts",
61-
"import": "./dist/src/insecure/index.js"
6258
}
6359
},
6460
"eslintConfig": {
@@ -117,7 +113,6 @@
117113
"it-drain": "^3.0.2",
118114
"it-filter": "^3.0.1",
119115
"it-first": "^3.0.1",
120-
"it-handshake": "^4.1.3",
121116
"it-length-prefixed": "^9.0.1",
122117
"it-map": "^3.0.3",
123118
"it-merge": "^3.0.0",
@@ -150,6 +145,7 @@
150145
"@libp2p/kad-dht": "^10.0.15",
151146
"@libp2p/mdns": "^9.0.14",
152147
"@libp2p/mplex": "^9.0.12",
148+
"@libp2p/plaintext": "^0.0.0",
153149
"@libp2p/tcp": "^8.0.13",
154150
"@libp2p/websockets": "^7.0.13",
155151
"aegir": "^41.0.2",

packages/libp2p/test/addresses/addresses.node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-env mocha */
22

3+
import { plaintext } from '@libp2p/plaintext'
34
import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback'
45
import { webSockets } from '@libp2p/websockets'
56
import { type Multiaddr, multiaddr, protocols } from '@multiformats/multiaddr'
67
import { expect } from 'aegir/chai'
78
import { pEvent } from 'p-event'
89
import sinon from 'sinon'
9-
import { plaintext } from '../../src/insecure/index.js'
1010
import { createNode } from '../fixtures/creators/peer.js'
1111
import { AddressesOptions } from './utils.js'
1212
import type { Libp2pNode } from '../../src/libp2p.js'

packages/libp2p/test/circuit-relay/discovery.node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-env mocha */
22

33
import { yamux } from '@chainsafe/libp2p-yamux'
4+
import { plaintext } from '@libp2p/plaintext'
45
import { tcp } from '@libp2p/tcp'
56
import { expect } from 'aegir/chai'
67
import { pEvent } from 'p-event'
78
import { circuitRelayServer, type CircuitRelayService, circuitRelayTransport } from '../../src/circuit-relay/index.js'
89
import { createLibp2p } from '../../src/index.js'
9-
import { plaintext } from '../../src/insecure/index.js'
1010
import { getRelayAddress, hasRelay, MockContentRouting, mockContentRouting } from './utils.js'
1111
import type { Libp2p } from '@libp2p/interface'
1212

packages/libp2p/test/circuit-relay/relay.node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { yamux } from '@chainsafe/libp2p-yamux'
55
import { identify } from '@libp2p/identify'
66
import { mplex } from '@libp2p/mplex'
7+
import { plaintext } from '@libp2p/plaintext'
78
import { tcp } from '@libp2p/tcp'
89
import { Circuit } from '@multiformats/mafmt'
910
import { multiaddr } from '@multiformats/multiaddr'
@@ -20,7 +21,6 @@ import { DEFAULT_DATA_LIMIT, RELAY_V2_HOP_CODEC } from '../../src/circuit-relay/
2021
import { circuitRelayServer, type CircuitRelayService, circuitRelayTransport } from '../../src/circuit-relay/index.js'
2122
import { HopMessage, Status } from '../../src/circuit-relay/pb/index.js'
2223
import { createLibp2p, type Libp2pOptions } from '../../src/index.js'
23-
import { plaintext } from '../../src/insecure/index.js'
2424
import { discoveredRelayConfig, doesNotHaveRelay, getRelayAddress, hasRelay, notUsingAsRelay, usingAsRelay, usingAsRelayCount } from './utils.js'
2525
import type { Components } from '../../src/components.js'
2626
import type { Libp2p } from '@libp2p/interface'

packages/libp2p/test/circuit-relay/relay.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import { yamux } from '@chainsafe/libp2p-yamux'
55
import { identify } from '@libp2p/identify'
66
import { mplex } from '@libp2p/mplex'
7+
import { plaintext } from '@libp2p/plaintext'
78
import { webSockets } from '@libp2p/websockets'
89
import * as filters from '@libp2p/websockets/filters'
910
import { Circuit } from '@multiformats/mafmt'
1011
import { expect } from 'aegir/chai'
1112
import { pEvent } from 'p-event'
1213
import { circuitRelayTransport } from '../../src/circuit-relay/index.js'
1314
import { createLibp2p } from '../../src/index.js'
14-
import { plaintext } from '../../src/insecure/index.js'
1515
import { hasRelay } from './utils.js'
1616
import type { Libp2p } from '@libp2p/interface'
1717
import type { Connection } from '@libp2p/interface/connection'

0 commit comments

Comments
 (0)