@digitalcredentials/ed25519-verification-key-2020

中文文档
5.0.0发布于 2025/10/16BSD-3-ClauseTypeScriptES Module近 30 天下载 4.4万

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

中文使用文档
文档目录15 节
  1. 目录
  2. 背景情况
  3. 警卫
  4. 安装
  5. 使用量
  6. 生成新的公用/私用密钥对
  7. 从存储导入一对密钥
  8. 只导出公钥
  9. 导出完整的公-私密密钥配对
  10. 生成和验证密钥指纹
  11. 创建签名函数
  12. 创建验证函数
  13. 转换为和从以前的 Ed25519 验证Key2018 密钥类型
  14. 贡献
  15. 许可证

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

Node.js CI NPM Version

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

目录

背景情况

(从 digitalbazaar/ed25519-verification-key-2020 页:1 以提供类型脚本兼容性。 )

用于:

另见(相关规格):

警卫

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

安装

  • 需要节点.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] 可选的确定种子值,用于生成 键.
import {Ed25519VerificationKey2020} from '@digitalcredentials/ed25519-verification-key-2020';

const edKeyPair = await Ed25519VerificationKey2020.generate();

从存储导入一对密钥

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

const serializedKeyPair = { ... };

const keyPair = await Ed25519VerificationKey2020.from(serializedKeyPair);

只导出公钥

要导出一对的公钥 :

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

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

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

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

生成和验证密钥指纹

要生成指纹 :

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

为了验证指纹:

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

创建签名函数

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

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 函数,然后引用它(通过数据验证,和签名).

const keyPair = Ed25519VerificationKey2020.generate();

const {verify} = keyPair.verifier();

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

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

如果您已经序列化并存储了上一个密钥 Ed25519VerificationKey2018 密钥类型(例如,使用 页:1 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年转换实例:

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系列化的例子:

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

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

贡献

公关接受.

请遵照 标准读取 规格.

许可证

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

版本与发布记录

@digitalcredentials/ed25519-verification-key-2020 共发布 12 个版本,首次发布于 2021/05/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2025/10/161.1 年前
5.0.0-beta.2beta2025/05/161.5 年前
5.0.0-beta.12025/05/021.5 年前
4.0.02022/12/233 年前
3.2.22021/10/165 年前
3.2.12021/10/025 年前

关于 @digitalcredentials/ed25519-verification-key-2020 的常见问题

@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 和提交记录判断。