From 517446310dea876003246b15255659bddcccb0be Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 9 Sep 2023 15:55:44 -0400 Subject: [PATCH] fix: if the registry entry hash type is not ed25519, return a new cid with the type set to raw --- src/cid.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cid.ts b/src/cid.ts index ccf1a68..9e0dcdf 100644 --- a/src/cid.ts +++ b/src/cid.ts @@ -1,6 +1,6 @@ import Multibase from "#multibase.js"; import { Multihash } from "#multihash.js"; -import { CID_TYPES, REGISTRY_TYPES } from "#constants.js"; +import { CID_HASH_TYPES, CID_TYPES, REGISTRY_TYPES } from "#constants.js"; import { decodeEndian, encodeEndian } from "#util.js"; import { concatBytes, equalBytes } from "@noble/curves/abstract/utils"; import { hexToBytes } from "@noble/hashes/utils"; @@ -29,7 +29,13 @@ export default class CID extends Multibase { bytes = bytes.slice(1); - return CID._init(bytes); + const cid = CID._init(bytes); + + if (cid.hash.functionType !== CID_HASH_TYPES.ED25519) { + return cid.copyWith({ type: CID_TYPES.RAW }); + } + + return cid; } static fromBytes(bytes: Uint8Array): CID {