Skip to content

Commit

Permalink
refactor!: extract plaintext into separate module (#2221)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: imports from `libp2p/plaintext` should be changed to `@libp2p/plaintext`
  • Loading branch information
achingbrain committed Nov 15, 2023
1 parent d2c3e72 commit a364d95
Show file tree
Hide file tree
Showing 39 changed files with 252 additions and 39 deletions.
1 change: 1 addition & 0 deletions .release-please.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"group-pull-request-title-pattern": "chore: release ${component}",
"packages": {
"interop": {},
"packages/connection-encrypter-plaintext": {},
"packages/crypto": {},
"packages/interface": {},
"packages/interface-compliance-tests": {},
Expand Down
35 changes: 35 additions & 0 deletions doc/migrations/v0.46-v1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ A migration guide for refactoring your application code from libp2p `v0.46` to `
- [DCUtR](#dcutr)
- [KeyChain](#keychain)
- [UPnPNat](#upnpnat)
- [Plaintext](#plaintext)
- [Pnet](#pnet)
- [Metrics](#metrics)

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

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

**Before**

```ts
import { createLibp2p } from 'libp2p'
import { uPnPNATService } from 'libp2p/upnp-nat'
Expand All @@ -191,6 +194,38 @@ const node = await createLibp2p({
})
```

## Plaintext

The Plaintext connection encrypter module is now published in its own package.

Note that it is still insecure and should not be used in production.

**Before**

```ts
import { createLibp2p } from 'libp2p'
import { plaintext } from 'libp2p/insecure'

const node = await createLibp2p({
connectionEncryption: [
plaintext: plaintext()
]
})
```

**After**

```ts
import { createLibp2p } from 'libp2p'
import { plaintext } from '@libp2p/plaintext'

const node = await createLibp2p({
connectionEncryption: [
plaintext: plaintext()
]
})
```

## Pnet

The pnet module is now published in its own package.
Expand Down
4 changes: 4 additions & 0 deletions packages/connection-encrypter-plaintext/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This project is dual licensed under MIT and Apache-2.0.

MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0
5 changes: 5 additions & 0 deletions packages/connection-encrypter-plaintext/LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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

http://www.apache.org/licenses/LICENSE-2.0

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.
19 changes: 19 additions & 0 deletions packages/connection-encrypter-plaintext/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
57 changes: 57 additions & 0 deletions packages/connection-encrypter-plaintext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
[![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)

> An insecure connection encrypter
# About

A connection encrypter that does no connection encryption.

This should not be used in production should be used for research purposes only.

## Example

```typescript
import { createLibp2p } from 'libp2p'
import { plaintext } from '@libp2p/plaintext'

const node = await createLibp2p({
// ...other options
connectionEncryption: [
plaintext()
]
})
```

# Install

```console
$ npm i @libp2p/plaintext
```

## Browser `<script>` tag

Loading this module through a script tag will make it's exports available as `Libp2pPlaintext` in the global namespace.

```html
<script src="https://unpkg.com/@libp2p/plaintext/dist/index.min.js"></script>
```

> Implementation of the DCUtR Protocol
# API Docs

- <https://libp2p.github.io/js-libp2p/modules/_libp2p_plaintext.html>

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribution

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.
68 changes: 68 additions & 0 deletions packages/connection-encrypter-plaintext/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "@libp2p/plaintext",
"version": "0.0.0",
"description": "An insecure connection encrypter",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/connection-encrypter-plaintext#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/libp2p/js-libp2p.git"
},
"bugs": {
"url": "https://github.com/libp2p/js-libp2p/issues"
},
"type": "module",
"types": "./dist/src/index.d.ts",
"files": [
"src",
"dist",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
}
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"project": true,
"sourceType": "module"
}
},
"scripts": {
"start": "node dist/src/main.js",
"build": "aegir build",
"test": "aegir test",
"clean": "aegir clean",
"generate": "protons ./src/pb/index.proto",
"lint": "aegir lint",
"test:chrome": "aegir test -t browser --cov",
"test:chrome-webworker": "aegir test -t webworker",
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"test:node": "aegir test -t node --cov",
"dep-check": "aegir dep-check"
},
"dependencies": {
"@libp2p/interface": "^0.1.2",
"@libp2p/peer-id": "^3.0.6",
"@multiformats/multiaddr": "^12.1.5",
"it-handshake": "^4.1.3",
"it-length-prefixed": "^9.0.3",
"it-map": "^3.0.4",
"it-stream-types": "^2.0.1",
"protons-runtime": "^5.0.0",
"uint8arraylist": "^2.4.3"
},
"devDependencies": {
"@libp2p/interface-compliance-tests": "^4.1.5",
"@libp2p/logger": "^3.0.2",
"@libp2p/peer-id-factory": "^3.0.8",
"aegir": "^41.0.2",
"protons": "^7.3.0",
"sinon": "^17.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
*
* ```typescript
* import { createLibp2p } from 'libp2p'
* import { plaintext } from 'libp2p/insecure'
*
* // Create a Uint8Array and write the swarm key to it
* const swarmKey = new Uint8Array(95)
* generateKey(swarmKey)
* import { plaintext } from '@libp2p/plaintext'
*
* const node = await createLibp2p({
* // ...other options
* connectionEncryption: [plaintext()]
* connectionEncryption: [
* plaintext()
* ]
* })
* ```
*/
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */

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

describe('plaintext compliance', () => {
suite({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createEd25519PeerId, createRSAPeerId } from '@libp2p/peer-id-factory'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import sinon from 'sinon'
import { plaintext } from '../../src/insecure/index.js'
import { plaintext } from '../src/index.js'
import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter'
import type { PeerId } from '@libp2p/interface/peer-id'

Expand Down
27 changes: 27 additions & 0 deletions packages/connection-encrypter-plaintext/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist"
},
"include": [
"src",
"test"
],
"references": [
{
"path": "../interface"
},
{
"path": "../interface-compliance-tests"
},
{
"path": "../logger"
},
{
"path": "../peer-id"
},
{
"path": "../peer-id-factory"
}
]
}
5 changes: 5 additions & 0 deletions packages/connection-encrypter-plaintext/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"entryPoints": [
"./src/index.ts"
]
}
2 changes: 1 addition & 1 deletion packages/libp2p/.aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
const { yamux } = await import('@chainsafe/libp2p-yamux')
const { WebSockets } = await import('@multiformats/mafmt')
const { createLibp2p } = await import('./dist/src/index.js')
const { plaintext } = await import('./dist/src/insecure/index.js')
const { plaintext } = await import('@libp2p/plaintext')
const { circuitRelayServer, circuitRelayTransport } = await import('./dist/src/circuit-relay/index.js')
const { identify } = await import('@libp2p/identify')
const { fetchService } = await import('./dist/src/fetch/index.js')
Expand Down
6 changes: 1 addition & 5 deletions packages/libp2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
"./fetch": {
"types": "./dist/src/fetch/index.d.ts",
"import": "./dist/src/fetch/index.js"
},
"./insecure": {
"types": "./dist/src/insecure/index.d.ts",
"import": "./dist/src/insecure/index.js"
}
},
"eslintConfig": {
Expand Down Expand Up @@ -117,7 +113,6 @@
"it-drain": "^3.0.2",
"it-filter": "^3.0.1",
"it-first": "^3.0.1",
"it-handshake": "^4.1.3",
"it-length-prefixed": "^9.0.1",
"it-map": "^3.0.3",
"it-merge": "^3.0.0",
Expand Down Expand Up @@ -150,6 +145,7 @@
"@libp2p/kad-dht": "^10.0.15",
"@libp2p/mdns": "^9.0.14",
"@libp2p/mplex": "^9.0.12",
"@libp2p/plaintext": "^0.0.0",
"@libp2p/tcp": "^8.0.13",
"@libp2p/websockets": "^7.0.13",
"aegir": "^41.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/test/addresses/addresses.node.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-env mocha */

import { plaintext } from '@libp2p/plaintext'
import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback'
import { webSockets } from '@libp2p/websockets'
import { type Multiaddr, multiaddr, protocols } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import { pEvent } from 'p-event'
import sinon from 'sinon'
import { plaintext } from '../../src/insecure/index.js'
import { createNode } from '../fixtures/creators/peer.js'
import { AddressesOptions } from './utils.js'
import type { Libp2pNode } from '../../src/libp2p.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/test/circuit-relay/discovery.node.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-env mocha */

import { yamux } from '@chainsafe/libp2p-yamux'
import { plaintext } from '@libp2p/plaintext'
import { tcp } from '@libp2p/tcp'
import { expect } from 'aegir/chai'
import { pEvent } from 'p-event'
import { circuitRelayServer, type CircuitRelayService, circuitRelayTransport } from '../../src/circuit-relay/index.js'
import { createLibp2p } from '../../src/index.js'
import { plaintext } from '../../src/insecure/index.js'
import { getRelayAddress, hasRelay, MockContentRouting, mockContentRouting } from './utils.js'
import type { Libp2p } from '@libp2p/interface'

Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/test/circuit-relay/relay.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { yamux } from '@chainsafe/libp2p-yamux'
import { identify } from '@libp2p/identify'
import { mplex } from '@libp2p/mplex'
import { plaintext } from '@libp2p/plaintext'
import { tcp } from '@libp2p/tcp'
import { Circuit } from '@multiformats/mafmt'
import { multiaddr } from '@multiformats/multiaddr'
Expand All @@ -20,7 +21,6 @@ import { DEFAULT_DATA_LIMIT, RELAY_V2_HOP_CODEC } from '../../src/circuit-relay/
import { circuitRelayServer, type CircuitRelayService, circuitRelayTransport } from '../../src/circuit-relay/index.js'
import { HopMessage, Status } from '../../src/circuit-relay/pb/index.js'
import { createLibp2p, type Libp2pOptions } from '../../src/index.js'
import { plaintext } from '../../src/insecure/index.js'
import { discoveredRelayConfig, doesNotHaveRelay, getRelayAddress, hasRelay, notUsingAsRelay, usingAsRelay, usingAsRelayCount } from './utils.js'
import type { Components } from '../../src/components.js'
import type { Libp2p } from '@libp2p/interface'
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/test/circuit-relay/relay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import { yamux } from '@chainsafe/libp2p-yamux'
import { identify } from '@libp2p/identify'
import { mplex } from '@libp2p/mplex'
import { plaintext } from '@libp2p/plaintext'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { Circuit } from '@multiformats/mafmt'
import { expect } from 'aegir/chai'
import { pEvent } from 'p-event'
import { circuitRelayTransport } from '../../src/circuit-relay/index.js'
import { createLibp2p } from '../../src/index.js'
import { plaintext } from '../../src/insecure/index.js'
import { hasRelay } from './utils.js'
import type { Libp2p } from '@libp2p/interface'
import type { Connection } from '@libp2p/interface/connection'
Expand Down
Loading

0 comments on commit a364d95

Please sign in to comment.