# @exodus/bintoken 中文文档

规范地址：https://npmcn.com/package/%40exodus/bintoken/

版本：0\.1\.2
npm 元数据更新时间：2026-10-06T20:58:30.818Z
中文译文更新时间：2026-11-14T03:52:13.757Z
软件包许可：UNLICENSED

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40exodus/bintoken
原文对照：https://npmcn.com/package/%40exodus/bintoken/?lang=original
项目主页：https://github.com/ExodusMovement/bintoken#readme
源码仓库：https://github.com/ExodusMovement/bintoken

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：6.7 kB，5 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=12\.18\.0
- 运行依赖：0 个
- 首次发布：2021-05-25T22:17:06.071Z
- 最新版本发布：2023-03-15T15:02:36.593Z
- 近 30 天下载量：31021（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 0 个）

## 中文简介

命名的固定长度缓冲器的二进制编码.

## 安装

```sh
npm install @exodus/bintoken
```

也可以使用：`pnpm add @exodus/bintoken`、`yarn add @exodus/bintoken`、`bun add @exodus/bintoken`

## README

# 宾托肯

Bintoken 是一个固定长度的编码二进制消息,意在作为可以签名的信息. 根据类型字节,以及谁在宾托肯上签名,消息可能具有不同的含义.

例如,如果该类型表示消息是认证符,而宾托肯由服务器的私人密钥签名,这可能会提供一种保证,即服务器在宾托肯指定的时间验证出一些信息.

符号的编码格式通过即时 `BintokenEncoding` 此软件包导出类别。 编码用每个属性的属性名称和长度来指定. 密钥名称在编码和解码宾托肯时按字母顺序排序.

决定二进制格式简化了签名验证. 它的固定长度简化了解码和验证,从而减少了恶意剥削的机会. 与JSON等其他格式不同,只有 _一个_ 在宾托肯编码方案中编码消息的方式.

以下是任何宾托肯编码的通用序列化格式:

-   类型(1字节) : 可用于识别信件上下文的版本编号.
-   \[... 负载属性\]
-   时间(4个字节):创建消息时的时间戳(以unix秒计),编码为大端的uint32.

## 示例

以下是一个宾托肯编码的例子,它只将32字节的公钥编码为有效载荷:

```js
const BintokenEncoding = require('@exodus/bintoken')

const tokenEncoding = new BintokenEncoding({ publicKey: 32, hash: 20 })

const token = tokenEncoding.toBuffer({
  type: 1,
  publicKey: randomBytes(32),
  hash: randomBytes(20),
})

/*
  // Erroneous use
  const token = tokenEncoding.toBuffer({ type: 1, publicKey: randomBytes(32), hash: randomBytes(20), otherProp: Buffer.alloc(0) })
  const token = tokenEncoding.toBuffer({ type: 1, publicKey: randomBytes(31), hash: randomBytes(20) })
  const token = tokenEncoding.toBuffer({ type: 1, publicKey: 'foo', hash: randomBytes(20) })
  const token = tokenEncoding.toBuffer({ type: 1 })
*/

const { type, time, publicKey, hash } = tokenEncoding.fromBuffer(token)

/*
  // Error, wrong length
  const { type, time, publicKey } = tokenEncoding.fromBuffer(
    Buffer.concat([token, Buffer.alloc(1)])
  )
*/
```

在这个例子中,序列化格式是:

-   类型(1字节) : 可用于识别信件上下文的版本编号.
-   hash (20) 字节 : 消息具有意义(如类型所暗示的) 的散列.
-   public key (32字节) : 消息具有意义(由类型所暗示)的公钥.
-   时间(4个字节):信息创建时的时间戳(以秒为单位),编码为大端的uint32.

注意到 `hash` 写入 _在此之前_ `publicKey` 在有效载荷中,因为属性在被写入或读出宾托肯之前按字母顺序排序。 这意味着 **您为您信件选择的密钥必须使用相同的宾肯对不同的应用程序相同.**

## 常见问题

### @exodus/bintoken 是什么？

命名的固定长度缓冲器的二进制编码\.

### 如何安装 @exodus/bintoken？

在项目目录运行 npm install @exodus/bintoken，或使用 pnpm add / yarn add / bun add。

### @exodus/bintoken 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/exodus\_\_bintoken 是否存在。

### @exodus/bintoken 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @exodus/bintoken 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=12\.18\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @exodus/bintoken 可以商用吗？

@exodus/bintoken 使用 UNLICENSED 许可。作者声明为 UNLICENSED，即不授予公开使用许可（与公共领域的 Unlicense 不同）。使用前需获得作者授权。以上为概括，不构成法律意见，请以许可原文为准。

### @exodus/bintoken 的下载量有多少？

根据 npm 官方下载统计，@exodus/bintoken 在 2026/10/14 – 2026/11/12 这 30 天内被下载 31,021 次，日均约 1,034 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @exodus/bintoken 还在维护吗？

最新版本 0\.1\.2 发布于 2023/03/15（3 年前）；至今共发布 3 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/05/26。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

