2023-09-01 23:04:07 +00:00
|
|
|
import { internalModuleCall, modules } from "./queries.js";
|
2023-09-01 22:59:06 +00:00
|
|
|
import { SignedRegistryEntry } from "@lumeweb/libs5";
|
|
|
|
import { base58btc } from "multiformats/bases/base58";
|
2023-09-02 18:46:06 +00:00
|
|
|
import { decodeCid } from "@lumeweb/libweb";
|
2023-09-01 22:59:06 +00:00
|
|
|
|
|
|
|
const CORE_MODULES = {
|
2023-09-02 13:49:59 +00:00
|
|
|
swarm: "z3o47ar8NBrnaEneBVzZD7QuMRMXjDtQDCpt4xP6mhsdw1cjnJ8mQKfNKGv3",
|
2023-09-02 13:42:09 +00:00
|
|
|
peerDiscoveryRegistry:
|
|
|
|
"z3o47aaLSspwrXzmu5mjuHPwaq3gRbyYQ3jL9RM1ammuHGB7uxSFBK2dRjqR",
|
|
|
|
ircPeerDiscovery:
|
|
|
|
"z3o47admQjBj2QUrwHhvTB3nV1cBwQ5ZaKF7P5WELXeRyzzvBZr33QMJWTLs",
|
|
|
|
s5: "z3o47hB2zLuvBMFaWa55SmbFQe3u97dWUG4fssXXTEcT4ZvnPkPaRF14b1EF",
|
2023-09-01 22:59:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export async function networkReady() {
|
|
|
|
for (const module of [
|
|
|
|
CORE_MODULES.peerDiscoveryRegistry,
|
|
|
|
CORE_MODULES.ircPeerDiscovery,
|
|
|
|
CORE_MODULES.swarm,
|
|
|
|
]) {
|
|
|
|
if (!moduleLoaded(module)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-09-02 17:07:43 +00:00
|
|
|
const resolvers = await internalModuleCall(CORE_MODULES.swarm, "getRelays");
|
2023-09-01 22:59:06 +00:00
|
|
|
|
|
|
|
return resolvers.length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function moduleLoaded(module: string) {
|
|
|
|
return module in modules;
|
|
|
|
}
|
|
|
|
|
2023-09-02 18:46:06 +00:00
|
|
|
export async function resolveModuleRegistryEntry(module: string) {
|
|
|
|
const [cid] = decodeCid(module);
|
|
|
|
|
|
|
|
const pubkey = cid.hash;
|
|
|
|
|
2023-09-01 22:59:06 +00:00
|
|
|
const signedEntry = (await internalModuleCall(
|
|
|
|
CORE_MODULES.s5,
|
|
|
|
"getRegistryEntry",
|
|
|
|
{ pubkey },
|
|
|
|
)) as SignedRegistryEntry;
|
|
|
|
|
|
|
|
return base58btc.encode(signedEntry.data);
|
|
|
|
}
|