Skip to content

Commit

Permalink
Enable did:jwk resolving (#2396)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul authored Aug 23, 2023
1 parent b9411e3 commit f49eb7f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vdr/didjwk/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions vdr/vdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
28 changes: 28 additions & 0 deletions vdr/vdr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f49eb7f

Please sign in to comment.