From 565bed46d511340854c443013c2be000c1e9302d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 8 Sep 2023 10:01:29 -0400 Subject: [PATCH] feat: add valid to CID --- src/cid.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cid.ts b/src/cid.ts index c91226e..0de7f91 100644 --- a/src/cid.ts +++ b/src/cid.ts @@ -52,6 +52,16 @@ export default class CID extends Multibase { return new CID(type, new Multihash(bytes), size); } + static valid(bytes: Uint8Array): boolean { + try { + CID._init(bytes); + } catch { + return false; + } + + return true; + } + private static _init(bytes: Uint8Array): CID { const type = bytes[0]; if (type === CID_TYPES.BRIDGE) {