fix: if we have a Uint8Array but invalid CID_HASH_TYPES, return error

This commit is contained in:
Derrick Hammer 2023-09-03 20:36:13 -04:00
parent 043f1657ab
commit 07a451ce5e
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 6 additions and 0 deletions

View File

@ -74,6 +74,12 @@ export function encodeRegistryCid(
hashType = CID_HASH_TYPES.ED25519,
raw: boolean = false,
): ErrTuple<string | Uint8Array> {
if (hash instanceof Uint8Array) {
if (!Object.values(CID_HASH_TYPES).includes(hash[0])) {
return ["", "invalid hash type"];
}
}
return encodeCid(hash, size, type, hashType, raw);
}