@chainsafe/bls-keystore

中文文档
3.1.0发布于 2024/07/16MITTypeScriptCommonJS近 30 天下载 1.5万
原始使用文档

@ChainSafe/bls-keystore

npm Discord License: MIT es-version node-version

Typescript implementation of EIP 2335 for node and browser.

How to use?

Functional interface

import {Buffer} from "buffer";
import {
  IKeystore,
  create,
  decrypt,
  verifyPassword,
  isValidKeystore,
  validateKeystore,
} from "@chainsafe/bls-keystore";

// encrypt private key
const password: string | Uint8Array = "SomePassword123"; 
const privateKey: Uint8Array = ...;
const publicKey: Uint8Array = ...;
const path: string = "m/12381/60/0/0";

// keystore is an `object` that follows the EIP-2335 schema
const keystore: IKeystore = await create(password, privateKey, publicKey, path);

// verify password
await verifyPassword(keystore, password); //true | false

// decrypt
const decryptedPrivateKey: Buffer = await decrypt(keystore, password);

// convert to string
JSON.stringify(keystore); //string

// determine if unsanitized data fits the EIP-2335 schema
const data: unknown = ...;
isValidKeystore(data); // true | false

validateKeystore(data); // throws if invalid

Class-based interface

import {Buffer} from "buffer";
import {
  Keystore,
} from "@chainsafe/bls-keystore";

// encrypt private key
const password: string | Uint8Array = "SomePassword123"; 
const privateKey: Uint8Array = ...;
const publicKey: Uint8Array = ...;
const path: string = "m/12381/60/0/0";

// keystore is a `Keystore` instance that follows the EIP-2335 schema with additional convenience methods
const keystore: Keystore = await Keystore.create(password, privateKey, publicKey, path);

// verify password
await keystore.verifyPassword(password); //true | false

// decrypt
const decryptedPrivateKey: Buffer = await keystore.decrypt(password);

// convert to string
keystore.stringify(); //string

// determine if unsanitized data fits the EIP-2335 schema
const data: unknown = ...;
Keystore.fromObject(data); // returns a Keystore or throws if data is invalid

For key derivation checkout @chainsafe/bls-keygen

Contribute

  • get yarn
  • yarn install
  • yarn test

版本与发布记录

@chainsafe/bls-keystore 共发布 6 个版本,首次发布于 2020/02/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.1.0latest2024/07/162 年前
3.0.12024/01/312 年前
3.0.02022/02/234 年前
2.0.02020/07/176 年前
1.0.0-beta82020/07/086 年前
1.0.0-beta72020/02/116 年前

关于 @chainsafe/bls-keystore 的常见问题

@chainsafe/bls-keystore 是什么?

[](https://opensource.org/

如何安装 @chainsafe/bls-keystore?

在项目目录运行 npm install @chainsafe/bls-keystore,或使用 pnpm add / yarn add / bun add。

@chainsafe/bls-keystore 支持 TypeScript 吗?

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

@chainsafe/bls-keystore 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@chainsafe/bls-keystore 可以商用吗?

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

@chainsafe/bls-keystore 的下载量有多少?

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

@chainsafe/bls-keystore 还在维护吗?

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