From d58fc82e08fb46ea3329a06e52565dbf8d9d12f9 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 8 Apr 2023 22:20:32 -0400 Subject: [PATCH] *Make bls export an async wrapper to prevent top-level await --- src/getImplementation.ts | 2 +- src/herumi/index.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/getImplementation.ts b/src/getImplementation.ts index 2fa4703..e6a46e6 100644 --- a/src/getImplementation.ts +++ b/src/getImplementation.ts @@ -6,7 +6,7 @@ const isNode = Object.prototype.toString.call(typeof process !== "undefined" ? p export async function getImplementation(impl: Implementation = "herumi"): Promise { switch (impl) { case "herumi": { - return (await import("./herumi/index.js")).bls; + return await (await import("./herumi/index.js")).bls(); } case "blst-native": diff --git a/src/herumi/index.ts b/src/herumi/index.ts index dc79acf..5dc82b7 100644 --- a/src/herumi/index.ts +++ b/src/herumi/index.ts @@ -5,19 +5,19 @@ import {init, destroy} from "./context.js"; import {IBls} from "../types.js"; import {functionalInterfaceFactory} from "../functional.js"; -await init(); - export * from "../constants.js"; export {SecretKey, PublicKey, Signature, init, destroy}; -export const bls: IBls = { - implementation: "herumi", - SecretKey, - PublicKey, - Signature, +export const bls = async (): Promise => { + await init(); + return { + implementation: "herumi", + SecretKey, + PublicKey, + Signature, - ...functionalInterfaceFactory({SecretKey, PublicKey, Signature}), + ...functionalInterfaceFactory({SecretKey, PublicKey, Signature}), + }; }; - export default bls;