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

microstar-crypto

v0.0.2

Published

Cryptography library for Microstar. Wraps tweetnacl, performing type conversions and simplifying public key management.

Downloads

10

Readme

s library wraps tweetnacl, doing a few things.

  • Performs type conversion on the UTF8 and Base64 encodings used in tweetnacl. All methods take and return strings.
  • Wraps synchronous methods into a callback API using process.nextTick. This is to make it easier to switch to different algorithms in the future, or offload processing to workers.
  • Simplifies key management. Tweetnacl provides box (public key encryption), secretbox (symmetric encryption), and sign (cryptographic signatures). Each of these takes a different kind of key, but they can all be generated from a box secret key. Microstar-crypto does this generation automatically so that you only need to handle and store one private key. Additionally, box and sign use separate public keys. Microstar-crypto concatenates these into one string, and then extracts the correct public key depending on method.

Using tweetnacl by itself:

var keys = {
  box: {
    secretKey: Uint8Array, // 32 bytes
    publicKey: Uint8Array // 32 bytes
  },
  sign: {
    secretKey: Uint8Array, // 32 bytes
    publicKey: Uint8Array // 64 bytes
  },
  secretbox: {
    secretKey: Uint8Array // 32 bytes
  }
}

Using microstar-crypto;

var keys = {
  publicKey: String, // 88 characters
  secretKey: String // 44 characters
}

.keys([secretKey, ]callback)

Generates a keypair. Called with a secretKey it will generate the corresponding public key. Without, it will generate both keys from scratch.

mCrypto.keys(function (err, keys) {
//  keys = {
//    publicKey: String, // 88 characters
//    secretKey: String // 44 characters
//  }
})

.box(string, nonce, theirPublicKey, mySecretKey, callback)

Encrypts a string using a public key. Returns a string.

mCrypto.box(string, nonce, alicePublicKey, bobSecretKey, function (err, box) {
//  box = String // encrypted
})

mCrypto.box.open(box, nonce, bobPublicKey, aliceSecretKey, function (err, string) {
//  string = String // plaintext
})

.secretbox(string, nonce, secretKey, callback)

Encrypts a string symmetrically with one secret key. Returns a string.

mCrypto.secretbox(string, nonce, secretKey, function (err, box) {
//  box = String // encrypted
})

mCrypto.secretbox.open(box, nonce, secretKey, function (err, string) {
//  string = String // plaintext
})

.sign(string, secretKey, callback)

Signs a string, returning a signature as a string. This uses tweetnacl.sign.detached under the hood.

mCrypto.sign(string, secretKey, function (err, signature) {
//  signature = String
})

mCrypto.sign.verify(string, signature, publicKey, function (err, valid) {
//  valid = Boolean
})