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";
|
2023-09-04 08:09:46 +00:00
|
|
|
import {
|
|
|
|
decodeRegistryValue,
|
|
|
|
encodeCid,
|
|
|
|
decodeRegistryCid,
|
|
|
|
} from "@lumeweb/libweb";
|
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-04 08:09:46 +00:00
|
|
|
const [cid] = decodeRegistryCid(module);
|
2023-09-02 18:46:06 +00:00
|
|
|
|
|
|
|
const pubkey = cid.hash;
|
|
|
|
|
2023-09-01 22:59:06 +00:00
|
|
|
const signedEntry = (await internalModuleCall(
|
|
|
|
CORE_MODULES.s5,
|
|
|
|
"getRegistryEntry",
|
|
|
|
{ pubkey },
|
|
|
|
)) as SignedRegistryEntry;
|
|
|
|
|
2023-09-04 08:09:46 +00:00
|
|
|
let [decodedRegistry, err] = decodeRegistryValue(signedEntry.data);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
throw new Error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
let rawEncCid;
|
|
|
|
[rawEncCid, err] = encodeCid(decodedRegistry);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
throw new Error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rawEncCid;
|
2023-09-01 22:59:06 +00:00
|
|
|
}
|