feat: add valid to CID

This commit is contained in:
Derrick Hammer 2023-09-08 10:01:29 -04:00
parent c24f062f80
commit 565bed46d5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 0 deletions

View File

@ -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) {