Jacob Heun fe2a8eddbb refactor: crypto and pnet (#469)
* feat: add initial plaintext 2 module

* refactor: initial refactor of pnet

* chore: fix lint

* fix: update plaintext api usage

* test: use plaintext for test crypto

* chore: update deps

test: update dialer suite scope

* feat: add connection protection to the upgrader

* refactor: cleanup and lint fix

* chore: remove unncessary transforms

* chore: temporarily disable bundlesize

* chore: add missing dep

* fix: use it-handshake to prevent overreading

* chore(fix): PR feedback updates

* chore: apply suggestions from code review

Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio>
2020-01-24 14:40:40 +01:00
..
2020-01-24 14:40:40 +01:00
2020-01-24 14:40:40 +01:00

js-libp2p-pnet

Connection protection management for libp2p leveraging PSK encryption via XSalsa20.

Note: git history prior to merging into js-libp2p can be found in the original repository, https://github.com/libp2p/js-libp2p-pnet.

Table of Contents

Usage

const Protector = require('libp2p-pnet')
const protector = new Protector(swarmKeyBuffer)
const privateConnection = protector.protect(myPublicConnection, (err) => { })

Examples

Private Networks with IPFS

Private Shared Keys

Private Shared Keys are expected to be in the following format:

/key/swarm/psk/1.0.0/
/base16/
dffb7e3135399a8b1612b2aaca1c36a3a8ac2cd0cca51ceeb2ced87d308cac6d

PSK Generation

A utility method has been created to generate a key for your private network. You can use one of the methods below to generate your key.

From libp2p-pnet

If you have libp2p locally, you can run the following from the projects root.

node ./src/pnet/key-generator.js > swarm.key

From a module using libp2p

If you have a module locally that depends on libp2p, you can run the following from that project, assuming the node_modules are installed.

node -e "require('libp2p/src/pnet').generate(process.stdout)" > swarm.key

Programmatically

const writeKey = require('libp2p/src/pnet').generate
const swarmKey = Buffer.alloc(95)
writeKey(swarmKey)
fs.writeFileSync('swarm.key', swarmKey)