1.0.10 • Published 3 years ago

swarm-peer-server v1.0.10

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

swarm-peer-server

A network swarm for creating secure P2P connections over Bittorrent DHT, DNS, and mDNS.

Uses discovery-swarm to find and connect peers. Connections use asymmetric encryption and Elliptic-curve Diffie-Hellman to establish a secure communication channel. Clients must know the public key of a peer ahead of time to initiate the connection.

Depends on native modules libsodium (via sodium-native) and libutp (via utp-native).

npm install swarm-peer-server

Usage

Server

var swarm = require('swarm-peer-server')

swarm.listen({
  publicKey: Buffer.from('...'),
  secretKey: Buffer.from('...')
}, (socket, peerKey, info) => {
  console.log('New authenticated connection')
  socket.once('data', data => {
    console.log('Received:', data.toString())
    socket.destroy()
  })
})

Client

var swarm = require('swarm-peer-server')

var { socket } = await swarm.connect({
  publicKey: Buffer.from('...'),
  secretKey: Buffer.from('...'),
  hostPublicKey: Buffer.from('...')
})

console.log('Established connection')
const data = Buffer.from('hello world')
socket.write(data)

Examples

examples/echo.js # CLI echo server

API

var sw = swarm.listen(opts)

Create a new swarm server. Options include:

{
  publicKey: crypto.randomBytes(32), // server public key
  secretKey: crypto.randomBytes(64), // server secret key
  convert: false, // convert signatures to authentication encryption [1]
}

1 https://download.libsodium.org/doc/advanced/ed25519-curve25519.html

For full list of options take a look at discovery-swarm or the TypeScript definitions.

swarm.connect(opts, (socket, peerKey, info) => {})

Create a new swarm server. Options include:

{
  hostPublicKey: crypto.randomBytes(32), // host/server public key
  publicKey: crypto.randomBytes(32), // client public key
  secretKey: crypto.randomBytes(64), // client secret key
  convert: false, // convert signatures to authentication encryption
}

License

MIT

1.0.10

3 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago