import initTestnet, * as testnet from "./wasm/testnet/contractless_browser_core";
import initMainnet, * as mainnet from "./wasm/mainnet/contractless_browser_core";
import type { ContractlessNetwork } from "./types";

const initialized: Partial<Record<ContractlessNetwork, Promise<unknown>>> = {};

export async function core(network: ContractlessNetwork = "testnet") {
  const module = network === "mainnet" ? mainnet : testnet;
  initialized[network] ??= network === "mainnet" ? initMainnet() : initTestnet();
  await initialized[network];
  return module;
}
