Allow switchable bls to detect the right implementation

Open
#137 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
api

Research direction

Start at the @chainsafe/bls/switchable entry point and trace the existing init logic that detects the implementation. Define how an automatic default should select the implementation without top-level await, then verify that the exported BLS object is usable after initialization across the affected environments.

Written by the indexing model from the issue text.

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.

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

Dominant language
TypeScript
Stars
106
Forks
24
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ChainSafe/bls

All issues in ChainSafe/bls

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.