From ab1ad68fcb7b2d08842a04ed4c411970f93cfbb4 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 8 Sep 2023 13:22:19 -0400 Subject: [PATCH] fix: need to use CID.decode --- src/download.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/download.ts b/src/download.ts index 6a0fb07..be32e1d 100644 --- a/src/download.ts +++ b/src/download.ts @@ -1,5 +1,5 @@ import { getActivePortals } from "#portal.js"; -import { decodeCid, getVerifiableStream } from "@lumeweb/libportal"; +import { getVerifiableStream } from "@lumeweb/libportal"; import { readableStreamToUint8Array, uint8ArrayToReadableStream, @@ -7,6 +7,7 @@ import { import { equalBytes } from "@noble/curves/abstract/utils"; import { blake3 } from "@noble/hashes/blake3"; import { NO_PORTALS_ERROR } from "#types.js"; +import { CID } from "@lumeweb/libs5"; export async function downloadObject(cid: string): Promise { const activePortals = getActivePortals(); @@ -33,7 +34,11 @@ export async function downloadObject(cid: string): Promise { continue; } - return await getVerifiableStream(decodeCid(cid).hash, proof, stream); + return await getVerifiableStream( + CID.decode(cid).hash.hashBytes, + proof, + stream, + ); } throw NO_PORTALS_ERROR; @@ -65,10 +70,9 @@ export async function downloadSmallObject( continue; } - const CID = decodeCid(cid); const data = await readableStreamToUint8Array(stream); - if (!equalBytes(blake3(data), CID.hash)) { + if (!equalBytes(blake3(data), CID.decode(cid).hash.hashBytes)) { throw new Error("cid verification failed"); }