refactor: update encodeCid and decodeCid to use ErrTuple with a CID type

This commit is contained in:
Derrick Hammer 2023-09-02 07:49:24 -04:00
parent 2a4a246799
commit 22ccc91566
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 5 additions and 4 deletions

View File

@ -4,15 +4,16 @@ import {
encodeCid as encodeCidPortal,
} from "@lumeweb/libportal";
import { addContextToErr } from "#err.js";
import type { CID } from "@lumeweb/libportal";
export function encodeCid(hash: Uint8Array, size: bigint): any;
export function encodeCid(hash: string, size: bigint): any;
export function encodeCid(hash: Uint8Array, size: bigint): ErrTuple<string>;
export function encodeCid(hash: string, size: bigint): ErrTuple<string>;
export function encodeCid(
hash: any,
size: bigint,
type?: number,
hashType?: number,
): ErrTuple {
): ErrTuple<CID> {
try {
return [encodeCidPortal(hash, size, type, hashType), null];
} catch (e) {
@ -20,7 +21,7 @@ export function encodeCid(
}
}
export function decodeCid(cid: string): ErrTuple {
export function decodeCid(cid: string): ErrTuple<CID> {
try {
return [decodeCidPortal(cid), null];
} catch (e) {