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

secrets-manager-signature-tools

v1.0.7

Published

Utility to use secrets from AWS Secrets Manager for cryptographic signature generation and verification

Downloads

6

Readme

secrets-manager-signature-tools

A lightweight wrapper over NodeJS native crypto library for content signing and verification. This library interfaces with AWS Secrets Manager (ASM) to fetch stored secrets for the signature processes to reduce boilerplate secret management in your code.

You can use this library for code signing with AWS Secrets Manager in your JavaScript/TypeScript applications. For TS, you do not need separate typings package to be installed; you'd find the typings as part of this package itself.

Installation

For installing this library in your project, you would need aws-sdk >=2.225.0. Use npm to install this library to your package:

npm i --save [email protected] secrets-manager-signature-tools

You can then start using this library in your code.

Usage

You can use this library to pull secret signing keys from AWS Secrets Manager service and sign/verify data with the utilities provided. For this, you'd need programmatic credentials for your AWS account and the secrets you want to use from AWS Secrets Manager. You can read more about AWS credentials here and AWS Secrets Manager here.

In your code, you can create a config for creating a signature engine provided in this tool:

// signature-engine-config.ts
import { SimpleSignEngineConfig } from 'secrets-manager-signature-tools';

// Export your config for use
export const config: SimpleSignEngineConfig = {
  // Config for the signing
  cryptoConfig: {
    signatureCipher: 'RSA-SHA256',
    signatureEncoding: 'base64'
  },

  // Config for ASM
  asmClientConfig: {
    region: 'us-east-1',
    credentials: {
      accessKeyId: 'My-AWS-User-Access-Key-ID',
      secretAccessKey: 'My-AWS-User-Secret-Access-Key'
    }
  }
};

Then, you can consume this config to drive a sign engine and use it:

// simple-sign-engine.ts
import { config } from './signature-engine-config';
import SimpleSignEngine from 'secrets-manager-signature-tools';

const signEngine = new SimpleSignEngine(config);
const myData = 'Sign me!';

// These are your secrets stored in ASM using which you can sign and verify data
const privateKeyIdInASM = 'my-private-key-in-ASM';
const publicKeyIdInASM = 'my-public-key-in-ASM';

// Sign and verify data with the engine
signEngine
  .getSign(myData, privateKeyIdInASM)
  .then((sign) => {
    console.log(`Sign generated is ${sign}`);
    console.log(`Verifying the signature now...`);
    console.log(
      `Original sign will be verified. Result: ${signEngine.verifySign(
        sign,
        myData,
        publicKeyIdInASM
      )}`
    );

    // Some fake base64 sign verification
    let fakeSign = 'YWJjZA0K';
    console.log(
      `Fake sign will be rejected. Result: ${signEngine.verifySign(
        fakeSign,
        myData,
        publicKeyIdInASM
      )}`
    );
  })
  .catch((err) => {
    // Some error handling here
  });

For some applications, network calls may be expensive (eg. mobile apps). In such cases, you can cache your signing keys in-memory by providing a flag to the getSign or veifySign methods. In either case, if the key exists in cache, the engine will use the key. Otherwise, the key is fetched, cached and then used.

signEngine.getSign(myData, privateKeyIdInASM, true); // Implies the key would be cached in-memory

NOTE: Caching of keys can be done during sign generation/verification but once cached, the same key is used for subsequent operations.

For more details, please read though code documentation in this library. Happy signing!

License

This library is licensed under the Apache 2.0 License.