ChainSafe / ChainSafe/bls

Allow switchable bls to detect the right implementation

Open
#137 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
106
Forks
24
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
Found out during the testing that on some environment `top-level-await` are not properly supported. Which are used to initialize the BLS object if the package is imported directly.

**Describe the solution you'd like**

The best approach to fit in all cases is to import the `BLS` from the `switchable`. And when is appropriate use the `init` to initialize the object.

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

That `init` does accept one parameter and it's redundant to identify and pass the parameter for the right implementation. This logic of detecting is already part of the package so we can reuse here. We can provide third option here `auto` which could be the default value as well. So user don't need to write custom logic and `switchable` will detect the right implementation.

**Describe alternatives you've considered**
The alternative safe approach is to use the `await import`. But that can't be done with correct user experience as code outside that block will not access to the `bls` object.

**Additional context**
https://github.com/ChainSafe/lodestar/issues/2723

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.