refactor: use CID class

This commit is contained in:
Derrick Hammer 2023-09-08 13:13:18 -04:00
parent 9dcb711c35
commit a73561d369
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 3 additions and 21 deletions

View File

@ -1,10 +1,5 @@
import { internalModuleCall, modules } from "./queries.js"; import { internalModuleCall, modules } from "./queries.js";
import { SignedRegistryEntry } from "@lumeweb/libs5"; import { SignedRegistryEntry, CID } from "@lumeweb/libs5";
import {
decodeRegistryValue,
encodeCid,
decodeRegistryCid,
} from "@lumeweb/libweb";
const CORE_MODULES = { const CORE_MODULES = {
swarm: "zdiLmwHCC15afFNLYzzT2DVV7m27SrBde7oXHdSzAe95GpFZXzdpatUN6b", swarm: "zdiLmwHCC15afFNLYzzT2DVV7m27SrBde7oXHdSzAe95GpFZXzdpatUN6b",
@ -35,7 +30,7 @@ function moduleLoaded(module: string) {
} }
export async function resolveModuleRegistryEntry(module: string) { export async function resolveModuleRegistryEntry(module: string) {
const [cid] = decodeRegistryCid(module); const cid = CID.decode(module);
const pubkey = cid.hash; const pubkey = cid.hash;
@ -45,18 +40,5 @@ export async function resolveModuleRegistryEntry(module: string) {
{ pubkey }, { pubkey },
)) as SignedRegistryEntry; )) as SignedRegistryEntry;
let [decodedRegistry, err] = decodeRegistryValue(signedEntry.data); const entry = CID.fromRegistry(signedEntry.data);
if (err) {
throw new Error(err);
}
let rawEncCid;
[rawEncCid, err] = encodeCid(decodedRegistry);
if (err) {
throw new Error(err);
}
return rawEncCid;
} }