feat(did): add accessor to report whether this DID is a did:key

This commit is contained in:
Steve Moyer
2024-09-16 13:54:18 -04:00
parent 64936fd061
commit 53cb82a2b4

View File

@@ -50,6 +50,10 @@ func (d DID) DID() DID {
return d return d
} }
func (d DID) Key() bool {
return d.key
}
func (d DID) PubKey() (crypto.PubKey, error) { func (d DID) PubKey() (crypto.PubKey, error) {
if !d.key { if !d.key {
return nil, fmt.Errorf("unsupported did type: %s", d.String()) return nil, fmt.Errorf("unsupported did type: %s", d.String())
@@ -110,5 +114,5 @@ func Parse(str string) (DID, error) {
varint.PutUvarint(buf, DIDCore) varint.PutUvarint(buf, DIDCore)
suffix, _ := strings.CutPrefix(str, Prefix) suffix, _ := strings.CutPrefix(str, Prefix)
buf = append(buf, suffix...) buf = append(buf, suffix...)
return DID{str: string(buf)}, nil return DID{str: string(buf), code: DIDCore}, nil
} }