kernel/src/coreModules.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-09-01 23:04:07 +00:00
import { internalModuleCall, modules } from "./queries.js";
import { CID, SignedRegistryEntry } from "@lumeweb/libs5";
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",
};
export async function networkReady() {
for (const module of [
CORE_MODULES.peerDiscoveryRegistry,
CORE_MODULES.ircPeerDiscovery,
CORE_MODULES.swarm,
]) {
if (!moduleLoaded(module)) {
return false;
}
}
const resolvers = await internalModuleCall(CORE_MODULES.swarm, "getRelays");
return resolvers.length > 0;
}
function moduleLoaded(module: string) {
return module in modules;
}
export async function resolveModuleRegistryEntry(module: string) {
2023-09-08 17:13:18 +00:00
const cid = CID.decode(module);
const pubkey = cid.hash.fullBytes;
const signedEntry = (await internalModuleCall(
CORE_MODULES.s5,
"getRegistryEntry",
{ pubkey },
)) as SignedRegistryEntry;
return CID.fromRegistry(signedEntry.data).toString();
}