From 867544e1c91171656af61bd54c8ff348c7f64165 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 4 Sep 2023 04:09:46 -0400 Subject: [PATCH] refactor: rewrite resolveModuleRegistryEntry to use decodeRegistryCid, decodeRegistryValue, and encodeCid --- src/coreModules.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/coreModules.ts b/src/coreModules.ts index 1eb33f2..f3cd586 100644 --- a/src/coreModules.ts +++ b/src/coreModules.ts @@ -1,7 +1,10 @@ import { internalModuleCall, modules } from "./queries.js"; import { SignedRegistryEntry } from "@lumeweb/libs5"; -import { base58btc } from "multiformats/bases/base58"; -import { decodeCid } from "@lumeweb/libweb"; +import { + decodeRegistryValue, + encodeCid, + decodeRegistryCid, +} from "@lumeweb/libweb"; const CORE_MODULES = { swarm: "zdiLmwHCC15afFNLYzzT2DVV7m27SrBde7oXHdSzAe95GpFZXzdpatUN6b", @@ -32,7 +35,7 @@ function moduleLoaded(module: string) { } export async function resolveModuleRegistryEntry(module: string) { - const [cid] = decodeCid(module); + const [cid] = decodeRegistryCid(module); const pubkey = cid.hash; @@ -42,5 +45,18 @@ export async function resolveModuleRegistryEntry(module: string) { { pubkey }, )) as SignedRegistryEntry; - return base58btc.encode(signedEntry.data); + 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; }