feat: add fromRegistry to CID

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

View File

@ -22,6 +22,16 @@ export default class CID extends Multibase {
return CID._init(decodedBytes);
}
static fromRegistry(bytes: Uint8Array): CID {
if (!Object.values(REGISTRY_TYPES).includes(bytes[0])) {
throw new Error(`invalid registry type ${bytes[0]}`);
}
bytes = bytes.slice(1);
return CID._init(bytes);
}
static fromBytes(bytes: Uint8Array): CID {
return CID._init(bytes);
}