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

secretstream-stream

v2.0.0

Published

Abstract encoding API of `libsodium` `crypto_secretstream`

Downloads

27

Readme

secretstream-stream

Build Status

Abstract encoding API of libsodium crypto_secretstream

Someday there will be a stream interface here too

Usage

var secretstream = require('secretstream-stream')

// Parameters
var header = Buffer.alloc(secretstream.HEADERBYTES)
var key = secretstream.keygen()

// Init encryption side, writing into header Buffer, which needs to be shared
// with decryption side
var tx = secretstream.encrypt(header, key)
var ciphertext = tx.encrypt(secretstream.TAG_MESSAGE, Buffer.from('Hello world!'))

// Setup the decrypt side
var rx = secretstream.decrypt(header, key)
var plaintext = rx.decrypt(ciphertext)

console.log(plaintext.equals(Buffer.from('Hello world!')), rx.decrypt.tag.equals(secretstream.TAG_MESSAGE))

tx.destroy()
rx.destroy()

API

Constants

Buffer sizes

  • secretstream.KEYBYTES - Key size
  • secretstream.HEADERBYTES - Header size
  • secretstream.ABYTES - MAC size added to every message

Tags

  • secretstream.TAG_MESSAGE
  • secretstream.TAG_PUSH
  • secretstream.TAG_FINAL
  • secretstream.TAG_REKEY

var key = secretstream.keygen([key])

Generate a new symmetric key for use with .encrypt and .decrypt. The key is stored in a sodium Secure Buffer. You can also save a allocation by passing in the key buffer, which must be at least .KEYBYTES bytes.

var tx = secretstream.encrypt(header, key)

Create an encrypt instance with key, writing into header. header needs to be passed the the decryption side somehow.

var ciphertext = tx.encrypt(tag, plaintext, [ad], [ciphertext], [offset])

Encrypt Buffer plaintext with added tag using optional Buffer ad, and write into Buffer ciphertext at offset. ad can be null if unused, while ciphertext will be allocated if not given. offset defalts to 0.

var bytes = tx.encryptionLength(plaintext)

Calculate the required length for a ciphertext from plaintext Buffer.

tx.encrypt.bytes

Number of bytes written into ciphertext at last call to tx.encrypt

tx.destroy()

Destroys the internal state and zero all memory. Can only be called once, you may never call encrypt after and sets .bytes to null.

var rx = secretstream.decrypt(header, key)

Create an decrypt instance with key, using header from encrypt.

var plaintext = rx.decrypt(ciphertext, [ad], [plaintext], [offset])

Decrypt Buffer ciphertext using optional Buffer ad, and write into Buffer plaintext at offset. ad can be null if unused, while plaintext will be allocated if not given. offset defalts to 0.

var bytes = tx.decryptionLength(ciphertext)

Calculate the required length for a plaintext from ciphertext Buffer.

rx.decrypt.bytes

Number of bytes written into plaintext at last call to rx.decrypt

rx.decrypt.tag

A tag Buffer for the tag from the last decrypted ciphertext. Should be compared against one of the exported tags. Please review the libsodium documentation for how tags should be interpreted.

rx.destroy()

Destroys the internal state and zero all memory. Can only be called once, you may never call encrypt after and sets .bytes and .tag to null.

Install

npm install secretstream-stream

License

ISC