# @digitalcredentials/ed25519-verification-key-2020 中文文档

规范地址：https://npmcn.com/package/%40digitalcredentials/ed25519-verification-key-2020/

版本：5\.0\.0
npm 元数据更新时间：2026-09-30T17:46:16.771Z
中文译文更新时间：2026-11-12T08:52:51.049Z
软件包许可：BSD-3-Clause

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

原始 npm 页面：https://www.npmjs.com/package/%40digitalcredentials/ed25519-verification-key-2020
原文对照：https://npmcn.com/package/%40digitalcredentials/ed25519-verification-key-2020/?lang=original
项目主页：https://github.com/digitalcredentials/ed25519-verification-key-2020
源码仓库：https://github.com/digitalcredentials/ed25519-verification-key-2020

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

- 包体积（解压后）：74.7 kB，32 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=20
- 运行依赖：4 个
- 首次发布：2021-05-19T19:13:48.162Z
- 最新版本发布：2025-10-16T01:03:22.323Z
- 近 30 天下载量：44349（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：12（近 12 个月 0 个）

## 中文简介

Javascript 库,用于生成并和 Ed25519VerificationKey2020 密钥对一起工作,用于加密-ld.

## 安装

```sh
npm install @digitalcredentials/ed25519-verification-key-2020
```

也可以使用：`pnpm add @digitalcredentials/ed25519-verification-key-2020`、`yarn add @digitalcredentials/ed25519-verification-key-2020`、`bun add @digitalcredentials/ed25519-verification-key-2020`

## README

# Ed25519 验证Key2020 链接数据密钥对等库 _(@数字证书/ed25519-核查-钥匙-2020)_

