Hugo Dias 9b13fe321a
fix: remove node global (#587)
* fix: use new libp2p-crypto

* fix: remove node globals and reduce size

- adds buffer require
- adds globalThis where needed
- streaming-iterables was remove and new utils created, this will be consolidated in `ipfs-utils` and backported here to normalize all these iterator helper functions
- latency-monitor was copied inside the repo
- iso-random-stream is now used instead of node crypto
- the test `should ignore self on discovery` was moved to node only

Size: 172.97KB
47.03KB below the 220KB limit.

`aegir build --node false` and `aegir test -t browser --node false` now work 🎉

* fix: fix require path

* fix: feedback

* fix: update deps and bundle size

* chore: bump interfaces

* chore: update size
2020-04-24 17:10:40 +02:00
..
2020-04-24 17:10:40 +02: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)