This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
chainsafe-bls/README.md

2.3 KiB

bls

Build Status codecov ETH2.0_Spec_Version 0.12.0 ES Version Node Version

Javascript library for BLS (Boneh-Lynn-Shacham) signatures and signature aggregation.

Usage

yarn add @chainsafe/bls

You must initialize the library once in your application before using it. The result is cached and use across all your imports

import bls, {init} from "@chainsafe/bls";

(async () => {
  await init("herumi");

  const secretKey = bls.PrivateKey.fromKeygen();
  const publicKey = secretKey.toPublicKey();
  const message = new Uint8Array(32);

  const signature = secretKey.sign(message);
  console.log("Is valid: ", signature.verify(publicKey, message));
})();

Browser

If you are in the browser, import from /browser to import directly the WASM version

import bls from "@chainsafe/bls/browser";

Native bindings only

If you are in NodeJS, import from /node to skip browser specific code. Also install peer dependency @chainsafe/blst which has the native bindings

yarn add @chainsafe/bls @chainsafe/blst
import bls from "@chainsafe/bls/node";

Native bindings + WASM fallback

If you want to offer a fallback in NodeJS, first try to load native bindings and then fallback to WASM. Also install peer dependency @chainsafe/blst which has the native bindings

yarn add @chainsafe/bls @chainsafe/blst
import bls from "@chainsafe/bls";

try {
  await bls.init("blst-native");
} catch (e) {
  await bls.init("herumi");
  console.warn("Using WASM");
}

The API is identical for all implementations.

Spec versioning

Version Bls spec version
2.x.x draft #7
1.x.x draft #6
0.3.x initial version

spec

test vectors

License

Apache-2.0