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

76 lines
1.9 KiB
Markdown
Raw Normal View History

2020-04-17 20:23:30 +00:00
# bls
2019-08-05 15:48:26 +00:00
2019-08-05 18:11:56 +00:00
[![Build Status](https://travis-ci.org/ChainSafe/lodestar.svg?branch=master)](https://travis-ci.org/ChainSafe/lodestar)
[![codecov](https://codecov.io/gh/ChainSafe/lodestar/branch/master/graph/badge.svg)](https://codecov.io/gh/ChainSafe/lodestar)
2020-05-21 17:10:46 +00:00
![ETH2.0_Spec_Version 0.12.0](https://img.shields.io/badge/ETH2.0_Spec_Version-0.12.0-2e86c1.svg)
2020-07-03 23:05:24 +00:00
![ES Version](https://img.shields.io/badge/ES-2017-yellow)
![Node Version](https://img.shields.io/badge/node-12.x-green)
2019-08-05 15:48:26 +00:00
2020-11-25 15:03:11 +00:00
Javascript library for BLS (Boneh-Lynn-Shacham) signatures and signature aggregation.
## Usage
```ts
2020-11-25 16:09:44 +00:00
import bls, {init} from "@chainsafe/bls";
2020-11-25 15:03:11 +00:00
2020-11-25 16:09:44 +00:00
(async () => {
await init("herumi");
2020-11-25 15:03:11 +00:00
2020-11-25 16:09:44 +00:00
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));
})();
2020-11-25 15:03:11 +00:00
```
### Browser
If you are in the browser, import from `/browser`
```ts
import bls from "@chainsafe/bls/browser";
```
### Native bindings only
If you are in NodeJS, import from `/node` to skip browser specific code
```ts
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
```ts
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
2019-08-05 15:48:26 +00:00
2020-11-04 17:40:36 +00:00
| Version | Bls spec version |
| ------- | :--------------: |
| 2.x.x | draft #7 |
2020-11-25 15:03:11 +00:00
| 1.x.x | draft #6 |
| 0.3.x | initial version |
2020-05-21 17:10:46 +00:00
2020-11-04 17:40:36 +00:00
> [spec](https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#bls-signatures)
2019-08-05 15:48:26 +00:00
2020-11-04 17:40:36 +00:00
> [test vectors](https://github.com/ethereum/eth2.0-spec-tests/tree/master/tests/bls)
2020-02-25 08:28:47 +00:00
2020-04-17 20:15:17 +00:00
## License
Apache-2.0