From 2c56658a6c06c51e6f079232c35cce05a6ca72c3 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 3 Sep 2023 21:29:51 -0400 Subject: [PATCH] fix: if has is a CID, override arguments with the CID properties unless we have an argument set already --- src/cid.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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) {