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-protocol-stream

v1.1.3

Published

Node stream wrapper for Noise Protocol C implementation compiled to WebAssembly

Downloads

67

Readme

noise-protocol-stream

Node stream wrapper for Noise Protocol C implementation compiled to WebAssembly.

npm install noise-protocol-stream

Usage

The constructor returns a stream pair for encrypting outgoing and decrypting incoming data. Both streams need to be connected for the initial noise handshake to succeed. After the handshake is complete writing to the encrypt stream will output the encrypted the data and reading from the decrypt stream returns the decrypted data (note that it's not possible to connect the same encrypt and decrypt pair directly).

var net = require('net')
var noise = require('noise-protocol-stream')

var socket = net.createConnection(8080)
var client = noise({ initiator: true })

client.encrypt.pipe(socket).pipe(client.decrypt)

client.decrypt.on('data', function (data) {
  console.log(data)
})

client.encrypt.write('hello')

The Noise_XX_25519_AESGCM_SHA256 handshake pattern is used to establish a secure connection, it supports mutual authentication and transmission of static public keys. If no key is specified in the constructor a new one will be created.

Constructor options:

{
  initiator: true,                       // Protocol initiator or responder.
  prologue: Buffer.from(prologue),       // Data that both parties want to confirm is identical.
  privateKey: Buffer.from(privateKey),   // Static private key. Public key is computed from it.
  verify: function () {}                 // Verify remote public key before any actual communication.
}

The verify function is called with the local key pair, the received remote public key and a callback function wich must be called to either accept or terminate the connection. If no verify function is provided the default is to accept any connection.

var net = require('net')
var noise = require('noise-protocol-stream')

var TRUSTED_PUBLIC_KEY = Buffer.from('...')

net.createServer(function (socket) {
  var server = noise({
    verify: function (localPrivateKey, localPublicKey, remotePublicKey, cb) {
      // Calling cb with an error as first argument will also emit an error event on the stream pair.
      // The callback must be called explicitly with true to accept.
      if (TRUSTED_PUBLIC_KEY.equals(remotePublicKey)) cb(null, true)
      else cb(null, false)
    }
  })

  server.encrypt.pipe(socket).pipe(server.decrypt)

  // Emitted after the connection is accepted in the verify function
  server.encrypt.on('handshake', function (localPrivateKey, localPublicKey, remotePublicKey) {
    console.log(remotePublicKey)
  })

  // Reading and writing will only work after the connection is accepted
  server.decrypt.on('data', function (data) {
    console.log(data)
  })

  server.encrypt.write('world')
}).listen(8080)

See the Noise protocol specifications for more details.