This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
2022-04-14 17:16:06 +00:00
|
|
|
import type {IBls, Implementation} from "./types.js";
|
2022-04-13 16:59:25 +00:00
|
|
|
|
|
|
|
// 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]";
|
|
|
|
|
|
|
|
export async function getImplementation(impl: Implementation = "herumi"): Promise<IBls> {
|
|
|
|
switch (impl) {
|
|
|
|
case "herumi": {
|
2022-04-13 19:36:07 +00:00
|
|
|
return (await import("./herumi/index.js")).bls;
|
2022-04-13 16:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "blst-native":
|
|
|
|
// Lazy import native bindings to prevent automatically importing binding.node files
|
|
|
|
if (!isNode) {
|
|
|
|
throw Error("blst-native is only supported in NodeJS");
|
|
|
|
}
|
|
|
|
return (await import("./blst-native/index.js")).bls;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new Error(`Unsupported implementation - ${impl}`);
|
|
|
|
}
|
|
|
|
}
|