From 1028fc1bb06a5c12ede75b546c25aa3a59a9a9a2 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 8 Apr 2023 22:31:59 -0400 Subject: [PATCH] *Make bls export an async wrapper to prevent top-level await --- src/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 145cb10..e701395 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,11 +4,16 @@ import {getImplementation} from "./getImplementation.js"; // Thanks https://github.com/iliakan/detect-node/blob/master/index.esm.js const isNode = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]"; -let bls: IBls; -try { - bls = await getImplementation(isNode ? "blst-native" : "herumi"); -} catch (e) { - bls = await getImplementation("herumi"); -} +export const bls = async (): Promise => { + let bls: IBls; + + try { + bls = await getImplementation(isNode ? "blst-native" : "herumi"); + } catch (e) { + bls = await getImplementation("herumi"); + } + + return bls; +}; export default bls;