From c26bcc3861958c6eb83d1575a4b684c621128460 Mon Sep 17 00:00:00 2001 From: Rein Krul Date: Wed, 2 Aug 2023 17:00:21 +0200 Subject: [PATCH 1/2] Enable did:jwk resolving --- vdr/didjwk/resolver.go | 3 +++ vdr/vdr.go | 2 ++ 2 files changed, 5 insertions(+) diff --git a/vdr/didjwk/resolver.go b/vdr/didjwk/resolver.go index 673220a50d..d4de1e8c8f 100644 --- a/vdr/didjwk/resolver.go +++ b/vdr/didjwk/resolver.go @@ -31,6 +31,9 @@ import ( "github.com/lestrrat-go/jwx/jwk" ) +// MethodName is the name of this DID method. +const MethodName = "jwk" + var _ types.DIDResolver = (*Resolver)(nil) // Resolver is a DID resolver for the did:jwk method. diff --git a/vdr/vdr.go b/vdr/vdr.go index 479829d7b7..8e06cae4cf 100644 --- a/vdr/vdr.go +++ b/vdr/vdr.go @@ -30,6 +30,7 @@ import ( "fmt" "github.com/nuts-foundation/nuts-node/crypto/hash" "github.com/nuts-foundation/nuts-node/storage" + "github.com/nuts-foundation/nuts-node/vdr/didjwk" "github.com/nuts-foundation/nuts-node/vdr/didnuts" didnutsStore "github.com/nuts-foundation/nuts-node/vdr/didnuts/didstore" "github.com/nuts-foundation/nuts-node/vdr/didservice" @@ -99,6 +100,7 @@ func (r *VDR) Configure(_ core.ServerConfig) error { // Register DID methods r.didResolver.Register(didnuts.MethodName, &didnuts.Resolver{Store: r.store}) r.didResolver.Register(didweb.MethodName, didweb.NewResolver()) + r.didResolver.Register(didjwk.MethodName, didjwk.NewResolver()) // Initiate the routines for auto-updating the data. r.networkAmbassador.Configure() From c55ae829d2686e3d39e7f53b1456421dc7e2cced Mon Sep 17 00:00:00 2001 From: Rein Krul Date: Fri, 11 Aug 2023 13:24:12 +0200 Subject: [PATCH 2/2] add test --- vdr/vdr_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/vdr/vdr_test.go b/vdr/vdr_test.go index e06ccee70b..289b201bdc 100644 --- a/vdr/vdr_test.go +++ b/vdr/vdr_test.go @@ -20,8 +20,13 @@ package vdr import ( "context" + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "encoding/base64" "encoding/json" "errors" + "github.com/lestrrat-go/jwx/jwk" "github.com/nuts-foundation/nuts-node/audit" "github.com/nuts-foundation/nuts-node/core" "github.com/nuts-foundation/nuts-node/vdr/didnuts" @@ -522,6 +527,29 @@ func TestVDR_Configure(t *testing.T) { assert.NotNil(t, doc) assert.NotNil(t, md) }) + t.Run("it can resolve using did:jwk", func(t *testing.T) { + privateKey, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + expectedJWK, err := jwk.New(privateKey.Public()) + require.NoError(t, err) + + jwkBytes, _ := json.Marshal(expectedJWK) + inputDIDString := "did:jwk:" + base64.URLEncoding.EncodeToString(jwkBytes) + inputDID, err := did.ParseDID(inputDIDString) + require.NoError(t, err) + + instance := NewVDR(nil, nil, nil, nil) + err = instance.Configure(core.ServerConfig{}) + require.NoError(t, err) + + doc, md, err := instance.Resolver().Resolve(*inputDID, nil) + + assert.NoError(t, err) + assert.NotNil(t, doc) + assert.NotNil(t, md) + // Basic assertion on the actual key + require.Len(t, doc.VerificationMethod, 1) + assert.Equal(t, "P-256", doc.VerificationMethod[0].PublicKeyJwk["crv"]) + }) } type roundTripperFunc func(*http.Request) (*http.Response, error)