[![Node.js CI](https://github.com/digitalcredentials/ed25519-verification-key-2020/workflows/Node.js%20CI/badge.svg)](https://github.com/digitalcredentials/ed25519-verification-key-2020/actions?query=workflow%3A%22Node.js+CI%22) [![NPM Version](https://img.shields.io/npm/v/@digitalcredentials/ed25519-verification-key-2020.svg)](https://npm.im/@digitalcredentials/ed25519-verification-key-2020)

> Typescript/Javascript 库,用于生成并配合 Ed25519VerificationKey2020 密钥对,用于加密-ld.

## 目录

-   [背景情况](https://npmcn.com/package/%40digitalcredentials/ed25519-verification-key-2020/#readme-background)
-   [警卫](https://npmcn.com/package/%40digitalcredentials/ed25519-verification-key-2020/#readme-security)
-   [安装](https://npmcn.com/package/%40digitalcredentials/ed25519-verification-key-2020/#readme-install)
-   [使用量](https://npmcn.com/package/%40digitalcredentials/ed25519-verification-key-2020/#readme-usage)
-   [贡献](https://npmcn.com/package/%40digitalcredentials/ed25519-verification-key-2020/#readme-contribute)
-   [商业支助](https://npmcn.com/package/%40digitalcredentials/ed25519-verification-key-2020/#readme-commercial-support)
-   [许可证](https://npmcn.com/package/%40digitalcredentials/ed25519-verification-key-2020/#readme-license)

## 背景情况

(从 [`digitalbazaar/ed25519-verification-key-2020` 页:1](https://github.com/digitalbazaar/ed25519-verification-key-2020) 以提供类型脚本兼容性。 )

用于:

-   [`@digitalcredentials/ed25519-signature-2020`](https://github.com/digitalcredentials/ed25519-signature-2020) `^2.0.0` 密码套件( 有 [`linked-data-integrity`](https://github.com/digitalcredentials/linked-data-integrity)(中文(简体) )
-   [`@digitalcredentials/vc`](https://github.com/digitalcredentials/vc) `^2.0.0`

另见(相关规格):

-   [Ed25519 核查Key 2020](https://w3c-ccg.github.io/lds-ed25519-2020/#ed25519verificationkey2020) 谱.

## 警卫

同大多数与安全和密码学有关的工具一样 您的系统将在很大程度上取决于您的设计决定 .

## 安装

-   需要节点.js 20+.

在当地安装(用于开发):

```
git clone https://github.com/digitalcredentials/ed25519-verification-key-2020.git
cd ed25519-verification-key-2020
npm install
```

## 使用量

### 生成新的公用/私用密钥对

要生成一个新的公/私密密钥配对 :

-   `{string} [controller]` 可选控制器 URI 或 Did 初始化 生成了密钥。 (此会输入密钥 ID. )
-   `{string} [seed]` 可选的确定种子值,用于生成 键.

```js
import {Ed25519VerificationKey2020} from '@digitalcredentials/ed25519-verification-key-2020';

const edKeyPair = await Ed25519VerificationKey2020.generate();
```

### 从存储导入一对密钥

从下列数据中创建公/私密密钥对实例: 存储,使用 `.from()`数字 :

```js
const serializedKeyPair = { ... };

const keyPair = await Ed25519VerificationKey2020.from(serializedKeyPair);
```

### 只导出公钥

要导出一对的公钥 :

```js
await keyPair.export({publicKey: true});
// ->
{
  type: 'Ed25519VerificationKey2020',
  id: 'did:example:1234#z6MkszZtxCmA2Ce4vUV132PCuLQmwnaDD5mw2L23fGNnsiX3',
  controller: 'did:example:1234',
  publicKeyMultibase: 'zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf'
}
```

### 导出完整的公-私密密钥配对

要导出完整一对密钥, 包括私钥( 警告 : 这应该是 仔细考虑的操作,最好留给专用密钥管理系统:

```js
await keyPair.export({publicKey: true, privateKey: true});
// ->
{
  type: 'Ed25519VerificationKey2020',
  id: 'did:example:1234#z6MkszZtxCmA2Ce4vUV132PCuLQmwnaDD5mw2L23fGNnsiX3',
  controller: 'did:example:1234',
  publicKeyMultibase: 'zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf',
  privateKeyMultibase: 'z4E7Q4neNHwv3pXUNzUjzc6TTYspqn9Aw6vakpRKpbVrCzwKWD4hQDHnxuhfrTaMjnR8BTp9NeUvJiwJoSUM6xHAZ'
}
```

### 生成和验证密钥指纹

要生成指纹 :

```js
keyPair.fingerprint();
// ->
'z6MkszZtxCmA2Ce4vUV132PCuLQmwnaDD5mw2L23fGNnsiX3'
```

为了验证指纹:

```js
const fingerprint = 'z6MkszZtxCmA2Ce4vUV132PCuLQmwnaDD5mw2L23fGNnsiX3';
keyPair.verifyFingerprint({fingerprint});
// ->
{verified: true}
```

### 创建签名函数

为了执行加密签名,您需要创建 `sign` 函数,然后引用它.

```js
const keyPair = Ed25519VerificationKey2020.generate();

const {sign} = keyPair.signer();

// data is a Uint8Array of bytes
const data = (new TextEncoder()).encode('test data goes here');
// Signing also outputs a Uint8Array, which you can serialize to text etc.
const signatureValueBytes = await sign({data});
```

### 创建验证函数

为了验证密码签名,您需要创建 `verify` 函数,然后引用它(通过数据验证,和签名).

```js
const keyPair = Ed25519VerificationKey2020.generate();

const {verify} = keyPair.verifier();

const verified = await verify({data, signature});
// true
```

### 转换为和从以前的 Ed25519 验证Key2018 密钥类型

如果您已经序列化并存储了上一个密钥 `Ed25519VerificationKey2018` 密钥类型(例如,使用 页:1 [`ed25519-verification-key-2018`](https://github.com/digitalbazaar/ed25519-verification-key-2018)(中文(简体) ) 库,或使用 `Ed25519KeyPair` 捆绑的密钥 `crypto-ld v3.x`, (中文(简体) ), 记住的事情:

-   这些关键类型的实例仍然包含同样的关键材料,即: 从2018年套房到2020年套房的改变 就是公众的方式 和私人关键材料在出口时进行序列化。 2018套房密钥 类型 `publicKeyBase58` 财务报告和审定财务报表 `privateKeyBase58` 属性, 和 2020 套接字密钥( 此回波) 使用相应的 `publicKeyMultibase` 财务报告和审定财务报表 `privateKeyMultibase` 属性.
-   您可以使用 2018 密钥类型转换为 2020 密钥类型 `Ed25519VerificationKey2020.fromEd25519VerificationKey2018()` 方法(见下文).
-   他们 `generate()` 相同的关键材料,考虑到相同的 `seed` 参数.
-   2018年和2020年的密钥都产生并验证了相同的签名.

2018年转换实例:

```js
import {Ed25519VerificationKey2018}
  from '@digitalbazaar/ed25519-verification-key-2018';
import {Ed25519VerificationKey2020}
  from '@digitalbazaar/ed25519-verification-key-2020';

const keyPair2018 = await Ed25519VerificationKey2018.generate({
  controller: 'did:example:1234'
});

const keyPair2020 = await Ed25519VerificationKey2020
  .fromEd25519VerificationKey2018({keyPair: keyPair2018});

// The resulting keyPair2020 will have the same `id` and `controller` properties
// as its 2018 source. They will also produce and verify the same signatures.

// data is a Uint8Array of bytes
const data = (new TextEncoder()).encode('test data goes here');
const signatureBytes2018 = await keyPair2018.signer().sign({data});

// this is the same signature as that produced by the 2020 key. And will verify
// the same.
await keyPair2020.verifier().verify({data, signature: signatureBytes2018})
// true
```

转换到2018系列化的例子:

```js
const keyPair2020 = await Ed25519VerificationKey2020.generate({
  controller: 'did:example:1234'
});

const keyObject2018 = keyPair2020.toEd255519VerificationKey2018({
  publicKey: true, privateKey: true, includeContext: true
});
```

## 贡献

公关接受.

请遵照 [标准读取](https://github.com/RichardLitt/standard-readme) 规格.

## 许可证

-   MIT许可证 - DCC - TypeScript兼容.
-   新BSD许可证 (3-clause) 2020-2021 Digital Bazaar - 初始实施.

## 常见问题

### @digitalcredentials/ed25519-verification-key-2020 是什么？

Javascript 库,用于生成并和 Ed25519VerificationKey2020 密钥对一起工作,用于加密-ld\.

### 如何安装 @digitalcredentials/ed25519-verification-key-2020？

在项目目录运行 npm install @digitalcredentials/ed25519-verification-key-2020，或使用 pnpm add / yarn add / bun add。

### @digitalcredentials/ed25519-verification-key-2020 支持 TypeScript 吗？

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

### @digitalcredentials/ed25519-verification-key-2020 支持 ESM 还是 CommonJS？

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

### @digitalcredentials/ed25519-verification-key-2020 需要什么版本的 Node\.js？

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

### @digitalcredentials/ed25519-verification-key-2020 可以商用吗？

@digitalcredentials/ed25519-verification-key-2020 使用 BSD-3-Clause 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括，不构成法律意见，请以许可原文为准。

### @digitalcredentials/ed25519-verification-key-2020 的下载量有多少？

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

### @digitalcredentials/ed25519-verification-key-2020 还在维护吗？

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

