From 22ccc915667c3c5d495c3c1ee6d8c745c0a40098 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 2 Sep 2023 07:49:24 -0400 Subject: [PATCH] refactor: update encodeCid and decodeCid to use ErrTuple with a CID type --- src/cid.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cid.ts b/src/cid.ts index 07d1374..e711f43 100644 --- a/src/cid.ts +++ b/src/cid.ts @@ -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; +export function encodeCid(hash: string, size: bigint): ErrTuple; export function encodeCid( hash: any, size: bigint, type?: number, hashType?: number, -): ErrTuple { +): ErrTuple { 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 { try { return [decodeCidPortal(cid), null]; } catch (e) {