2023-09-01 23:04:07 +00:00
|
|
|
import { internalModuleCall, modules } from "./queries.js";
|
2023-09-11 09:44:19 +00:00
|
|
|
import { CID, SignedRegistryEntry } from "@lumeweb/libs5";
|
2023-09-01 22:59:06 +00:00
|
|
|
|
|
|
|
const CORE_MODULES = {
|
2023-09-03 05:01:11 +00:00
|
|
|
swarm: "zdiLmwHCC15afFNLYzzT2DVV7m27SrBde7oXHdSzAe95GpFZXzdpatUN6b",
|
2023-09-02 13:42:09 +00:00
|
|
|
peerDiscoveryRegistry:
|
2023-09-03 05:01:11 +00:00
|
|
|
"zdiLW9MtAAMssP5vLBgd1FitouiVXzNUYZszFYG44uVKqCPDqUQox9aq1y",
|
2023-09-02 13:42:09 +00:00
|
|
|
ircPeerDiscovery:
|
2023-09-03 05:01:11 +00:00
|
|
|
"zdiLZaKjWwXkMU88GNEWf6d5NREHe1Yk4M7eQm1owSC4ezeqFGGuGpfYXR",
|
|
|
|
s5: "zdiT6quMF8gh8BhQdXE7CZYhp8S1BxSgsucSS48WuTGdars1noejvak6Qo",
|
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) {
|
2023-09-08 17:13:18 +00:00
|
|
|
const cid = CID.decode(module);
|
2023-09-02 18:46:06 +00:00
|
|
|
|
2023-09-11 09:44:19 +00:00
|
|
|
const pubkey = cid.hash.fullBytes;
|
2023-09-02 18:46:06 +00:00
|
|
|
|
2023-09-01 22:59:06 +00:00
|
|
|
const signedEntry = (await internalModuleCall(
|
|
|
|
CORE_MODULES.s5,
|
|
|
|
"getRegistryEntry",
|
|
|
|
{ pubkey },
|
|
|
|
)) as SignedRegistryEntry;
|
|
|
|
|
2023-09-11 09:44:19 +00:00
|
|
|
return CID.fromRegistry(signedEntry.data).toString();
|
2023-09-01 22:59:06 +00:00
|
|
|
}
|