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

sops-age

v0.6.3

Published

Node.js sops age decryption

Downloads

191

Readme

sops-age

sops-age is a Node.js library designed to decrypt files encrypted with SOPS (Secrets OPerationS) and the age encryption tool. This library provides an easy way to decrypt environment variables, configuration files, and other sensitive data encrypted with SOPS and age in your Node.js applications.

Features

  • Supports decryption of SOPS files encrypted with age.
  • Compatible with various file formats including .env, .ini, .json, and .yaml.
  • Provides utility functions for loading and decrypting different types of SOPS files or strings.
  • Allows decrypted all or part of a SOPS encrypted data.

Installation

To install sops-age, run the following command in your project directory:

npm install sops-age

Usage

Decrypting a SOPS File

To decrypt a SOPS file, you first need to load the encrypted file and then decrypt it (or parts of it) using a secret age key:

import { decrypt, loadSopsFile } from "sops-age";

async function decryptSopsFile(filePath, secretKey) {
  try {
    // Load the SOPS file (auto-detects file types env, ini, json, yaml from extension)
    const sopsData = await loadSopsFile(filePath);

    // Decrypt the data using the secret key
    const decryptedData = await decrypt(sopsData, secretKey);

    console.log("Decrypted Data:", decryptedData);
  } catch (error) {
    console.error("Error decrypting SOPS file:", error);
  }
}

const filePath = "./config.enc.yaml";
const secretKey = "YOUR_SECRET_AGE_KEY_HERE";
decryptSopsFile(filePath, secretKey);

Supported File Types

sops-age supports the following file types:

  • .env
  • .ini
  • .json
  • .yaml / .yml

The library automatically detects the file type based on the file extension. You can also manually specify the file type when loading a SOPS file.

API Reference

loadSopsFile(path, [sopsFileType])

Loads a SOPS file from the specified path. The sopsFileType parameter is optional and can be used to manually specify the file type (env, ini, json, yaml) when it can't be inferred from the file extension.

decrypt(sops, secretKey, [keyPath])

Decrypts the data from a loaded SOPS object using the provided secret key. If keyPath is specified, only the value at the given path is decrypted and returned; otherwise, all decrypted data is returned.

const sopsData = await loadSopsFile(filePath);

// Decrypt only the DB_URI value secret key
const DB_URI = await decrypt(sopsData, secretKey, "DB_URI");

Parsing Functions

  • parseSopsEnv(envString)
  • parseSopsIni(iniString)
  • parseSopsJson(json)
  • parseSopsYaml(yamlString)

These functions parse the strings of the specified type into a SOPS object that can be decrypted. Use this if you aren't working with files (e.g., SOPS data in a database).

// Assuming `env` contains a string in the form on an ENV file
const sopsData = parseSopsEnv(env);

const decryptedEnv = await decrypt(sopsData, secretKey);

License

sops-age is released under the MIT License. See the LICENSE file for more details.