*Make bls export an async wrapper to prevent top-level await

This commit is contained in:
Derrick Hammer 2023-04-08 22:31:59 -04:00
parent a74045db4a
commit 1028fc1bb0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 6 deletions

View File

@ -4,11 +4,16 @@ import {getImplementation} from "./getImplementation.js";
// Thanks https://github.com/iliakan/detect-node/blob/master/index.esm.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]"; const isNode = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
let bls: IBls; export const bls = async (): Promise<IBls> => {
try { let bls: IBls;
bls = await getImplementation(isNode ? "blst-native" : "herumi");
} catch (e) { try {
bls = await getImplementation("herumi"); bls = await getImplementation(isNode ? "blst-native" : "herumi");
} } catch (e) {
bls = await getImplementation("herumi");
}
return bls;
};
export default bls; export default bls;