diff --git a/src/cid.ts b/src/cid.ts index e8e05f2..0eb9d1e 100644 --- a/src/cid.ts +++ b/src/cid.ts @@ -22,13 +22,26 @@ export function encodeCid( hashType?: number, raw?: boolean, ): ErrTuple; +export function encodeCid( + hash: CID, + size?: bigint, + type?: number, + hashType?: number, + raw?: boolean, +): ErrTuple; export function encodeCid( hash: any, - size: bigint, + size?: bigint, type?: number, hashType?: number, raw: boolean = false, ): ErrTuple { + if (typeof hash !== "string" && !(hash instanceof Uint8Array)) { + size = hash.size; + type = type ?? hash.type; + hashType = hashType ?? hash.type; + hash = hash.hash; + } try { return [encodeCidPortal(hash, size, type, hashType, raw), null]; } catch (e) {