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

ssb-encryption-format

v2.2.0

Published

devDependency to test encryption formats

Downloads

14

Readme

ssb-encryption-format

A tool that you install as a devDependency to check whether your encryption format for SSB messages is correct and ready to be installed in ssb-db2.

This tool helps you create new encryption formats that are compatible with ssb-db2 (and maybe one day other databases).

Installation

npm install --save-dev ssb-encryption-format

Usage

const {check} = require('ssb-encryption-format');

const myEncryptionFormat = {
  // ...
};

// Pass your encryption format:
check(myEncryptionFormat, (err) => {
  // `err` if the format is incorrect, else it is undefined
});

In case your encryption format implement setup(), then you can also pass an onSetup function as an argument to check(). This is useful in case you need to do some extra preparation after setup() but before encrypt()/decrypt() is run:

function onSetup() {
  myEncryptionFormat.prepareSomething();
}

check(myEncryptionFormat, onSetup, (err) => {
  // ...
});

Spec

An encryption format specifies how to encrypt and decrypt JavaScript buffers (these could be SSB messages from any feed format) using a particular encryption scheme and algorithms. Every encryption format is a plugin-like object with:

  • name
  • setup(config, cb)
  • teardown(config, cb)
  • encrypt(plaintext, opts)
  • decrypt(ciphertext, opts)

Fields and functions

Your encryption format must include these properties:

name

A string to name this format. Try to use computer-friendly names, not human-friendly names. Avoid spaces and select short unique names.

The name will also be appended to the ciphertexts when they are base64-stringified. Do NOT include a dot in the name, use only lowercase alphanumeric characters.

setup(config, cb)

An OPTIONAL function that you can use to asynchronously setup your encryption format. This function is called when the encryption format is installed in ssb-db2.

The config argument is the same config object that usually comes from secret-stack, and the cb is a function you call with zero arguments once your setup has completed.

teardown(cb)

An OPTIONAL function that you can use to asynchronously teardown your encryption format. This function is called when the encryption format is no longer needed in ssb-db2 or when the ssb instance is closed.

encrypt(plaintext, opts)

Takes a plaintext as a Buffer and opts object and MUST return a Buffer representing the ciphertext.

You can assume opts has the following properties:

  • opts.keys: the "ssb-keys"-style cryptographic keypair object of the current SSB peer
  • opts.recps: an array of public keys (usually strings such as sigil IDs or SSB URIs) of the recipients of the ciphertext
  • opts.previous: a string representing the message ID of the previous SSB message before this plaintext

decrypt(ciphertext, opts)

Takes a ciphertext as a Buffer and an opts object and MUST return a Buffer representing the plaintext.

You can assume opts has the following properties:

  • opts.keys: the "ssb-keys"-style cryptographic keypair object of the current SSB peer
  • opts.previous: a string representing the message ID of the previous SSB message before this plaintext
  • opts.author: a string representing the feed ID who authored this ciphertext message

License

LGPL-3.0-only