npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chainsafe/bls

v8.1.0

Published

Implementation of bls signature verification for ethereum 2.0

Downloads

5,729

Readme

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

By default, native bindings will be used if in NodeJS and they are installed. A WASM implementation ("herumi") is used as a fallback in case any error occurs.

The blst-native implementation offers a multi-threaded approach to verification and utilizes the libuv worker pool to verification. It is a more performant options synchronously and FAR better when utilized asynchronously. All verification functions provide sync and async versions. Both the blst-native and herumi implementations offer verification functions with async prefixes as free functions and also on their respective classes. This was done to preserve the isomorphic architecture of this library. In reality however, only the blst-native bindings have the ability to implement a promise based approach. In the herumi version the async version just proxies to the sync version under the hood.

import bls from "@chainsafe/bls";

(async () => {
    // class-based interface
    const secretKey = bls.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 = bls.secretKeyToPublicKey(sk);
    const sig = bls.sign(sk, message);
    console.log("Is valid: ", bls.verify(pk, message, sig));
})();

Browser

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

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

Native bindings only

If you are in NodeJS, import from /blst-native to explicitly import the native bindings. Also install peer dependency @chainsafe/blst which has the native bindings

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

Get implementation at runtime

If you need to get a bls implementation at runtime, import from /getImplementation.

import {getImplementation} from "@chainsafe/bls/getImplementation";

const bls = await getImplementation("herumi");

Switchable singleton

If you need a singleton that is switchable at runtime (the default behavior in <=v6), import from /switchable.

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

// here `bls` is uninitialized
await init("herumi");
// here `bls` is initialized
// now other modules can `import bls from "@chainsafe/bls/switchable"` and it will be initialized

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