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

steel-seal

v1.0.3

Published

简单、易用且支持防重放的签名工具

Downloads

4

Readme

steel-seal

简单、易用且支持防重放的签名工具。

安装模块

在你的项目下执行下面命令进行安装:

npm i steel-seal

快速开始

生成一个新的令牌

为了便于使用,steel_seal 实现了 generateToken 函数用于生成一个新的令牌。

import { SteelSeal } from "steel_seal"

const token = SteelSeal.generateToken()

console.log(token) // 输出: 2sqlFObdoqqYRpUFAGiGQecCwJ3Qw9je

对请求进行签名和验签

steel_seal主要用于对 Http/Https请求进行签名和验签。为保证当前请求不被篡改,建议对请求的 Query 参数以及 Body 参数进行拼接后并使用 signatureverify 方法对数据进行签名和验签。

1、对Get请求进行签名和验签

示例:

fetch("https://127.0.0.1:8080/api/message/list?self_only=0", {
  "headers": {
    "accept": "*/*",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
  },
  "method": "GET",
  "mode": "cors",
  "credentials": "include"
});

签名(伪代码):

// 使用令牌初始化实例
import { SteelSeal } from "steel_seal"

const token = "2sqlFObdoqqYRpUFAGiGQecCwJ3Qw9je"
const steelSeal = new SteelSeal({ token })

......

// 把查询参数组装成Object并序列化成JSON字符串
let queryStr = { self_only: 0 }
const signateData = JSON.stringify(queryStr) // 输出:'{"self_only":0}

// 使用 signature 方法对数据进行签名
// 输出:
//       {
//         timestamp: 1655956125,
//         nonce: '5yqXByu9',
//         signature: '6465a0b2ff69712c00a3430b26f4e1089c3ff851'
//       }
const sigInfo = steelSeal.signature(signateData)

// 把签名对象内的timestamp、nonce、signature拼接到query参数内并向目标服务发起请求
// 输出:https://127.0.0.1:8080/api/message/list?self_only=0&timestamp=1655956125&nonce=5yqXByu9&signature=6465a0b2ff69712c00a3430b26f4e1089c3ff851
const requestUrl = `https://127.0.0.1:8080/api/message/list?self_only=0&timestamp=${sigInfo.timestamp}&nonce=${sigInfo.nonce}&signature=${sigInfo.signature}`

const result = await fetch(requestUrl)

// TODO: 实现相关的业务逻辑
console.log(result)

验签(伪代码):

// 使用令牌初始化实例
import { SteelSeal } from "steel_seal"

const token = "2sqlFObdoqqYRpUFAGiGQecCwJ3Qw9je"
const steelSeal = new SteelSeal({ token })

......

// 从请求的query中解析timestamp、nonce、signature参数组装成签名对象,比如:
const sigInfo = {
    timestamp: 1655956125,
    nonce: '5yqXByu9',
    signature: '6465a0b2ff69712c00a3430b26f4e1089c3ff851'
}

// 从请求的query中解析其它参数组装成Object并序列化成JSON字符串
let query = { self_only: 0 }
const signateData = JSON.stringify(query) // 输出:'{"self_only":0}

// 使用 verify 方法对数据进行验签
const isValid = steelSeal.verify(signateData, sigInfo)

// 如果签名无效,则拒绝当前请求
if(!isValid) {
    // TODO: 拒绝请求
    return
}

// TODO: 实现具体的业务逻辑
console.log(result)

2、对POST请求进行签名和验签

示例:

fetch("https://127.0.0.1:8080/api/message/modify", {
  "headers": {
    "accept": "*/*",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
  }, 
    "data": '{"id":1,"content":"hello, world"}',
  "method": "POST",
  "mode": "cors",
  "credentials": "include"
});

签名(伪代码):

// 使用令牌初始化实例
import { SteelSeal } from "steel_seal"

const token = "2sqlFObdoqqYRpUFAGiGQecCwJ3Qw9je"
const steelSeal = new SteelSeal({ token })

......

// 把body参数组装成Dict并序列化成JSON字符串
let bodyStr = { id: 1, content: "hello, world" }
const signData = JSON.stringify(bodyStr) // 输出:'{"self_only":0}

// 使用 signature 方法对数据进行签名
// 输出:
//       {
//         timestamp: 1655956125,
//         nonce: '5yqXByu9',
//         signature: '6465a0b2ff69712c00a3430b26f4e1089c3ff851'
//       }
const sigInfo = steelSeal.signature(signData)

// 把签名对象内的timestamp、nonce、signature拼接到query参数内并向目标服务发起请求
// 输出:https://127.0.0.1:8080/api/message/modify?timestamp=1655956125&nonce=5yqXByu9&signature=6465a0b2ff69712c00a3430b26f4e1089c3ff851
const requestUrl = `https://127.0.0.1:8080/api/message/modify?timestamp=${sigInfo.timestamp}&nonce=${sigInfo.nonce}&signature=${sigInfo.signature}`

const result = await fetch(requestUrl, {method: "POST", body=bodyStr})

// TODO: 实现相关的业务逻辑
console.log(result)

验签(伪代码):

// 使用令牌初始化实例
import { SteelSeal } from "steel_seal"

const token = "2sqlFObdoqqYRpUFAGiGQecCwJ3Qw9je"
const steelSeal = new SteelSeal({ token })

......

// 从请求的query中解析timestamp、nonce、signature参数组装成签名对象,比如:
const sigInfo = {
    timestamp: 1655956125,
    nonce: '5yqXByu9',
    signature: '6465a0b2ff69712c00a3430b26f4e1089c3ff851'
}

// 从请求中读取原始的raw_body并使用verify方法进行验签
rawBody = "..."
const isValid = steelSeal.verify(rawBody, sigInfo)

// 如果签名无效,则拒绝当前请求
if(!isValid) {
    // TODO: 拒绝请求
    return
}

// TODO: 实现具体的业务逻辑
console.log(result)