diff --git a/did/document.go b/did/document.go index 3982de1..f78dd3d 100644 --- a/did/document.go +++ b/did/document.go @@ -340,7 +340,7 @@ func NewVerificationMethod(id DIDURL, keyType ssi.KeyType, controller DID, key c } vm.PublicKeyJwk = jwkAsMap } - if keyType == ssi.ED25519VerificationKey2018 { + if keyType == ssi.ED25519VerificationKey2018 || keyType == ssi.ED25519VerificationKey2020 { ed25519Key, ok := key.(ed25519.PublicKey) if !ok { return nil, errors.New("wrong key type") @@ -371,7 +371,7 @@ func (v VerificationMethod) JWK() (jwk.Key, error) { func (v VerificationMethod) PublicKey() (crypto.PublicKey, error) { var pubKey crypto.PublicKey switch v.Type { - case ssi.ED25519VerificationKey2018: + case ssi.ED25519VerificationKey2018, ssi.ED25519VerificationKey2020: var keyBytes []byte var err error if v.PublicKeyMultibase != "" { diff --git a/did/document_test.go b/did/document_test.go index 50cc7be..2bd1493 100644 --- a/did/document_test.go +++ b/did/document_test.go @@ -139,6 +139,19 @@ func Test_Document(t *testing.T) { require.NotNil(t, publicKey) }) + t.Run("ED25519VerificationKey2020", func(t *testing.T) { + keyID := DIDURL{DID: actual.ID} + keyID.Fragment = "added-assertion-method-1" + + pubKey, _, _ := ed25519.GenerateKey(rand.Reader) + vm, err := NewVerificationMethod(keyID, ssi.ED25519VerificationKey2020, actual.ID, pubKey) + require.NoError(t, err) + + publicKey, err := vm.PublicKey() + require.NoError(t, err) + require.NotNil(t, publicKey) + }) + t.Run("ECDSASECP256K1VerificationKey2019", func(t *testing.T) { t.Run("generated key", func(t *testing.T) { keyID := DIDURL{DID: actual.ID} diff --git a/spec-registries.go b/spec-registries.go index ad61d3f..546b102 100644 --- a/spec-registries.go +++ b/spec-registries.go @@ -7,9 +7,13 @@ type KeyType string const JsonWebKey2020 = KeyType("JsonWebKey2020") // ED25519VerificationKey2018 is the Ed25519VerificationKey2018 verification key type as specified here: -// https://w3c-ccg.github.io/lds-ed25519-2018/ +// https://w3c-ccg.github.io/ const ED25519VerificationKey2018 = KeyType("Ed25519VerificationKey2018") +// ED25519VerificationKey2020 is the Ed25519VerificationKey2020 verification key type as specified here: +// https://www.w3.org/TR/vc-di-eddsa/#ed25519verificationkey2020 +const ED25519VerificationKey2020 = KeyType("Ed25519VerificationKey2020") + // ECDSASECP256K1VerificationKey2019 is the EcdsaSecp256k1VerificationKey2019 verification key type as specified here: // https://w3c-ccg.github.io/lds-ecdsa-secp256k1-2019/ const ECDSASECP256K1VerificationKey2019 = KeyType("EcdsaSecp256k1VerificationKey2019")