Skip to content

Commit

Permalink
Refactor VDR's didservice and types packages (#2513)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul authored Sep 27, 2023
1 parent 4f14681 commit 722e7a1
Show file tree
Hide file tree
Showing 124 changed files with 2,744 additions and 2,697 deletions.
6 changes: 3 additions & 3 deletions api/ssi_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-node/crypto/hash"
vcr "github.com/nuts-foundation/nuts-node/vcr/api/vcr/v2"
vdrTypes "github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
)

const (
Expand Down Expand Up @@ -183,8 +183,8 @@ func createDidDocument() did.Document {
}
}

func createDidDocumentMetadata() vdrTypes.DocumentMetadata {
return vdrTypes.DocumentMetadata{
func createDidDocumentMetadata() resolver.DocumentMetadata {
return resolver.DocumentMetadata{
Created: time.Now(),
Hash: hash.RandomHash(),
Deactivated: true,
Expand Down
8 changes: 4 additions & 4 deletions auth/api/iam/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/vcr"
"github.com/nuts-foundation/nuts-node/vcr/openid4vci"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
vdr "github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"html/template"
"net/http"
"sync"
Expand Down Expand Up @@ -206,7 +206,7 @@ func (r Wrapper) OAuthAuthorizationServerMetadata(ctx context.Context, request O

owned, err := r.vdr.IsOwner(ctx, ownDID)
if err != nil {
if didservice.IsFunctionalResolveError(err) {
if resolver.IsFunctionalResolveError(err) {
return nil, core.NotFoundError("authz server metadata: %w", err)
}
log.Logger().WithField("did", ownDID.String()).Errorf("authz server metadata: failed to assert ownership of did: %s", err.Error())
Expand All @@ -227,7 +227,7 @@ func (r Wrapper) GetWebDID(ctx context.Context, request GetWebDIDRequestObject)

document, err := r.vdr.DeriveWebDIDDocument(ctx, baseURL, ownDID)
if err != nil {
if didservice.IsFunctionalResolveError(err) {
if resolver.IsFunctionalResolveError(err) {
return GetWebDID404Response{}, nil
}
log.Logger().WithError(err).Errorf("Could not resolve Nuts DID: %s", ownDID.String())
Expand Down
11 changes: 6 additions & 5 deletions auth/api/iam/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
"github.com/nuts-foundation/nuts-node/audit"
"github.com/nuts-foundation/nuts-node/auth"
"github.com/nuts-foundation/nuts-node/core"
vdr "github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
Expand Down Expand Up @@ -60,7 +61,7 @@ func TestWrapper_OAuthAuthorizationServerMetadata(t *testing.T) {
t.Run("error - did does not exist", func(t *testing.T) {
//404
ctx := newTestClient(t)
ctx.vdr.EXPECT().IsOwner(nil, testDID).Return(false, vdr.ErrNotFound)
ctx.vdr.EXPECT().IsOwner(nil, testDID).Return(false, resolver.ErrNotFound)

res, err := ctx.client.OAuthAuthorizationServerMetadata(nil, OAuthAuthorizationServerMetadataRequestObject{Id: testDID.ID})

Expand Down Expand Up @@ -105,7 +106,7 @@ func TestWrapper_GetWebDID(t *testing.T) {
})
t.Run("unknown DID", func(t *testing.T) {
test := newTestClient(t)
test.vdr.EXPECT().DeriveWebDIDDocument(ctx, *webDIDBaseURL, nutsDID).Return(nil, vdr.ErrNotFound)
test.vdr.EXPECT().DeriveWebDIDDocument(ctx, *webDIDBaseURL, nutsDID).Return(nil, resolver.ErrNotFound)

response, err := test.client.GetWebDID(ctx, GetWebDIDRequestObject{nutsDID.ID})

Expand Down Expand Up @@ -168,7 +169,7 @@ type testCtx struct {
client *Wrapper
authnServices *auth.MockAuthenticationServices
vdr *vdr.MockVDR
resolver *vdr.MockDIDResolver
resolver *resolver.MockDIDResolver
}

func newTestClient(t testing.TB) *testCtx {
Expand All @@ -177,7 +178,7 @@ func newTestClient(t testing.TB) *testCtx {
ctrl := gomock.NewController(t)
authnServices := auth.NewMockAuthenticationServices(ctrl)
authnServices.EXPECT().PublicURL().Return(publicURL).AnyTimes()
resolver := vdr.NewMockDIDResolver(ctrl)
resolver := resolver.NewMockDIDResolver(ctrl)
vdr := vdr.NewMockVDR(ctrl)
vdr.EXPECT().Resolver().Return(resolver).AnyTimes()
return &testCtx{
Expand Down
4 changes: 2 additions & 2 deletions auth/api/iam/openid4vp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/nuts-foundation/nuts-node/vcr/credential"
"github.com/nuts-foundation/nuts-node/vcr/holder"
"github.com/nuts-foundation/nuts-node/vcr/pe"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestWrapper_handlePresentationRequest(t *testing.T) {
ctrl := gomock.NewController(t)
peStore := &pe.DefinitionResolver{}
_ = peStore.LoadFromFile("test/presentation_definition_mapping.json")
mockVDR := types.NewMockVDR(ctrl)
mockVDR := vdr.NewMockVDR(ctrl)
mockVCR := vcr.NewMockVCR(ctrl)
mockWallet := holder.NewMockWallet(ctrl)
mockVCR.EXPECT().Wallet().Return(mockWallet)
Expand Down
4 changes: 2 additions & 2 deletions auth/api/iam/s2s_vptoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/labstack/echo/v4"
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"net/http"
)

Expand Down Expand Up @@ -89,7 +89,7 @@ func (r Wrapper) RequestAccessToken(ctx context.Context, request RequestAccessTo
}
_, _, err = r.vdr.Resolver().Resolve(*requestVerifier, nil)
if err != nil {
if errors.Is(err, types.ErrNotFound) {
if errors.Is(err, resolver.ErrNotFound) {
return nil, core.InvalidInputError("verifier not found: %w", err)
}
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions auth/api/iam/s2s_vptoken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package iam

import (
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"testing"

"github.com/nuts-foundation/go-did/did"
Expand All @@ -35,7 +35,7 @@ func TestWrapper_RequestAccessToken(t *testing.T) {
t.Run("ok", func(t *testing.T) {
ctx := newTestClient(t)
ctx.vdr.EXPECT().IsOwner(nil, walletDID).Return(true, nil)
ctx.resolver.EXPECT().Resolve(verifierDID, nil).Return(&did.Document{}, &types.DocumentMetadata{}, nil)
ctx.resolver.EXPECT().Resolve(verifierDID, nil).Return(&did.Document{}, &resolver.DocumentMetadata{}, nil)

_, err := ctx.client.RequestAccessToken(nil, RequestAccessTokenRequestObject{Did: walletDID.String(), Body: body})

Expand Down Expand Up @@ -78,7 +78,7 @@ func TestWrapper_RequestAccessToken(t *testing.T) {
t.Run("verifier not found", func(t *testing.T) {
ctx := newTestClient(t)
ctx.vdr.EXPECT().IsOwner(nil, walletDID).Return(true, nil)
ctx.resolver.EXPECT().Resolve(verifierDID, nil).Return(nil, nil, types.ErrNotFound)
ctx.resolver.EXPECT().Resolve(verifierDID, nil).Return(nil, nil, resolver.ErrNotFound)

_, err := ctx.client.RequestAccessToken(nil, RequestAccessTokenRequestObject{Did: walletDID.String(), Body: body})

Expand Down
4 changes: 2 additions & 2 deletions auth/api/iam/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ package iam

import (
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
)

// DIDDocument is an alias
type DIDDocument = did.Document

// DIDDocumentMetadata is an alias
type DIDDocumentMetadata = types.DocumentMetadata
type DIDDocumentMetadata = resolver.DocumentMetadata

const (
// responseTypeParam is the name of the response_type parameter.
Expand Down
10 changes: 5 additions & 5 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/vcr/pe"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"net/url"
"path"
"time"
Expand Down Expand Up @@ -55,7 +55,7 @@ type Auth struct {
vcr vcr.VCR
pkiProvider pki.Provider
shutdownFunc func()
vdrInstance types.VDR
vdrInstance vdr.VDR
publicURL *url.URL
presentationDefinitions *pe.DefinitionResolver
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func (auth *Auth) PresentationDefinitions() *pe.DefinitionResolver {
}

// NewAuthInstance accepts a Config with several Nuts Engines and returns an instance of Auth
func NewAuthInstance(config Config, vdrInstance types.VDR, vcr vcr.VCR, keyStore crypto.KeyStore, serviceResolver didman.CompoundServiceResolver, jsonldManager jsonld.JSONLD, pkiProvider pki.Provider) *Auth {
func NewAuthInstance(config Config, vdrInstance vdr.VDR, vcr vcr.VCR, keyStore crypto.KeyStore, serviceResolver didman.CompoundServiceResolver, jsonldManager jsonld.JSONLD, pkiProvider pki.Provider) *Auth {
return &Auth{
config: config,
jsonldManager: jsonldManager,
Expand Down Expand Up @@ -145,7 +145,7 @@ func (auth *Auth) Configure(config core.ServerConfig) error {
ContractValidators: auth.config.ContractValidators,
ContractValidity: contractValidity,
StrictMode: config.Strictmode,
}, auth.vcr, didservice.KeyResolver{Resolver: auth.vdrInstance.Resolver()}, auth.keyStore, auth.jsonldManager, auth.pkiProvider)
}, auth.vcr, resolver.DIDKeyResolver{Resolver: auth.vdrInstance.Resolver()}, auth.keyStore, auth.jsonldManager, auth.pkiProvider)

tlsEnabled := config.TLS.Enabled()
if config.Strictmode && !tlsEnabled {
Expand Down
4 changes: 2 additions & 2 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/nuts-foundation/nuts-node/crypto"
"github.com/nuts-foundation/nuts-node/pki"
"github.com/nuts-foundation/nuts-node/vcr"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/nuts-foundation/nuts-node/vdr"
"go.uber.org/mock/gomock"
"testing"

Expand All @@ -45,7 +45,7 @@ func TestAuth_Configure(t *testing.T) {
pkiMock := pki.NewMockProvider(ctrl)
pkiMock.EXPECT().AddTruststore(gomock.Any()) // uzi
pkiMock.EXPECT().CreateTLSConfig(gomock.Any()) // tlsConfig
vdrInstance := types.NewMockVDR(ctrl)
vdrInstance := vdr.NewMockVDR(ctrl)
vdrInstance.EXPECT().Resolver().AnyTimes()

i := NewAuthInstance(config, vdrInstance, vcr.NewTestVCRInstance(t), crypto.NewMemoryCryptoInstance(), nil, nil, pkiMock)
Expand Down
10 changes: 5 additions & 5 deletions auth/services/notary/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/vdr/resolver"

"github.com/nuts-foundation/nuts-node/core"
"reflect"
Expand All @@ -42,7 +43,6 @@ import (
"github.com/nuts-foundation/nuts-node/jsonld"
"github.com/nuts-foundation/nuts-node/pki"
"github.com/nuts-foundation/nuts-node/vcr"
"github.com/nuts-foundation/nuts-node/vdr/types"
)

// ErrMissingOrganizationKey is used to indicate that this node has no private key of the indicated organization.
Expand Down Expand Up @@ -78,7 +78,7 @@ func (c Config) hasContractValidator(cv string) bool {
type notary struct {
config Config
jsonldManager jsonld.JSONLD
keyResolver types.KeyResolver
keyResolver resolver.KeyResolver
privateKeyStore crypto.KeyStore
verifiers map[string]contract.VPVerifier
signers map[string]contract.Signer
Expand All @@ -90,7 +90,7 @@ type notary struct {
var timeNow = time.Now

// NewNotary accepts the registry and crypto Nuts engines and returns a ContractNotary
func NewNotary(config Config, vcr vcr.VCR, keyResolver types.KeyResolver, keyStore crypto.KeyStore, jsonldManager jsonld.JSONLD, pkiValidator pki.Validator) services.ContractNotary {
func NewNotary(config Config, vcr vcr.VCR, keyResolver resolver.KeyResolver, keyStore crypto.KeyStore, jsonldManager jsonld.JSONLD, pkiValidator pki.Validator) services.ContractNotary {
return &notary{
config: config,
jsonldManager: jsonldManager,
Expand All @@ -107,8 +107,8 @@ func NewNotary(config Config, vcr vcr.VCR, keyResolver types.KeyResolver, keySto
// If the duration is 0 than the default duration is used.
func (n *notary) DrawUpContract(ctx context.Context, template contract.Template, orgID did.DID, validFrom time.Time, validDuration time.Duration, organizationCredential *vc.VerifiableCredential) (*contract.Contract, error) {
// Test if the org in managed by this node:
signingKeyID, _, err := n.keyResolver.ResolveKey(orgID, &validFrom, types.NutsSigningKeyType)
if errors.Is(err, types.ErrNotFound) {
signingKeyID, _, err := n.keyResolver.ResolveKey(orgID, &validFrom, resolver.NutsSigningKeyType)
if errors.Is(err, resolver.ErrNotFound) {
return nil, services.InvalidContractRequestError{Message: "no valid organization credential at provided validFrom date"}
} else if err != nil {
return nil, fmt.Errorf("could not draw up contract: %w", err)
Expand Down
15 changes: 7 additions & 8 deletions auth/services/notary/notary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"context"
"encoding/json"
"errors"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"testing"
"time"

Expand All @@ -35,7 +35,6 @@ import (
"github.com/nuts-foundation/nuts-node/jsonld"
"github.com/nuts-foundation/nuts-node/vcr"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/types"
irma "github.com/privacybydesign/irmago"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -68,7 +67,7 @@ func TestContract_DrawUpContract(t *testing.T) {
t.Run("draw up valid contract", func(t *testing.T) {
test := buildContext(t)

test.keyResolver.EXPECT().ResolveKey(orgID, &validFrom, types.NutsSigningKeyType).Return(keyID, nil, nil)
test.keyResolver.EXPECT().ResolveKey(orgID, &validFrom, resolver.NutsSigningKeyType).Return(keyID, nil, nil)
test.keyStore.EXPECT().Exists(ctx, keyID.String()).Return(true)
test.vcr.EXPECT().Search(context.Background(), searchTerms, false, nil).Return([]vc.VerifiableCredential{testCredential}, nil)

Expand All @@ -83,7 +82,7 @@ func TestContract_DrawUpContract(t *testing.T) {
test := buildContext(t)
defer test.ctrl.Finish()

test.keyResolver.EXPECT().ResolveKey(orgID, gomock.Any(), types.NutsSigningKeyType).Return(keyID, nil, nil)
test.keyResolver.EXPECT().ResolveKey(orgID, gomock.Any(), resolver.NutsSigningKeyType).Return(keyID, nil, nil)
test.keyStore.EXPECT().Exists(ctx, keyID.String()).Return(true)

drawnUpContract, err := test.notary.DrawUpContract(ctx, template, orgID, validFrom, duration, &testCredential)
Expand Down Expand Up @@ -128,7 +127,7 @@ func TestContract_DrawUpContract(t *testing.T) {
t.Run("nok - unknown organization", func(t *testing.T) {
test := buildContext(t)

test.keyResolver.EXPECT().ResolveKey(orgID, &validFrom, gomock.Any()).Return(ssi.URI{}, nil, types.ErrNotFound)
test.keyResolver.EXPECT().ResolveKey(orgID, &validFrom, gomock.Any()).Return(ssi.URI{}, nil, resolver.ErrNotFound)

drawnUpContract, err := test.notary.DrawUpContract(ctx, template, orgID, validFrom, duration, nil)

Expand Down Expand Up @@ -239,7 +238,7 @@ func TestNewContractNotary(t *testing.T) {
ContractValidity: 60 * time.Minute,
},
vcr.NewTestVCRInstance(t),
didservice.KeyResolver{},
resolver.DIDKeyResolver{},
crypto.NewMemoryCryptoInstance(),
nil,
nil,
Expand Down Expand Up @@ -372,7 +371,7 @@ type testContext struct {

signerMock *contract.MockSigner
vcr *vcr.MockVCR
keyResolver *types.MockKeyResolver
keyResolver *resolver.MockKeyResolver
keyStore *crypto.MockKeyStore
notary notary
}
Expand All @@ -388,7 +387,7 @@ func buildContext(t *testing.T) *testContext {
ctx := &testContext{
ctrl: ctrl,
vcr: vcr.NewMockVCR(ctrl),
keyResolver: types.NewMockKeyResolver(ctrl),
keyResolver: resolver.NewMockKeyResolver(ctrl),
keyStore: crypto.NewMockKeyStore(ctrl),
signerMock: signerMock,
}
Expand Down
Loading

0 comments on commit 722e7a1

Please sign in to comment.