fix: update encodeCid overloads and return types

This commit is contained in:
Derrick Hammer 2023-09-03 16:13:03 -04:00
parent c1913e7ba5
commit 7dc8067e95
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 18 additions and 5 deletions

View File

@ -6,18 +6,31 @@ import {
import { addContextToErr } from "#err.js";
import type { CID } from "@lumeweb/libportal";
export function encodeCid(hash: Uint8Array, size: bigint): ErrTuple<string>;
export function encodeCid(hash: string, size: bigint): ErrTuple<string>;
export function encodeCid(
hash: Uint8Array,
size: bigint,
type?: number,
hashType?: number,
raw?: boolean,
): ErrTuple<string>;
export function encodeCid(
hash: string,
size: bigint,
type?: number,
hashType?: number,
raw?: boolean,
): ErrTuple<string>;
export function encodeCid(
hash: any,
size: bigint,
type?: number,
hashType?: number,
): ErrTuple<CID> {
raw: boolean = false,
): ErrTuple<string> {
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")];
}
}