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

secure-peer

v0.2.1

Published

peer-to-peer encrypted streams using public key cryptography and signing

Downloads

182

Readme

secure-peer

Create encrypted peer-to-peer streams using public key cryptography and signing.

No certificates, no authorities. Each side of the connection has the same kind of keys so it doesn't matter which side initiates the connection.

build status

example

First generate some public/private keypairs with rsa-json:

$ rsa-json > a.json
$ rsa-json > b.json
var secure = require('secure-peer');
var peer = secure(require('./a.json'));
var through = require('through');

var net = require('net');
var server = net.createServer(function (rawStream) {
    var sec = peer(function (stream) {
        stream.pipe(through(function (buf) {
            this.emit('data', String(buf).toUpperCase());
        })).pipe(stream);
    });
    sec.pipe(rawStream).pipe(sec);
});
server.listen(5000);
var secure = require('secure-peer');
var peer = secure(require('./b.json'));

var net = require('net');
var rawStream = net.connect(5000);

var sec = peer(function (stream) {
    stream.pipe(process.stdout);
    stream.end('beep boop\n');
});
sec.pipe(rawStream).pipe(sec);

sec.on('identify', function (id) {
    // you can asynchronously verify that the key matches the known value here
    id.accept();
});

For extra security, you should keep a file around with known hosts to verify that the public key you receive on the first connection doesn't change later on like how ~/.ssh/known_hosts works.

Maintaining a known hosts file is outside the scope of this module.

methods

var secure = require('secure-peer')

var peer = secure(keys)

Return a function to create streams given the keys supplied.

keys.private should be a private PEM string and keys.public should be a public PEM string.

You can generate keypairs with rsa-json.

var sec = peer(cb)

Create a new duplex stream sec

events

sec.on('connection', function (stream) {})

Emitted when the secure connection has been established successfully.

stream.id is the identify object from the 'identify' event.

sec.on('identify', function (id) {})

Emitted when the connection identifies with its public key, id.key.

Each listener must call either id.accept() or id.reject().

The connection won't be accepted until all listeners call id.accept(). If any listener calls id.reject(), the connection will be aborted.

id.accept()

Accept the connection. This function must be called for every listener on the 'identify' event for the connection to succeed.

id.reject()

Reject the connection. The connection will not succeed even if id.accept() was called in another listener.

sec.on('header', function (header) {})

Emitted when the remote side provides a signed header.payload json string signed with its private key in header.hash.

install

With npm do:

npm install secure-peer

license

MIT