fix: if has is a CID, override arguments with the CID properties unless we have an argument set already

This commit is contained in:
Derrick Hammer 2023-09-03 21:29:51 -04:00
parent f74ee39b9a
commit 2c56658a6c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 1 deletions

View File

@ -22,13 +22,26 @@ export function encodeCid(
hashType?: number, hashType?: number,
raw?: boolean, raw?: boolean,
): ErrTuple<string | Uint8Array>; ): ErrTuple<string | Uint8Array>;
export function encodeCid(
hash: CID,
size?: bigint,
type?: number,
hashType?: number,
raw?: boolean,
): ErrTuple<string | Uint8Array>;
export function encodeCid( export function encodeCid(
hash: any, hash: any,
size: bigint, size?: bigint,
type?: number, type?: number,
hashType?: number, hashType?: number,
raw: boolean = false, raw: boolean = false,
): ErrTuple<string | Uint8Array> { ): ErrTuple<string | Uint8Array> {
if (typeof hash !== "string" && !(hash instanceof Uint8Array)) {
size = hash.size;
type = type ?? hash.type;
hashType = hashType ?? hash.type;
hash = hash.hash;
}
try { try {
return [encodeCidPortal(hash, size, type, hashType, raw), null]; return [encodeCidPortal(hash, size, type, hashType, raw), null];
} catch (e) { } catch (e) {