# @atcute/cid 中文文档

规范地址：https://npmcn.com/package/%40atcute/cid/

版本：2\.5\.0
npm 元数据更新时间：2026-09-24T03:30:50.829Z
中文译文更新时间：2026-11-07T01:50:21.220Z
软件包许可：0BSD

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

原始 npm 页面：https://www.npmjs.com/package/%40atcute/cid
原文对照：https://npmcn.com/package/%40atcute/cid/?lang=original
源码仓库：https://tangled.org/did:plc:pljn5qch4tgadongtc7i6qij

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

- 包体积（解压后）：14.6 kB，9 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：2 个
- 首次发布：2024-08-18T04:18:00.833Z
- 最新版本发布：2026-09-24T03:30:50.624Z
- 近 30 天下载量：318528（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：19（近 12 个月 5 个）

## 中文简介

aT 协议的轻量级 DASL CID 编码库

## 安装

```sh
npm install @atcute/cid
```

也可以使用：`pnpm add @atcute/cid`、`yarn add @atcute/cid`、`bun add @atcute/cid`

## README

# @ tcute/ cid (帮助)

aT协议的内容标识符(CID)编码克.

```sh
npm install @atcute/cid
```

此库执行 DASL 的 [刑事调查司](https://dasl.ing/cid.html) aT 议定书用于处理 他们的内容.

## 使用量

```ts
import * as CID from '@atcute/cid';
import { toCidLink, fromCidLink, isCidLink } from '@atcute/cid';

// create a CID by hashing data (0x71 for DAG-CBOR, 0x55 for raw)
const cid = await CID.create(0x71, cborBytes);
// -> { version: 1, codec: 113, digest: { codec: 18, contents: Uint8Array(32) }, bytes: Uint8Array(36) }

// parse from base32 string
const parsed = CID.fromString('bafyreihffx5a2e7k5uwrmmgofbvzujc5cmw5h4espouwuxt3liqoflx3ee');

// parse from binary (with 0x00 prefix) or raw CID bytes
const fromBin = CID.fromBinary(binaryBytes);
const fromRaw = CID.decode(cidBytes);

// serialize to base32 string or binary format
CID.toString(cid); // -> "bafyreihffx5a2e7k5uwrmmgofbvzujc5cmw5h4espouwuxt3liqoflx3ee"
CID.toBinary(cid); // -> Uint8Array(37) with 0x00 prefix

// compare two CIDs
CID.equals(cidA, cidB); // -> true if identical

// convert to CidLink for JSON serialization (atproto data model)
const link = toCidLink(cid); // -> { $link: "bafyrei..." }
const back = fromCidLink(link);

// type guard for CidLink
if (isCidLink(value)) {
    console.log(value.$link);
}
```

## 常见问题

### @atcute/cid 是什么？

aT 协议的轻量级 DASL CID 编码库

### 如何安装 @atcute/cid？

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

### @atcute/cid 支持 TypeScript 吗？

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

### @atcute/cid 支持 ESM 还是 CommonJS？

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

### @atcute/cid 可以商用吗？

@atcute/cid 使用 0BSD 许可。几乎没有限制：可自由使用、修改和分发，连保留版权声明也不要求。以上为概括，不构成法律意见，请以许可原文为准。

### @atcute/cid 的下载量有多少？

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

### @atcute/cid 还在维护吗？

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

