💻 Javascript Implementation of Boneh-Lynn-Shacham Signatures
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.
Go to file
Lion - dapplion 89f857a40d
Merge pull request #123 from ChainSafe/dependabot/npm_and_yarn/async-2.6.4
Bump async from 2.6.3 to 2.6.4
2022-05-04 16:38:21 +02:00
.github Update CODEOWNERS 2022-04-11 15:42:37 -06:00
benchmark Speed-up benchmarks 2021-04-05 21:02:07 +02:00
src herumi fromBytes explicit signature 2021-09-22 20:51:31 +05:30
test bls-eth-wasm package update for invalidating signature not in g2, validation on by default 2021-09-22 11:05:53 +05:30
.eslintrc.js bls-eth-wasm package update for invalidating signature not in g2, validation on by default 2021-09-22 11:05:53 +05:30
.gitignore Store spec tests data in local directory 2020-12-01 08:22:58 +00:00
.mocharc.yml Use mocharc 2021-04-04 23:00:37 +02:00
.prettierignore Fix lint issues 2020-11-25 11:50:47 +00:00
.prettierrc.yml Fix prettier config file 2020-11-04 18:04:55 +00:00
CHANGELOG.md release 6.0.3 2021-09-25 11:40:28 +05:30
LICENSE Move to packages/bls 2019-08-05 10:48:26 -05:00
README.md remove stale badge 2021-06-23 15:59:58 -05:00
blst-native.d.ts Export strategies 2020-11-25 15:03:15 +00:00
blst-native.js Export strategies 2020-11-25 15:03:15 +00:00
browser.d.ts Export strategies 2020-11-25 15:03:15 +00:00
browser.js Export strategies 2020-11-25 15:03:15 +00:00
herumi.d.ts Export strategies 2020-11-25 15:03:15 +00:00
herumi.js Export strategies 2020-11-25 15:03:15 +00:00
karma.conf.js Move web test to a different folder to not run herumi tests twice 2020-12-03 00:05:49 +00:00
node.d.ts Export strategies 2020-11-25 15:03:15 +00:00
node.js Export strategies 2020-11-25 15:03:15 +00:00
package.json Update bls-keygen to 0.4 2022-02-22 21:35:48 +02:00
register.js Add register script 2021-08-23 19:27:09 +02:00
tsconfig.build.json Include tests in ts-config 2020-11-04 18:00:50 +00:00
tsconfig.json Merge pull request #68 from ChainSafe/dapplion/tsc 2020-12-08 15:22:40 +00:00
webpack.config.js Run webpack on production mode 2020-12-03 00:06:46 +00:00
yarn.lock Bump async from 2.6.3 to 2.6.4 2022-04-29 17:18:32 +00:00

README.md

bls

codecov ETH2.0_Spec_Version 1.0.0 ES Version Node Version

Javascript library for BLS (Boneh-Lynn-Shacham) signatures and signature aggregation, tailored for use in Eth2.

Usage

yarn add @chainsafe/bls

To use native bindings you must install peer dependency @chainsafe/blst

yarn add @chainsafe/bls @chainsafe/blst

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

import {init, SecretKey, secretKeyToPublicKey, sign, verify} from "@chainsafe/bls";

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

  // class-based interface
  const secretKey = SecretKey.fromKeygen();
  const publicKey = secretKey.toPublicKey();
  const message = new Uint8Array(32);

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

  // functional interface
  const sk = secretKey.toBytes();
  const pk = secretKeyToPublicKey(sk);
  const sig = sign(sk, message);
  console.log("Is valid: ", verify(pk, message, sig));
})();

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 {init} from "@chainsafe/bls";

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

The API is identical for all implementations.

Benchmarks

Results are in ops/sec (x times slower), where x times slower = times slower than fastest implementation (blst).

Function - ops/sec blst herumi noble
verify 326.38 47.674 (x7) 17.906 (x18)
verifyAggregate (30) 453.29 51.151 (x9) 18.372 (x25)
verifyMultiple (30) 34.497 3.5233 (x10) 2.0286 (x17)
verifyMultipleSignatures (30) 26.381 3.1633 (x8) -
aggregate (pubkeys, 30) 15686 2898.9 (x5) 1875.0 (x8)
aggregate (sigs, 30) 6373.4 1033.0 (x6) 526.25 (x12)
sign 925.49 108.81 (x9) 10.246 (x90)

* blst and herumi performed 100 runs each, noble 10 runs.

Results from CI run https://github.com/ChainSafe/bls/runs/1513710175?check_suite_focus=true#step:12:13

Spec versioning

Version Bls spec hash-to-curve version
5.x.x draft #9
2.x.x draft #7
1.x.x draft #6
0.3.x initial version

spec

test vectors

License

Apache-2.0