npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

noise-peer

v2.1.1

Published

Simple end-to-end encrypted, secure channels using Noise Protocol Framework and libsodium secretstream

Downloads

39

Readme

noise-peer

Build Status

Simple end-to-end encrypted, secure channels using Noise Protocol Framework and libsodium secretstream

Usage

Below is an example of a secure UPPERCASE echo server.

Server:

var peer = require('noise-peer')
var through = require('through2')
var pump = require('pump')
var net = require('net')

var server = net.createServer(function (rawStream) {
  var sec = peer(rawStream, false)

  pump(sec, through(function (buf, _, cb) {
    cb(null, buf.toString().toUpperCase())
  }), sec)
})

server.listen(5000)

Client:

var peer = require('noise-peer')
var pump = require('pump')
var net = require('net')

var rawStream = net.connect(5000)

var sec = peer(rawStream, true)

pump(sec, process.stdout)
sec.end('beep boop\n')

More examples are available in examples

API

var {publicKey, secretKey} = peer.keygen()

Generate a new key pair for use with noiseOpts. See the Handshake Pattern examples

var secureStream = peer(rawStream, isInitiator, [noiseOpts])

Create a new peer, performing handshaking transparently. Note that all messages are chunked to ~64kb size due to a 2 byte length header. By default the Noise NN pattern is used, which simply creates a forward secret channel. This does not authenticate either party. See below for other handshake pattern exapmles.

secureStream.initiator

Boolean indicating whether the stream is a client/initiator or a server/responder, as given by the isInitiator constructor argument.

secureStream.rawStream

Access to the rawStream passed in the constructor

secureStream.end([chunk][, encoding][, callback])

Special mention, as this also sends a FINISH message to the other party, which signals that the stream is to end and no more messages are to be expected. This is important to know that an active adversary did not truncate the stream.

secureStream.setTimeout(timeout[, callback])

Call setTimeout on the underlying rawStream if supported. This function will be undefined if not supported

secureStream.on('timeout')

Bubble timeout event from the underlying rawStream if supported. You should call either .end() (which sends a FINISH message to the other peer) or .destroy() the stream manually (like eg. net specifies).

secureStream.on('handshake', {remoteStaticKey, remoteEphemeralKey, handshakeHash})

Emitted when the handshaking has succeeded. remoteStaticKey may be null if you're using a pattern which does not use or receive a remote static key. All will be Buffers, with keys be cleared immediately after the handshake event. The handshakeHash can be used for channel binding as described in the Noise Specficiation

secureSteam.on('connected')

Emitted when the secure connection is fully established

Handshake Pattern examples

To have mutual authentication use the XX pattern, add a static keypair and provide a onstatickey function on both sides:

var opts = {
  pattern: 'XX',
  staticKeyPair: peer.keygen(),
  onstatickey: function (remoteKey, done) {
    if (remoteKey.equals(someSavedKey)) return done()

    return done(new Error('Unauthorized key'))
  }
}

To have have client authentication but use a preshared server public key use the XK pattern, add a static keypair on both sides, a remote static key on the client and provide a onstatickey function on the server:

var serverKeys = peer.keygen()

var clientOpts = {
  pattern: 'XK',
  staticKeyPair: peer.keygen(),
  remoteStaticKey: serverKeys.publicKey
}

var serverOpts = {
  pattern: 'XK',
  staticKeyPair: serverKeys,
  onstatickey: function (remoteKey, done) {
    if (remoteKey.equals(someSavedClientKey)) return done()

    return done(new Error('Unauthorized key'))
  }
}

Install

npm install noise-peer

License

ISC