You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constnoise=require('noise-network')constserver=noise.createServer()server.on('connection',function(encryptedStream){console.log('new encrypted stream!')// encryptedStream is a noise-peer stream instanceencryptedStream.on('data',function(data){console.log('client wrote:',data)})})constkeyPair=noise.keygen()// Announce ourself to the HyperSwarm DHT on the following keyPair's publicKeyserver.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 streamconstclient=noise.connect('{public key from above}')// client is a noise-peer stream instanceclient.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 connectvalidate(remoteKey,done){ ... },// you can add the onconnection handler here alsoonconnection(connection){ ... }}