From 7dc8067e958bb62efe856cdb234ac0010b6d2896 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 3 Sep 2023 16:13:03 -0400 Subject: [PATCH] fix: update encodeCid overloads and return types --- src/cid.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/cid.ts b/src/cid.ts index e711f43..2fd80c7 100644 --- a/src/cid.ts +++ b/src/cid.ts @@ -6,18 +6,31 @@ import { import { addContextToErr } from "#err.js"; import type { CID } from "@lumeweb/libportal"; -export function encodeCid(hash: Uint8Array, size: bigint): ErrTuple; -export function encodeCid(hash: string, size: bigint): ErrTuple; +export function encodeCid( + hash: Uint8Array, + size: bigint, + type?: number, + hashType?: number, + raw?: boolean, +): ErrTuple; +export function encodeCid( + hash: string, + size: bigint, + type?: number, + hashType?: number, + raw?: boolean, +): ErrTuple; export function encodeCid( hash: any, size: bigint, type?: number, hashType?: number, -): ErrTuple { + raw: boolean = false, +): ErrTuple { try { - return [encodeCidPortal(hash, size, type, hashType), null]; + return [encodeCidPortal(hash, size, type, hashType, raw), null]; } catch (e) { - return [null, addContextToErr(e as Error, "failed to encode cid")]; + return ["", addContextToErr(e as Error, "failed to encode cid")]; } }