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

@ikenxuan/xhshow-ts

v1.0.1

Published

XHS API signature generator

Readme

xhshow-ts

小红书请求签名生成库的 TypeScript 实现,支持 GET/POST 请求的 x-s 和 x-s-common 签名。本 Fork 代码由 AI 生成,仅供个人使用,不保证与上游仓库行为一致。

系统要求

  • Node.js 16+
  • TypeScript 5.0+ (可选,用于开发)

安装

npm install @ikenxuan/xhshow-ts

或使用其他包管理器:

# 使用 yarn
yarn add @ikenxuan/xhshow-ts

# 使用 pnpm
pnpm add @ikenxuan/xhshow-ts

使用方法

ESM (推荐)

import { Xhshow } from '@ikenxuan/xhshow-ts'

const client = new Xhshow()

// GET请求签名
const getSignature = client.signXsGet(
  "/api/sns/web/v1/user_posted",
  "your_a1_cookie_value",
  "xhs-pc-web",
  { num: "30", cursor: "", user_id: "123" }
)

// POST请求签名
const postSignature = client.signXsPost(
  "/api/sns/web/v1/login",
  "your_a1_cookie_value", 
  "xhs-pc-web",
  { username: "test", password: "123456" }
)

// x-s-common 签名
const xsCommon = client.signXsc({
  a1: "your_a1_cookie_value",
  web_session: "your_web_session"
})

// 一次性生成所有请求头
const headers = client.signHeadersGet(
  "/api/sns/web/v1/user_posted",
  { a1: "your_a1_cookie_value", web_session: "..." },
  "xhs-pc-web",
  { num: "30" }
)
// headers 包含: x-s, x-s-common, x-t, x-b3-traceid, x-xray-traceid

CommonJS

const { Xhshow } = require('@ikenxuan/xhshow-ts')

const client = new Xhshow()

// GET请求签名
const getSignature = client.signXsGet(
  "/api/sns/web/v1/user_posted",
  "your_a1_cookie_value",
  "xhs-pc-web",
  { num: "30", cursor: "", user_id: "123" }
)

通用方法

import { Xhshow } from '@ikenxuan/xhshow-ts'

const client = new Xhshow()

// 通用签名方法
const signature = client.signXs(
  "GET",  // 或 "POST"
  "/api/sns/web/v1/user_posted",
  "your_a1_cookie_value",
  "xhs-pc-web",
  { num: "30", cursor: "", user_id: "123" }
)

API 参考

Xhshow 类

signXs(method, uri, a1Value, xsecAppid?, payload?, timestamp?)

通用签名方法

  • method: 'GET' | 'POST' - 请求方法
  • uri: string - 请求URI(支持完整URL或仅路径)
  • a1Value: string - cookie中的a1值
  • xsecAppid: string - 应用标识符,默认为 'xhs-pc-web'
  • payload: Record<string, any> | null - 请求参数
  • timestamp: number - Unix时间戳(秒),默认为当前时间

signXsGet(uri, a1Value, xsecAppid?, params?, timestamp?)

GET请求专用签名方法

signXsPost(uri, a1Value, xsecAppid?, payload?, timestamp?)

POST请求专用签名方法

signXsCommon(cookieDict) / signXsc(cookieDict)

生成 x-s-common 签名

  • cookieDict: Record<string, any> | string - 完整的cookie字典或cookie字符串

signHeaders(method, uri, cookies, xsecAppid?, params?, payload?, timestamp?)

一次性生成完整的请求头

  • 返回包含 x-s, x-s-common, x-t, x-b3-traceid, x-xray-traceid 的对象

signHeadersGet(uri, cookies, xsecAppid?, params?, timestamp?)

GET请求专用的完整请求头生成方法

signHeadersPost(uri, cookies, xsecAppid?, payload?, timestamp?)

POST请求专用的完整请求头生成方法

decodeXs(xsSignature)

解密完整的 XYS 签名

decodeX3(x3Signature)

解密 x3 签名

buildUrl(baseUrl, params?)

构建带查询参数的完整URL

buildJsonBody(payload)

构建POST请求的JSON body字符串

getB3TraceId()

生成 x-b3-traceid

getXrayTraceId(timestamp?, seq?)

生成 x-xray-traceid

getXT(timestamp?)

生成 x-t 头部值(毫秒时间戳)

类型定义

type Method = 'GET' | 'POST'
type Payload = Record<string, any> | null

class Xhshow {
  signXs(method: Method, uri: string, a1Value: string, xsecAppid?: string, payload?: Payload, timestamp?: number): string
  signXsGet(uri: string, a1Value: string, xsecAppid?: string, params?: Payload, timestamp?: number): string
  signXsPost(uri: string, a1Value: string, xsecAppid?: string, payload?: Payload, timestamp?: number): string
  signXsCommon(cookieDict: Record<string, any> | string): string
  signXsc(cookieDict: Record<string, any> | string): string
  signHeaders(method: Method, uri: string, cookies: Record<string, any> | string, xsecAppid?: string, params?: Payload, payload?: Payload, timestamp?: number): Record<string, string>
  signHeadersGet(uri: string, cookies: Record<string, any> | string, xsecAppid?: string, params?: Payload, timestamp?: number): Record<string, string>
  signHeadersPost(uri: string, cookies: Record<string, any> | string, xsecAppid?: string, payload?: Payload, timestamp?: number): Record<string, string>
  decodeXs(xsSignature: string): Record<string, any>
  decodeX3(x3Signature: string): Uint8Array
  buildUrl(baseUrl: string, params?: Record<string, any> | null): string
  buildJsonBody(payload: Record<string, any>): string
  getB3TraceId(): string
  getXrayTraceId(timestamp?: number, seq?: number): string
  getXT(timestamp?: number): number
}

开发环境

环境准备

# 克隆项目
git clone https://github.com/ikenxuan/xhshow-ts
cd xhshow-ts

# 安装依赖
npm install

开发流程

# 开发模式(监听文件变化)
npm run dev

# 构建项目
npm run build

项目结构

src/
├── client.ts          # 主要客户端类
├── core/              # 核心加密处理
│   ├── crypto.ts      # 加密处理器
│   ├── commonSign.ts  # x-s-common 签名
│   └── crc32.ts       # CRC32 实现
├── config/            # 配置文件
├── data/              # 指纹数据
├── generators/        # 指纹生成器
├── utils/             # 工具函数
├── validators.ts      # 参数验证
└── index.ts           # 入口文件

License

MIT