feat: add fromSignedRegistryEntry

This commit is contained in:
Derrick Hammer 2023-12-11 22:58:38 -05:00
parent 067dd9cd22
commit 8e786ec164
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 5 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import { CID_HASH_TYPES, CID_TYPES, REGISTRY_TYPES } from "#constants.js";
import { decodeEndian, encodeEndian } from "#util.js"; import { decodeEndian, encodeEndian } from "#util.js";
import { concatBytes, equalBytes } from "@noble/curves/abstract/utils"; import { concatBytes, equalBytes } from "@noble/curves/abstract/utils";
import { hexToBytes } from "@noble/hashes/utils"; import { hexToBytes } from "@noble/hashes/utils";
import { SignedRegistryEntry } from "#types.js";
export default class CID extends Multibase { export default class CID extends Multibase {
type: number; type: number;
@ -42,6 +43,10 @@ export default class CID extends Multibase {
return CID._init(bytes); return CID._init(bytes);
} }
static fromSignedRegistryEntry(sre: SignedRegistryEntry): CID {
return CID.fromRegistryPublicKey(sre.pk);
}
static fromRegistryPublicKey(pubkey: string | Uint8Array): CID { static fromRegistryPublicKey(pubkey: string | Uint8Array): CID {
return CID.fromHash(pubkey, 0, CID_TYPES.RESOLVER); return CID.fromHash(pubkey, 0, CID_TYPES.RESOLVER);
} }