@arcjet/stable-hash

中文文档
1.15.0发布于 2026/10/29Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 32.8万

Arcjet stable hashing utility

原始使用文档
文档目录14 节
  1. What is this?
  2. When should I use this?
  3. Install
  4. Use
  5. API
  6. FieldHasher
  7. StringWriter
  8. bool(key, value)
  9. hash(…hashers)
  10. makeHasher(subtle)
  11. stringSliceOrdered(key, values)
  12. string(key, value)
  13. uint32(key, value)
  14. License
Arcjet Logo

@arcjet/stable-hash

npm badge

Arcjet stable hashing utility.

What is this?

This is an internal utility to help us create stable hashes. It’s super minimal and matches similar internal code in other languages. This exists to make sure things work the same across languages.

When should I use this?

This is an internal Arcjet package not designed for public use. See our Get started guide for how to use Arcjet in your application.

Install

This package is ESM only. Install with npm in Node.js:

npm install @arcjet/stable-hash

Use

import * as hasher from "@arcjet/stable-hash";

const id = await hasher.hash(
  hasher.string("type", "EMAIL"),
  hasher.uint32("version", 0),
  hasher.string("mode", "LIVE"),
  hasher.stringSliceOrdered("allow", []),
  hasher.stringSliceOrdered("deny", []),
);

console.log(id);
// => 49573b7df8d854c2cd5d8a755a4c03aff4014493a41b963490861a279ad675b2

API

This package exports the identifiers bool, hash, makeHasher, stringSliceOrdered, string, and uint32. There is no default export.

This package exports the TypeScript types FieldHasher and StringWriter.

FieldHasher

This type represents a function that hashes a single field. You get one of these back from bool, string, stringSliceOrdered, and uint32.

Type
type FieldHasher = (data: StringWriter) => void;

StringWriter

This type represents a writer that the hasher writes data into.

Fields
  • writeString(data: string): void — writes data to the hash

bool(key, value)

Creates a field hasher for a boolean value.

Parameters
  • key (string) — the field name
  • value (boolean) — the boolean value to hash
Returns

A field hasher (FieldHasher).

hash(…hashers)

Hashes multiple fields together and returns a stable hash string. You pass in the field hashers created by bool, string, stringSliceOrdered, and uint32.

Parameters
Returns

A Promise that resolves to the hash (Promise<string>).

makeHasher(subtle)

Creates a new hash function using the provided SubtleCrypto implementation. We use this internally to support different crypto implementations across runtimes.

Parameters
  • subtle (SubtleCryptoLike) — a SubtleCrypto-like implementation
Returns

A hash function (hash).

stringSliceOrdered(key, values)

Creates a field hasher for an ordered array of strings.

Parameters
  • key (string) — the field name
  • values (ReadonlyArray<string>) — the string array to hash
Returns

A field hasher (FieldHasher).

string(key, value)

Creates a field hasher for a string value.

Parameters
  • key (string) — the field name
  • value (string) — the string value to hash
Returns

A field hasher (FieldHasher).

uint32(key, value)

Creates a field hasher for an unsigned 32-bit integer.

Parameters
  • key (string) — the field name
  • value (number) — the integer value to hash
Returns

A field hasher (FieldHasher).

License

Apache License, Version 2.0 © Arcjet Labs, Inc.

Derivative work based on feross/buffer licensed under MIT © Feross Aboukhadijeh and contributors. Our work picks its internal hex encoding logic adjusted for our use.

版本与发布记录

@arcjet/stable-hash 共发布 38 个版本,首次发布于 2025/05/07;过去 12 个月发布了 30 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.15.0latest2026/10/298 天前
1.14.12026/10/0730 天前
1.14.02026/10/021 个月前
1.13.02026/09/171 个月前
1.12.02026/09/091 个月前
1.11.02026/08/272 个月前

其他发布通道:rc → 1.10.0-rc.1。

关于 @arcjet/stable-hash 的常见问题

@arcjet/stable-hash 是什么?

Arcjet stable hashing utility

如何安装 @arcjet/stable-hash?

在项目目录运行 npm install @arcjet/stable-hash,或使用 pnpm add / yarn add / bun add。

@arcjet/stable-hash 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@arcjet/stable-hash 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@arcjet/stable-hash 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.21.0 <23 || >=24.5.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@arcjet/stable-hash 可以商用吗?

@arcjet/stable-hash 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@arcjet/stable-hash 的下载量有多少?

根据 npm 官方下载统计,@arcjet/stable-hash 在 2026/10/07 – 2026/11/05 这 30 天内被下载 328,218 次,日均约 10,941 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@arcjet/stable-hash 还在维护吗?

最新版本 1.15.0 发布于 2026/10/29(8 天前);至今共发布 38 个版本,其中过去 12 个月发布了 30 个;首次发布于 2025/05/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。