@digitalcredentials/ed25519-multikey

中文文档
1.4.0发布于 2025/04/30ES Module近 30 天下载 1.2万

Javascript library for generating and working with Ed25519Multikey key pairs.

原始使用文档
文档目录15 节
  1. Table of Contents
  2. Background
  3. Security
  4. Install
  5. Usage
  6. Generating a new public/secret key pair
  7. Importing a key pair from storage
  8. Exporting the public key only
  9. Exporting the full public-secret key pair
  10. Creating a signer function
  11. Creating a verifier function
  12. Converting from previous Ed25519VerificationKey2020 key type
  13. Converting from previous Ed25519VerificationKey2018 key type
  14. Contribute
  15. License

Ed25519Multikey Key Pair Library for Linked Data (@digitalcredentials/ed25519-multikey)

NPM Version

Javascript library for generating and working with Ed25519Multikey key pairs.

NOTE: this is a fork of @digitalbazaar/ed25519-multikey to add support for react native. The only fundamental change is to add this react native override that uses @noble/ed25519 for cryptography in react native.

Table of Contents

Background

For use with:

See also (related specs):

Security

As with most security- and cryptography-related tools, the overall security of your system will largely depend on your design decisions.

Install

  • Node.js 16+ is required.

To install locally (for development):

git clone https://github.com/digitalbazaar/ed25519-multikey.git
cd ed25519-multikey
npm install

Usage

Generating a new public/secret key pair

To generate a new public/secret key pair:

  • {string} [id] Optional id for the generated key.
  • {string} [controller] Optional controller URI or DID to initialize the generated key. (This will also init the key id.)
  • {string} [seed] Optional deterministic seed value from which to generate the key.
import * as Ed25519Multikey from '@digitalbazaar/ed25519-multikey';

const edKeyPair = await Ed25519Multikey.generate();

Importing a key pair from storage

To create an instance of a public/secret key pair from data imported from storage, use .from():

const serializedKeyPair = { ... };

const keyPair = await Ed25519Multikey.from(serializedKeyPair);

Exporting the public key only

To export just the public key of a pair:

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

Exporting the full public-secret key pair

To export the full key pair, including secret key (warning: this should be a carefully considered operation, best left to dedicated Key Management Systems):

await keyPair.export({publicKey: true, secretKey: true});
// ->
{
  type: 'Multikey',
  id: 'did:example:1234#z6Mkon3Necd6NkkyfoGoHxid2znGc59LU3K7mubaRcFbLfLX',
  controller: 'did:example:1234',
  publicKeyMultibase: 'z6Mkon3Necd6NkkyfoGoHxid2znGc59LU3K7mubaRcFbLfLX',
  secretKeyMultibase: 'zruzf4Y29hDp7vLoV3NWzuymGMTtJcQfttAWzESod4wV2fbPvEp4XtzGp2VWwQSQAXMxDyqrnVurYg2sBiqiu1FHDDM'
}

Creating a signer function

In order to perform a cryptographic signature, you need to create a sign function, and then invoke it.

const keyPair = Ed25519Multikey.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});

Creating a verifier function

In order to verify a cryptographic signature, you need to create a verify function, and then invoke it (passing it the data to verify, and the signature).

const keyPair = Ed25519Multikey.generate();

const {verify} = keyPair.verifier();

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

Converting from previous Ed25519VerificationKey2020 key type

If you have serialized and stored keys of the previous Ed25519VerificationKey2020 key type (for example, generated using the ed25519-verification-key-2020) library, things to keep in mind:

  • Instances of those key types still contain the same key material, the only thing that has changed from the 2020 suite to Multikey is the property name change for storing the secret key and replacing the type with Multikey. The 2020 suite key types serialize using the type Ed25519VerificationKey2020 and stored secret key material in privateKeyMultibase, and the Ed25519 Multikey (this repo) serializes using corresponding the type Multikey an stores the secret key material in secretKeyMultibase property.
  • You can convert from the 2020 key type to Multikey using the provided Ed25519Multikey.from() method (see below).
  • They generate() the same key material, given the same seed parameter.
  • Both the 2020 and Multikey keys produce and verify the same signatures.

Example of converting:

import * as Ed25519Multikey from '@digitalcredentials/ed25519-multikey';
import {Ed25519VerificationKey2020}
  from '@digitalbazaar/ed25519-verification-key-2020';


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

const ed25519Multikey = await Ed25519Multikey.from(keyPair2020);

// The resulting ed25519Multikey will have the same `id` and `controller` properties
// as its 2020 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 signatureBytes2020 = await keyPair2020.signer().sign({data});

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

Converting from previous Ed25519VerificationKey2018 key type

If you have serialized and stored keys of the previous Ed25519VerificationKey2018 key type (for example, generated using the ed25519-verification-key-2018) library, things to keep in mind:

  • Instances of those key types still contain the same key material, the only thing that has changed from the 2018 suite to Multikey is the way the public and secret key material is serialized when exporting. The 2018 suite key types serialize using the publicKeyBase58 and secretKeyBase58 properties, and the Ed25519 Multikey (this repo) serializes using corresponding publicKeyMultibase and secretKeyMultibase property.
  • You can convert from the 2018 key type to Multikey using the provided Ed25519Multikey.from() method (see below).
  • They generate() the same key material, given the same seed parameter.
  • Both the 2018 and Multikey keys produce and verify the same signatures.

Example of converting:

import * as Ed25519Multikey from '@digitalcredentials/ed25519-multikey';
import {Ed25519VerificationKey2018}
  from '@digitalbazaar/ed25519-verification-key-2018';


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

const ed25519Multikey = await Ed25519Multikey.from(keyPair2018);

// The resulting ed25519Multikey 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 ed25519Multikey.verifier().verify({data, signature: signatureBytes2018})
// true

Contribute

See the contribute file!

PRs accepted.

If editing the Readme, please conform to the standard-readme specification.

License

MIT License © 2025 Digital Credentials Consortium.

版本与发布记录

@digitalcredentials/ed25519-multikey 共发布 6 个版本,首次发布于 2025/02/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.0latest2025/04/301.5 年前
1.4.0-beta.1beta2025/03/141.7 年前
1.3.3-beta.42025/02/071.8 年前
1.3.3-beta.32025/02/071.8 年前
1.3.3-beta.22025/02/071.8 年前
1.3.3-beta.12025/02/061.8 年前

关于 @digitalcredentials/ed25519-multikey 的常见问题

@digitalcredentials/ed25519-multikey 是什么?

Javascript library for generating and working with Ed25519Multikey key pairs.

如何安装 @digitalcredentials/ed25519-multikey?

在项目目录运行 npm install @digitalcredentials/ed25519-multikey,或使用 pnpm add / yarn add / bun add。

@digitalcredentials/ed25519-multikey 支持 TypeScript 吗?

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

@digitalcredentials/ed25519-multikey 支持 ESM 还是 CommonJS?

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

@digitalcredentials/ed25519-multikey 需要什么版本的 Node.js?

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

@digitalcredentials/ed25519-multikey 可以商用吗?

@digitalcredentials/ed25519-multikey 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@digitalcredentials/ed25519-multikey 的下载量有多少?

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

@digitalcredentials/ed25519-multikey 还在维护吗?

最新版本 1.4.0 发布于 2025/04/30(1.5 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/02/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。