Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve implementation selection strategy #157

Closed
jeluard opened this issue Mar 6, 2024 · 0 comments
Closed

Improve implementation selection strategy #157

jeluard opened this issue Mar 6, 2024 · 0 comments

Comments

@jeluard
Copy link
Contributor

jeluard commented Mar 6, 2024

Usage of bls is problematic under some alternative JS environment for the following reasons:

  • usage of top-level-wait in a lib
  • automatic detection of the proper implementation (i.e. use native when node env is detected)

Ideally there would be a way to allow bls users to select the implementation used at runtime. Users should not be able to specify their chosen implementation after the initialization has been done (thus ignoring their choice).

First idea

Single global implementation

BLS_IMPLEMENTATION=herumi node ...
import bls, {init} from "@chainsafe/bls";

// Make sure the initialization has been done
// Can be called several times, initialization is done only once
await init();

const secretKey = bls.SecretKey.fromKeygen();
const message = new Uint8Array(32);
const signature = secretKey.sign(message);

No automatic init would be done, users explicitly have to do it. Essentially it's a modified version (with env variable) of the existing switchable singleton. This would be the only way to use the lib.

Second idea

Explicitly pass around a bls object tied to an implementation.

const bls = await BLS.init("herumi");
const secretKey = bls.SecretKey.fromKeygen();
const message = new Uint8Array(32);
const signature = secretKey.sign(message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant