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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zhengkan2008/secure-keyfile-pkg

v1.2.0

Published

Secure Ethereum private key keyfile encryption/decryption with AES-256-GCM + scrypt.

Readme

@zhengkan2008/secure-keyfile-pkg

使用 AES-256-GCM + scrypt 的以太坊私钥 keyfile 工具包。

安装

npm install @zhengkan2008/secure-keyfile-pkg

功能

  • 将私钥加密为 JSON keyfile
  • 运行时仅在内存中解密
  • 支持将加密 keyfile 直接放入 .env(base64/json)
  • scrypt 参数合法性与成本上限校验
  • CLI 隐藏输入(不支持明文命令行参数)
  • 保存文件时强制 0600 权限

API 示例

import {
  encryptPrivateKey,
  decryptPrivateKey,
  encodeEncryptedKeyfileToBase64,
  loadKeyfilePasswordFromEnv,
  loadEncryptedKeyfileFromEnv,
  loadEncryptedKeyfile,
  saveEncryptedKeyfile,
} from '@zhengkan2008/secure-keyfile-pkg';

const keyfile = encryptPrivateKey('0xYOUR_PRIVATE_KEY', 'your-strong-password');
saveEncryptedKeyfile('./keys/arb-bot.keyfile.json', keyfile);

const loaded = loadEncryptedKeyfile('./keys/arb-bot.keyfile.json');
const privateKey = decryptPrivateKey(loaded, 'your-strong-password');

const keyfileB64 = encodeEncryptedKeyfileToBase64(keyfile);
process.env.KEYFILE_JSON_B64 = keyfileB64;
process.env.KEYFILE_PASSWORD_FILE = '/run/bot-secrets/arb-bot.pw';
const fromEnv = loadEncryptedKeyfileFromEnv();
const password = loadKeyfilePasswordFromEnv();
const privateKey2 = decryptPrivateKey(fromEnv, password);

.env 方案(推荐)

建议把“加密后的 keyfile”直接放入 .env,不再单独保存 keyfile 文件:

  • KEYFILE_JSON_B64(推荐):keyfile JSON 的 base64
  • KEYFILE_JSON(兼容):原始 keyfile JSON 字符串
  • KEYFILE_PASSWORD_FILE(推荐):运行期密码文件路径(如 /run/bot-secrets/*.pw
  • KEYFILE_PASSWORD(兼容):明文密码环境变量(仅调试场景)

CLI 示例

npx @zhengkan2008/secure-keyfile-pkg --out ./secure-keyfile.json

仅输出 env 变量(不写文件):

npx @zhengkan2008/secure-keyfile-pkg --env-only

可选参数:

  • -o, --out <path> 输出路径(默认 ./keyfile.json
  • -f, --force 覆盖已存在文件
  • --env-only 仅输出 KEYFILE_JSON_B64
  • -h, --help 查看帮助

scrypt 可通过环境变量覆盖:

  • SCRYPT_N(默认 32768,必须是 2 的幂)
  • SCRYPT_R(默认 8
  • SCRYPT_P(默认 1
  • SCRYPT_DKLEN(必须为 32

发布

cd shared/secure-keyfile-pkg
npm install
npm run build
npm run pack:dry-run
npm login --registry https://registry.npmjs.org
npm run publish:npm

安全说明

  • keyfile 虽已加密,但仍应按敏感文件管理。
  • 必须使用强密码,且不要把密码写进命令历史。
  • 解密后的私钥应尽量缩短在内存中的存在时间。