Skip to content

Commit c4884f2

Browse files
authored
Added New VeficationMethod ED25519VerificationKey2020 (#114)
1 parent 590f0a5 commit c4884f2

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

did/document.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func NewVerificationMethod(id DIDURL, keyType ssi.KeyType, controller DID, key c
340340
}
341341
vm.PublicKeyJwk = jwkAsMap
342342
}
343-
if keyType == ssi.ED25519VerificationKey2018 {
343+
if keyType == ssi.ED25519VerificationKey2018 || keyType == ssi.ED25519VerificationKey2020 {
344344
ed25519Key, ok := key.(ed25519.PublicKey)
345345
if !ok {
346346
return nil, errors.New("wrong key type")
@@ -371,7 +371,7 @@ func (v VerificationMethod) JWK() (jwk.Key, error) {
371371
func (v VerificationMethod) PublicKey() (crypto.PublicKey, error) {
372372
var pubKey crypto.PublicKey
373373
switch v.Type {
374-
case ssi.ED25519VerificationKey2018:
374+
case ssi.ED25519VerificationKey2018, ssi.ED25519VerificationKey2020:
375375
var keyBytes []byte
376376
var err error
377377
if v.PublicKeyMultibase != "" {

did/document_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ func Test_Document(t *testing.T) {
139139
require.NotNil(t, publicKey)
140140
})
141141

142+
t.Run("ED25519VerificationKey2020", func(t *testing.T) {
143+
keyID := DIDURL{DID: actual.ID}
144+
keyID.Fragment = "added-assertion-method-1"
145+
146+
pubKey, _, _ := ed25519.GenerateKey(rand.Reader)
147+
vm, err := NewVerificationMethod(keyID, ssi.ED25519VerificationKey2020, actual.ID, pubKey)
148+
require.NoError(t, err)
149+
150+
publicKey, err := vm.PublicKey()
151+
require.NoError(t, err)
152+
require.NotNil(t, publicKey)
153+
})
154+
142155
t.Run("ECDSASECP256K1VerificationKey2019", func(t *testing.T) {
143156
t.Run("generated key", func(t *testing.T) {
144157
keyID := DIDURL{DID: actual.ID}

spec-registries.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ type KeyType string
77
const JsonWebKey2020 = KeyType("JsonWebKey2020")
88

99
// ED25519VerificationKey2018 is the Ed25519VerificationKey2018 verification key type as specified here:
10-
// https://w3c-ccg.github.io/lds-ed25519-2018/
10+
// https://w3c-ccg.github.io/
1111
const ED25519VerificationKey2018 = KeyType("Ed25519VerificationKey2018")
1212

13+
// ED25519VerificationKey2020 is the Ed25519VerificationKey2020 verification key type as specified here:
14+
// https://www.w3.org/TR/vc-di-eddsa/#ed25519verificationkey2020
15+
const ED25519VerificationKey2020 = KeyType("Ed25519VerificationKey2020")
16+
1317
// ECDSASECP256K1VerificationKey2019 is the EcdsaSecp256k1VerificationKey2019 verification key type as specified here:
1418
// https://w3c-ccg.github.io/lds-ecdsa-secp256k1-2019/
1519
const ECDSASECP256K1VerificationKey2019 = KeyType("EcdsaSecp256k1VerificationKey2019")

0 commit comments

Comments
 (0)