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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@emiyalee/demo-node-cert

v1.0.1

Published

SM2 Certificate Tool for Node.js - Cross-platform native binary wrapper

Readme

@emiyalee/demo-node-cert

SM2证书工具的Node.js插件版本 - 跨平台原生二进制文件封装

npm version License: MIT

✨ 特性

  • 🚀 高性能: 使用GraalVM原生镜像编译,提供极快的启动速度
  • 🌍 跨平台: 支持 macOS (x64/ARM64) 和 Linux (x64/ARM64)
  • 🔒 国密算法: 完整的SM2椭圆曲线密码算法支持
  • 📦 零依赖: 单文件部署,无需额外系统依赖
  • 🛠️ 易集成: 简洁的JavaScript API接口
  • 命令行工具: 提供CLI工具直接使用

📦 安装

npm install @emiyalee/demo-node-cert
# 或者
yarn add @emiyalee/demo-node-cert
# 或者
pnpm add @emiyalee/demo-node-cert

🚀 快速开始

JavaScript API 使用

const sm2 = require('@emiyalee/demo-node-cert');

// 生成SM2密钥对
async function generateKeys() {
    try {
        const keyPair = await sm2.generateKey();
        console.log('私钥:', keyPair.privateKeyPem);
        console.log('公钥:', keyPair.publicKeyPem);
    } catch (error) {
        console.error('生成密钥失败:', error.message);
    }
}

// 生成证书签名请求 (CSR)
async function generateCSR() {
    try {
        const csr = await sm2.generateCSR('张三', '440681198802194273');
        console.log('CSR:', csr.certP10);
        console.log('私钥:', csr.privateKeyPem);
    } catch (error) {
        console.error('生成CSR失败:', error.message);
    }
}

// 解析证书
async function parseCert(certPem) {
    try {
        const certInfo = await sm2.parseCertificate(certPem);
        console.log('证书信息:', certInfo);
    } catch (error) {
        console.error('解析证书失败:', error.message);
    }
}

generateKeys();

命令行工具使用

安装后会自动注册全局命令 sm2-cert:

# 生成密钥对
sm2-cert generateKey

# 生成CSR
sm2-cert generateCSR "张三" "440681198802194273"

# 解析证书
sm2-cert parseCert "$(cat certificate.pem)"

# 显示帮助
sm2-cert help

📋 API 文档

SM2Cert 类

generateKey()

生成SM2密钥对

返回值:

{
    privateKeyPem: string,  // PEM格式私钥
    publicKeyPem: string    // PEM格式公钥
}

generateCSR(name, identity)

生成证书签名请求

参数:

  • name (string): 姓名
  • identity (string): 身份证号

返回值:

{
    certP10: string,        // PEM格式CSR
    privateKeyPem: string,  // PEM格式私钥
    subjectCN: string       // 证书主题
}

parseCertificate(certPem)

解析X.509证书

参数:

  • certPem (string): PEM格式证书内容

返回值: 证书详细信息对象

getPlatformInfo()

获取当前平台信息

返回值:

{
    platform: string,       // 操作系统 (darwin/linux)
    arch: string,          // 架构 (x64/arm64)
    detectedBinary: string, // 检测到的二进制文件名
    binaryPath: string      // 二进制文件完整路径
}

🖥️ 支持的平台

| 平台 | 架构 | 二进制文件名 | |------|------|-------------| | macOS | Intel (x64) | sm2-cert-macos-x64 | | macOS | Apple Silicon (ARM64) | sm2-cert-macos-arm64 | | Linux | x64 | sm2-cert-linux-x64 | | Linux | ARM64 | sm2-cert-linux-arm64 |

插件会自动检测当前运行环境并选择对应的二进制文件。

🔧 开发和测试

验证安装

# 检查二进制文件状态
npm run install-binaries

# 运行完整性测试
npm run test

开发模式

// 直接测试插件功能
node index.js

📁 项目结构

@emiyalee/demo-node-cert/
├── bin/                    # 二进制文件目录
│   ├── sm2-cert-macos-x64     # macOS x64 二进制
│   ├── sm2-cert-macos-arm64   # macOS ARM64 二进制
│   ├── sm2-cert-linux-x64     # Linux x64 二进制
│   └── sm2-cert-linux-arm64   # Linux ARM64 二进制
├── lib/                    # 工具库
│   └── utils.js            # 工具函数
├── scripts/                # 脚本目录
│   └── install-binaries.js # 安装验证脚本
├── index.js                # 主入口文件
├── package.json            # 包配置
└── README.md               # 文档

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License - 查看 LICENSE 文件了解详情

🔗 相关链接