# @edge-csrf/core 中文文档

规范地址：https://npmcn.com/package/%40edge-csrf/core/

版本：2\.5\.3-cloudflare-rc1
npm 元数据更新时间：2026-05-01T07:39:21.776Z
中文译文更新时间：2026-11-13T06:33:34.959Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40edge-csrf/core
原文对照：https://npmcn.com/package/%40edge-csrf/core/?lang=original
项目主页：https://github.com/kubetail-org/edge-csrf#readme
源码仓库：https://github.com/kubetail-org/edge-csrf

弃用说明：Package no longer supported\. Contact Support at https://www\.npmjs\.com/support for more info\.

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

- 包体积（解压后）：9.9 kB，6 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2024-04-19T17:16:23.881Z
- 最新版本发布：2024-11-21T11:28:46.698Z
- 近 30 天下载量：16877（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：23（近 12 个月 0 个）

## 中文简介

边缘- CSRF 核心 API

## 安装

```sh
npm install @edge-csrf/core
```

也可以使用：`pnpm add @edge-csrf/core`、`yarn add @edge-csrf/core`、`bun add @edge-csrf/core`

## README

# 核心 API

这是Edge-CSRF低级API的文档.

## 安装

```console
npm install @edge-csrf/core
# or
pnpm add @edge-csrf/core
# or
yarn add @edge-csrf/core
```

## 文档

兹将下列方法命名为出口: `@edge-csrf/core` 模块 :

```
createSecret(length) - Create new secret (cryptographically secure)

  * @param {int} length - Byte length of secret
  * @returns {Uint8Array} - The secret

createToken(secret, saltByteLength) - Create new CSRF token (cryptographically insecure
                                      salt hashed with secret)

  * @param {Uint8Array} secret - The secret
  * @param {int} saltByteLength - Salt length in number of bytes
  * @returns {Promise<Uint8Array>} - A promise returning the token in Uint8Array format

getTokenString(request) - Get the CSRF token from the request

  * @param {Request} request - The request object
  * @returns {Promise<string>} - A promise returning the token in string format

verifyToken(token, secret) - Verify the CSRF token and secret obtained from the request

  * @param {Uint8Array} token - The CSRF token
  * @param {Uint8Array} secret - The CSRF secret
  * @returns {Promise<boolean>} - A promise returning result of verification

utoa(input) - Encode Uint8Array as base64 string

  * @param {Uint8Array} input - The data to be converted from Uint8Array to base64
  * @returns {string} The base64 encoded string

atou(input) - Decode base64 string into Uint8Array

  * @param {string} input - The data to be converted from base64 to Uint8Array
  * @returns {Uint8Array} - The Uint8Array representing the input string
```

**说明**:如果你使用这些方法,你可能正在研究一个自定义框架集成. 如果有的话,请考虑向这个项目捐款!

## 常见问题

### @edge-csrf/core 是什么？

边缘- CSRF 核心 API注意：该包已被作者标记为弃用——Package no longer supported\. Contact Support at https://www\.npmjs\.com/support for more info\.

### 如何安装 @edge-csrf/core？

在项目目录运行 npm install @edge-csrf/core，或使用 pnpm add / yarn add / bun add。

### @edge-csrf/core 支持 TypeScript 吗？

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

### @edge-csrf/core 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @edge-csrf/core 可以商用吗？

@edge-csrf/core 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @edge-csrf/core 的下载量有多少？

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

### @edge-csrf/core 还在维护吗？

最新版本 2\.5\.3-cloudflare-rc1 发布于 2024/11/21（2 年前）；至今共发布 23 个版本，其中过去 12 个月发布了 0 个；首次发布于 2024/04/20。作者已将其标记为弃用，新项目建议寻找替代方案。

