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

triple-double

v0.0.3

Published

Create end-to-end encrypted WebSocket channels with Extended Triple Diffie-Hellman and Double Ratchet

Downloads

16

Readme

triple-double

Create end-to-end encrypted WebSocket channels!

This package implements secret negotation via Extended Triple Diffie-Hellman (X3DH), allowing two peers to establish a WebSocket channel encrypted end-to-end with the Double Ratchet Algorithm and header encryption.

WARNING: this library has NOT received a formal security audit, use at your own risk.

Install

npm i triple-double

Usage

Server

Generate TLS certificate

npm run cert

This generates a private key and self-signed certificate and writes them to private/.

Note: the client will need the certificate to connect to the server.

Start server

[host=] [port=] npm start

Client

Example

The following code snippets assume top-level async/await for readability purposes.

A secure, out-of-band channel is needed to communicate public keys and session IDs between peers.

Find the complete code in ./example.js and run it with npm run example.

Alice publishes bundle

Alice only has to perform this step if:

  • She hasn't published her bundle yet
  • She runs out of one-time prekeys
  • She wants to publish a new signed prekey

We'll assume she hasn't published her bundle yet.

See here for more details.

// Alice's code
const fs = require('fs')
const { Client } = require('triple-double')

const ca = fs.readFileSync('/path/to/cert')
const host = '1.2.3.4'
const port = 8888

const alice = new Client({ ca, host, port })

const pubKey = await alice.publishBundle()

// Send public key to Bob out-of-band
Bob sends initial message

See here for more details.

// Bob's code
const fs = require('fs')
const { Client } = require('triple-double')

const ca = fs.readFileSync('/path/to/cert')
const host = '1.2.3.4'
const port = 8888

const bob = new Client({ ca, host, port })

const peerKey = Buffer.from(/* alice's public key */)
const plaintext = 'intial plaintext'

const sid = await bob.sendInitMessage(peerKey, plaintext)

// Send session ID to alice out-of-band
Alice receives initial message

See here for more details.

// Alice's code continued
const plaintext = await alice.recvInitMessage('<session ID from Bob>')
Connect

At this point, the peers can establish a secure WebSocket channel.

This operation won't complete until both peers are connected.

// Alice's code continued
await alice.connect('<session ID>')
// Bob's code continued
await bob.connect('<session ID>')
Send/receive messages

After connecting, the peers can send messages to each other!

These messages are encrypted with Double Ratchet (including header encryption).

// Alice's code continued
alice.on('message', ({ sid, plaintext }) => {
  if (sid === '<session ID>') {
    // handle Bob's plaintext
  }
})

alice.send('<session ID>', 'hello "bob"')
// Bob's code continued
bob.on('message', ({ sid, plaintext }) => {
  if (sid === '<session ID>') {
    // handle Alice's plaintext
  }
})

bob.send('<session ID>', 'hello "alice"')

Alice and Bob can establish secure channels to other peers, if they so choose.

Disconnect

Once a peer calls disconnect() with the session ID, the channel closes and both peers receive "disconnect" events.

// Alice's code continued
alice.on('disconnect', sid => {
  if (sid === '<session ID>') {
    // Disconnected from Bob
  }
})

alice.disconnect('<session ID>')
// Bob's code continued
bob.on('disconnect', sid => {
  if (sid === '<session ID>') {
    // Disconnected from Alice
  }
})

Docs

npm run doc

This generates the documentation and writes it to out/.

Then you can open out/index.html in your browser.

Test

npm test

Lint

npm run lint

Contributing

Go for it! Whether it's code cleanup, a bugfix, or feature request, your input is seriously appreciated.

Unsure where to start? Take a look at the code or open an issue.

References