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

sofa-signature-sdk

v1.1.2

Published

A JavaScript SDK for HTTP signature generation and verification, implementing RFC https://w3c-dvcg.github.io/http-signatures specification

Downloads

12

Readme

sofa-signature-sdk

npm version License: MIT

一个轻量级的 HTTP 签名库,实现了 RFC HTTP Signatures 标准。

特性

  • ✅ 支持多种签名算法(HMAC-SHA1, HMAC-SHA256 等)
  • ✅ 完整的 TypeScript 支持
  • ✅ 轻量级,无额外依赖负担
  • ✅ 符合 RFC 标准的 HTTP 签名实现
  • ✅ 支持签名生成和解析

安装

npm install sofa-signature-sdk

或者使用 yarn:

yarn add sofa-signature-sdk

快速开始

生成签名

import { Signature, SignatureAlgorithm } from 'sofa-signature-sdk'

// 创建签名实例
const signature = new Signature(
  'hmac-key-1', // keyId
  'your-authorization', // authorization
  SignatureAlgorithm.HMACSHA256, // 签名算法
  ['host', '(request-target)'] // 需要签名的头部字段
)

// 生成签名
const result = signature.doSignature(
  'your-secret-key', // 私钥
  {
    // 请求头
    host: 'example.com',
    date: 'Tue, 07 Jun 2014 20:51:35 GMT',
  },
  'POST', // HTTP 方法
  '/foo' // 请求路径
)

console.log(result)
// 输出: Signature keyId="hmac-key-1",algorithm="hmac-sha256",headers="host (request-target)",signature="..."

解析签名

import { ParseSignature } from 'sofa-signature-sdk'

const signatureString = `Signature keyId="hmac-key-1",algorithm="hmac-sha256",headers="host (request-target)",signature="nm9wk8zKSbKRm8+dnhV1rZHjOSdt6VYacCJkpETRtq8="`

const parsedSignature = ParseSignature(signatureString)
console.log(parsedSignature)
// 输出解析后的签名对象

API 参考

Signature 类

构造函数

new Signature(keyId: string, authorization: string, algorithm: SignatureAlgorithm, headers: string[])
  • keyId: 密钥标识符
  • authorization: 授权信息
  • algorithm: 签名算法
  • headers: 需要包含在签名中的 HTTP 头部字段列表

方法

doSignature(privateKey: string, reqHeaders: Record<string, string>, method: string, path: string): string

生成 HTTP 签名字符串。

参数:

  • privateKey: 用于签名的私钥
  • reqHeaders: HTTP 请求头对象
  • method: HTTP 方法(GET, POST, PUT, DELETE 等)
  • path: 请求路径

返回值: 完整的签名字符串

SignatureAlgorithm 枚举

支持的签名算法:

enum SignatureAlgorithm {
  HMACSHA1 = 'hmac-sha1',
  HMACSHA256 = 'hmac-sha256',
}

ParseSignature 函数

ParseSignature(signatureString: string): ParsedSignature

解析签名字符串并返回结构化的签名对象。

使用场景

这个库特别适用于:

  • API 网关签名验证
  • 微服务之间的安全通信
  • Webhook 签名验证
  • RESTful API 的安全认证

开发

构建

npm run build

测试

npm test

许可证

本项目采用 MIT 许可证。

贡献

欢迎提交 Issues 和 Pull Requests!

更新日志

v1.1.1

  • 更新文档和示例
  • 改进 TypeScript 类型定义

v1.1.0

  • 初始发布版本
  • 支持 HMAC-SHA1 和 HMAC-SHA256 算法
  • 完整的 TypeScript 支持