Catalog npm
Back to packageRELEASE DETAILS

0.2.3

npm

1env

One secret to encrypt them all

Published25 May 2023
Direct dependencies4
Transitive dependenciesNot calculated

README

Current package documentation

One secret to encrypt them all

If you work for a responsible company, you probably have to store your secrets in a secure way. Due to this, sometimes, when you need to add or change a secret, you have to go through a lot of steps involving other people, and it can be a pain in the ass.

The 1env package offers a simple(r) way to approach your secrets, where you have just one (public) variable that, when decrypted, contains all your secrets in a JSON format. Thus, the only secret you have to worry about is the one that decrypts your secrets.

Installation

npm install 1env

Usage

  1. Create a file called .secrets.json in the root of your project, containing all your secrets.

  2. ADD IT TO YOUR .gitignore FILE.

  3. As early as possible in your code (but after env loaders such as dotenv), call these two functions:

// import { config } from 'dotenv'; // if you use dotenv
import { encryptSecrets, loadSecrets } from '1env';

// config(); // if you use dotenv
encryptSecrets();
loadSecrets();
  1. Set an environment variable named ONE_ENV_SECRET with a secure enough value. Alternatively, run the code above and it will suggest a value for you while throwing an error.

This is the key that will be used to encrypt and decrypt your secrets, and the only one you will have to worry about.

For example, if your company requires you to pass all screts through the devops team for encryption, you will only have to do it once and forget about it.

  1. After the first run, encryptSecrets will fail, and the console will show you the value of a ONE_ENV_ENCRYPTED variable you will have to set in your environment. Set it, and run again.

  2. If encryptSecrets succeeds, loadSecrets will load all your secrets into process.env.

That’s it! You can now access your secrets via process.env just like you would with any other environment variable.

Notes

  1. Whenever you change your .secrets.json file, the execution will fail again, indicating which value to set for ONE_ENV_ENCRYPTED.

  2. The execution will also fail if you don’t add .secrets.json to your .gitignore file. You’re welcome.

  3. The .secrets.json file is only needed while you’re developing your project, so that you can easily convert your secrets into the public ONE_ENV_ENCRYPTED variable. You can safely ignore/delete it when deploying your project to production.

  4. You do not need to remove encryptSecrets from your production code. It will simply do nothing and proceed to loadSecrets. (It will still give a warning, though, just to be sure.)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 4

Native requirements
4 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
vovas-utils
Environment
{
  "local_name": "vovas-utils",
  "alias": false,
  "peer_metadata": null
}
^0.0.39runtime
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^18.14.2development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^4.9.5development
unbuild
Environment
{
  "local_name": "unbuild",
  "alias": false,
  "peer_metadata": null
}
^1.1.2development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "b62060933f484aae871fe85df9f3a6d5914c52c7",
  "integrity": "sha512-7+2wRyfat7rWI7GTCIjqdz5NBwTqzEDirm0QcBG5qRofMV5N5IG1wALex1nYEKLPDQ4T9aEKQPEPr7aTn7KYCQ==",
  "tarball": "https://registry.npmjs.org/1env/-/1env-0.2.3.tgz",
  "fileCount": 7,
  "unpackedSize": 11486,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEYCIQCtQJFdZx0WYJEdK9jMtgPkM7nCkNSqenxC8anG1SkdJQIhAJs/OvwTBje/r4Xt6wvj0OQa2QLLH56FKAFNdiuj7+3Q"
    }
  ]
}

Repository

PENDING
vzakharov/1env

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:27 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:32ee111f5c24631e5b7bf4df2139246271fb267a8fcd482589fdeb9c3d251d73

Other collected versions

0.2.526 May0.2.425 May0.2.225 May0.2.125 May0.2.029 Apr0.1.128 AprView all collected versions →