@chainsafe/bls-keystore
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

@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

Package Sidebar

Install

npm i @chainsafe/bls-keystore

Weekly Downloads

1,029

Version

3.0.1

License

MIT

Unpacked Size

104 kB

Total Files

23

Last publish

Collaborators

  • sadiq1971
  • ansermino
  • gregthegreek
  • priom
  • wemeetagain
  • mpetrunic