Skip to content

Authenticated P2P network backed by Hyperswarm and Noise

License

Notifications You must be signed in to change notification settings

mafintosh/noise-network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

noise-network

Authenticated network P2P backed by Hyperswarm and Noise

Usage

First spin up a server

const noise = require('noise-network')

const server = noise.createServer()

server.on('connection', function (encryptedStream) {
  console.log('new encrypted stream!')

  // encryptedStream is a noise-peer stream instance
  encryptedStream.on('data', function (data) {
    console.log('client wrote:', data)
  })
})

const keyPair = noise.keygen()

// Announce ourself to the HyperSwarm DHT on the following keyPair's publicKey
server.listen(keyPair, function () {
  console.log('Server is listening on:', server.publicKey.toString('hex'))
})

Then connect to the server by connecting to the public key

// noise guarantees that we connect to the server in a E2E encrypted stream
const client = noise.connect('{public key from above}')

// client is a noise-peer stream instance
client.write('hello server')

API

const server = noise.createServer([options])

Create a new Noise server.

Options include:

{
  // validate the remote client's public key before allowing them to connect
  validate (remoteKey, done) { ... },
  // you can add the onconnection handler here also
  onconnection (connection) { ... }
}

const client = noise.connect(serverPublicKey, [keyPair])

Connect to a server. Does UDP hole punching if necessary. serverPublicKey must be of type Buffer or hex.

License

MIT

About

Authenticated P2P network backed by Hyperswarm and Noise

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 3

  •  
  •  
  •