Skip to content

Commit

Permalink
move and rename doc package for clarity (#1744)
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst authored Dec 12, 2022
1 parent 3fe0dc9 commit f2f9894
Show file tree
Hide file tree
Showing 45 changed files with 170 additions and 192 deletions.
4 changes: 2 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"crypto/tls"
"errors"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"path"
"time"

Expand All @@ -36,7 +37,6 @@ import (
"github.com/nuts-foundation/nuts-node/crypto"
"github.com/nuts-foundation/nuts-node/didman"
"github.com/nuts-foundation/nuts-node/vcr"
"github.com/nuts-foundation/nuts-node/vdr/doc"
)

// ErrMissingPublicURL is returned when the publicUrl is missing from the config
Expand Down Expand Up @@ -125,7 +125,7 @@ func (auth *Auth) Configure(config core.ServerConfig) error {
ContractValidators: auth.config.ContractValidators,
ContractValidity: contractValidity,
StrictMode: config.Strictmode,
}, auth.vcr, doc.KeyResolver{Store: auth.registry}, auth.keyStore, auth.jsonldManager)
}, auth.vcr, didservice.KeyResolver{Store: auth.registry}, auth.keyStore, auth.jsonldManager)

tlsEnabled := config.TLS.Enabled()
if config.Strictmode && !tlsEnabled {
Expand Down
4 changes: 2 additions & 2 deletions auth/services/contract/notary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"encoding/json"
"errors"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"github.com/stretchr/testify/require"
"testing"
"time"
Expand All @@ -39,7 +40,6 @@ import (
"github.com/nuts-foundation/nuts-node/crypto"
"github.com/nuts-foundation/nuts-node/vcr"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/doc"
"github.com/nuts-foundation/nuts-node/vdr/store"
"github.com/nuts-foundation/nuts-node/vdr/types"
)
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestNewContractNotary(t *testing.T) {
ContractValidity: 60 * time.Minute,
},
vcr.NewTestVCRInstance(t),
doc.KeyResolver{Store: store.NewTestStore(t)},
didservice.KeyResolver{Store: store.NewTestStore(t)},
crypto.NewTestCryptoInstance(),
nil,
)
Expand Down
6 changes: 3 additions & 3 deletions auth/services/oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/vdr/didservice"

"github.com/nuts-foundation/nuts-node/auth/log"
"github.com/nuts-foundation/nuts-node/jsonld"
Expand All @@ -42,7 +43,6 @@ import (
nutsCrypto "github.com/nuts-foundation/nuts-node/crypto"
"github.com/nuts-foundation/nuts-node/vcr"
"github.com/nuts-foundation/nuts-node/vcr/credential"
"github.com/nuts-foundation/nuts-node/vdr/doc"
"github.com/nuts-foundation/nuts-node/vdr/types"
)

Expand Down Expand Up @@ -145,8 +145,8 @@ func (c validationContext) verifiableCredentials() ([]vc2.VerifiableCredential,
// NewOAuthService accepts a vendorID, and several Nuts engines and returns an implementation of services.OAuthClient
func NewOAuthService(store types.Store, vcFinder vcr.Finder, vcVerifier verifier.Verifier, serviceResolver didman.CompoundServiceResolver, privateKeyStore nutsCrypto.KeyStore, contractNotary services.ContractNotary, jsonldManager jsonld.JSONLD) services.OAuthClient {
return &service{
docResolver: doc.Resolver{Store: store},
keyResolver: doc.KeyResolver{Store: store},
docResolver: didservice.Resolver{Store: store},
keyResolver: didservice.KeyResolver{Store: store},
serviceResolver: serviceResolver,
contractNotary: contractNotary,
jsonldManager: jsonldManager,
Expand Down
4 changes: 2 additions & 2 deletions auth/services/oauth/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"github.com/stretchr/testify/require"
"net/url"
"testing"
Expand All @@ -51,7 +52,6 @@ import (
"github.com/nuts-foundation/nuts-node/vcr/credential"
vcrTypes "github.com/nuts-foundation/nuts-node/vcr/types"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/doc"
"github.com/nuts-foundation/nuts-node/vdr/types"
)

Expand Down Expand Up @@ -991,7 +991,7 @@ var createContext = func(t *testing.T) *testContext {
verifier: verifier,
didResolver: didResolver,
oauthService: &service{
docResolver: doc.Resolver{Store: didResolver},
docResolver: didservice.Resolver{Store: didResolver},
keyResolver: keyResolver,
contractNotary: contractNotaryMock,
privateKeyStore: privateKeyStore,
Expand Down
10 changes: 5 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
httpEngine "github.com/nuts-foundation/nuts-node/http"
"github.com/nuts-foundation/nuts-node/storage"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"github.com/spf13/pflag"
"io"
"os"
Expand Down Expand Up @@ -55,7 +56,6 @@ import (
"github.com/nuts-foundation/nuts-node/vdr"
vdrAPI "github.com/nuts-foundation/nuts-node/vdr/api/v1"
vdrCmd "github.com/nuts-foundation/nuts-node/vdr/cmd"
"github.com/nuts-foundation/nuts-node/vdr/doc"
"github.com/nuts-foundation/nuts-node/vdr/store"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -182,9 +182,9 @@ func CreateSystem(shutdownCallback context.CancelFunc) *core.System {
jsonld := jsonld.NewJSONLDInstance()
storageInstance := storage.New()
didStore := store.NewStore(storageInstance.GetProvider(vdr.ModuleName))
keyResolver := doc.KeyResolver{Store: didStore}
docResolver := doc.Resolver{Store: didStore}
docFinder := doc.Finder{Store: didStore}
keyResolver := didservice.KeyResolver{Store: didStore}
docResolver := didservice.Resolver{Store: didStore}
docFinder := didservice.Finder{Store: didStore}
eventManager := events.NewManager()
networkInstance := network.NewNetworkInstance(network.DefaultConfig(), keyResolver, cryptoInstance, cryptoInstance, docResolver, docFinder, eventManager, storageInstance.GetProvider(network.ModuleName))
vdrInstance := vdr.NewVDR(vdr.DefaultConfig(), cryptoInstance, networkInstance, didStore, eventManager)
Expand All @@ -198,7 +198,7 @@ func CreateSystem(shutdownCallback context.CancelFunc) *core.System {
system.RegisterRoutes(&core.LandingPage{})
system.RegisterRoutes(&cryptoAPI.Wrapper{C: cryptoInstance})
system.RegisterRoutes(&networkAPI.Wrapper{Service: networkInstance})
system.RegisterRoutes(&vdrAPI.Wrapper{VDR: vdrInstance, DocResolver: docResolver, DocManipulator: &doc.Manipulator{
system.RegisterRoutes(&vdrAPI.Wrapper{VDR: vdrInstance, DocResolver: docResolver, DocManipulator: &didservice.Manipulator{
KeyCreator: cryptoInstance,
Updater: vdrInstance,
Resolver: docResolver,
Expand Down
6 changes: 3 additions & 3 deletions didman/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ package v1
import (
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"net/http"
"net/url"
"strings"

"github.com/nuts-foundation/nuts-node/vdr/doc"
"github.com/nuts-foundation/nuts-node/vdr/types"

"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -59,11 +59,11 @@ func (w *Wrapper) ResolveStatusCode(err error) int {
return http.StatusConflict
case errors.Is(err, didman.ErrServiceInUse):
return http.StatusConflict
case errors.Is(err, doc.ErrInvalidOptions):
case errors.Is(err, didservice.ErrInvalidOptions):
return http.StatusBadRequest
case errors.Is(err, types.ErrServiceNotFound):
return http.StatusNotFound
case errors.As(err, new(doc.DIDServiceQueryError)):
case errors.As(err, new(didservice.DIDServiceQueryError)):
return http.StatusBadRequest
case errors.Is(err, types.ErrServiceReferenceToDeep):
return http.StatusNotAcceptable
Expand Down
4 changes: 2 additions & 2 deletions didman/api/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package v1

import (
"errors"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"github.com/stretchr/testify/require"
"net/http"
"net/url"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/didman"
"github.com/nuts-foundation/nuts-node/mock"
"github.com/nuts-foundation/nuts-node/vdr/doc"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -464,7 +464,7 @@ func TestWrapper_GetCompoundServiceEndpoint(t *testing.T) {
t.Run("error mapping", func(t *testing.T) {
ctx := newMockContext(t)
assert.Equal(t, http.StatusNotFound, ctx.wrapper.ResolveStatusCode(types.ErrServiceNotFound))
assert.Equal(t, http.StatusBadRequest, ctx.wrapper.ResolveStatusCode(doc.DIDServiceQueryError{errors.New("arbitrary")}))
assert.Equal(t, http.StatusBadRequest, ctx.wrapper.ResolveStatusCode(didservice.DIDServiceQueryError{errors.New("arbitrary")}))
assert.Equal(t, http.StatusNotAcceptable, ctx.wrapper.ResolveStatusCode(types.ErrServiceReferenceToDeep))
assert.Equal(t, http.StatusNotAcceptable, ctx.wrapper.ResolveStatusCode(didman.ErrReferencedServiceNotAnEndpoint{}))
assert.Equal(t, http.StatusNotFound, ctx.wrapper.ResolveStatusCode(types.ErrNotFound))
Expand Down
18 changes: 9 additions & 9 deletions didman/didman.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"net/url"
"sync"

Expand All @@ -36,7 +37,6 @@ import (
"github.com/nuts-foundation/nuts-node/jsonld"
"github.com/nuts-foundation/nuts-node/vcr"
"github.com/nuts-foundation/nuts-node/vcr/credential"
"github.com/nuts-foundation/nuts-node/vdr/doc"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/shengdoushi/base58"
)
Expand Down Expand Up @@ -88,7 +88,7 @@ func (e ErrReferencedServiceNotAnEndpoint) Is(other error) bool {
type didman struct {
jsonldManager jsonld.JSONLD
docResolver types.DocResolver
serviceResolver doc.ServiceResolver
serviceResolver didservice.ServiceResolver
store types.Store
vdr types.VDR
vcr vcr.Finder
Expand All @@ -100,7 +100,7 @@ type didman struct {
func NewDidmanInstance(docResolver types.DocResolver, store types.Store, vdr types.VDR, vcr vcr.Finder, jsonldManager jsonld.JSONLD) Didman {
return &didman{
docResolver: docResolver,
serviceResolver: doc.NewServiceResolver(docResolver),
serviceResolver: didservice.NewServiceResolver(docResolver),
store: store,
vdr: vdr,
vcr: vcr,
Expand Down Expand Up @@ -207,7 +207,7 @@ func (d *didman) GetCompoundServiceEndpoint(id did.DID, compoundServiceType stri
documentsCache := map[string]*did.Document{document.ID.String(): document}

// First, resolve the compound endpoint
compoundService, err := d.serviceResolver.ResolveEx(doc.MakeServiceReference(id, compoundServiceType), referenceDepth, doc.DefaultMaxServiceReferenceDepth, documentsCache)
compoundService, err := d.serviceResolver.ResolveEx(didservice.MakeServiceReference(id, compoundServiceType), referenceDepth, didservice.DefaultMaxServiceReferenceDepth, documentsCache)
if err != nil {
return "", ErrReferencedServiceNotAnEndpoint{Cause: fmt.Errorf("unable to resolve compound service: %w", err)}
}
Expand All @@ -222,13 +222,13 @@ func (d *didman) GetCompoundServiceEndpoint(id did.DID, compoundServiceType stri
if endpoint == "" {
return "", types.ErrServiceNotFound
}
if resolveReferences && doc.IsServiceReference(endpoint) {
if resolveReferences && didservice.IsServiceReference(endpoint) {
endpointURI, err := ssi.ParseURI(endpoint)
if err != nil {
// Not sure when this could ever happen
return "", err
}
resolvedEndpoint, err := d.serviceResolver.ResolveEx(*endpointURI, referenceDepth, doc.DefaultMaxServiceReferenceDepth, documentsCache)
resolvedEndpoint, err := d.serviceResolver.ResolveEx(*endpointURI, referenceDepth, didservice.DefaultMaxServiceReferenceDepth, documentsCache)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -469,12 +469,12 @@ func (d *didman) validateCompoundServiceEndpoint(endpoints map[string]ssi.URI) e
// Cache resolved DID documents because most of the time a compound service will refer the same DID document in all service references.
cache := make(map[string]*did.Document, 0)
for _, serviceRef := range endpoints {
if doc.IsServiceReference(serviceRef.String()) {
err := doc.ValidateServiceReference(serviceRef)
if didservice.IsServiceReference(serviceRef.String()) {
err := didservice.ValidateServiceReference(serviceRef)
if err != nil {
return ErrReferencedServiceNotAnEndpoint{Cause: err}
}
_, err = d.serviceResolver.ResolveEx(serviceRef, 0, doc.DefaultMaxServiceReferenceDepth, cache)
_, err = d.serviceResolver.ResolveEx(serviceRef, 0, didservice.DefaultMaxServiceReferenceDepth, cache)
if err != nil {
return ErrReferencedServiceNotAnEndpoint{Cause: err}
}
Expand Down
12 changes: 6 additions & 6 deletions didman/didman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"github.com/stretchr/testify/require"
"io"
"net/url"
Expand All @@ -40,7 +41,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/doc"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -127,10 +127,10 @@ func TestDidman_AddEndpoint(t *testing.T) {
func TestDidman_AddCompoundService(t *testing.T) {
meta := &types.DocumentMetadata{Hash: hash.EmptyHash()}

helloServiceQuery := doc.MakeServiceReference(*vdr.TestDIDA, "hello")
worldServiceQuery := doc.MakeServiceReference(*vdr.TestDIDB, "world")
universeServiceQuery := doc.MakeServiceReference(*vdr.TestDIDB, "universe")
universeNestedServiceQuery := doc.MakeServiceReference(*vdr.TestDIDB, "universe-ref")
helloServiceQuery := didservice.MakeServiceReference(*vdr.TestDIDA, "hello")
worldServiceQuery := didservice.MakeServiceReference(*vdr.TestDIDB, "world")
universeServiceQuery := didservice.MakeServiceReference(*vdr.TestDIDB, "universe")
universeNestedServiceQuery := didservice.MakeServiceReference(*vdr.TestDIDB, "universe-ref")
references := make(map[string]ssi.URI, 0)
references["hello"] = helloServiceQuery
references["world"] = worldServiceQuery
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestDidman_DeleteService(t *testing.T) {
}

func TestDidman_UpdateContactInformation(t *testing.T) {
didDoc := doc.CreateDocument()
didDoc := didservice.CreateDocument()
id, _ := did.ParseDID("did:nuts:123")
didDoc.ID = *id
meta := &types.DocumentMetadata{Hash: hash.EmptyHash()}
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gen-mocks:
mockgen -destination=crypto/mock.go -package=crypto -source=crypto/interface.go
mockgen -destination=crypto/storage/mock.go -package=storage -source=crypto/storage/storage.go
mockgen -destination=vdr/types/mock.go -package=types -source=vdr/types/interface.go -self_package github.com/nuts-foundation/nuts-node/vdr/types --imports did=github.com/nuts-foundation/go-did/did
mockgen -destination=vdr/doc/resolvers_mock.go -package=doc -source=vdr/doc/resolvers.go
mockgen -destination=vdr/diddocuments/dochelper/resolvers_mock.go -package=dochelper -source=vdr/diddocuments/dochelper/resolvers.go
mockgen -destination=network/mock.go -package=network -source=network/interface.go
mockgen -destination=network/transport/connection_manager_mock.go -package=transport -source=network/transport/connection_manager.go
mockgen -destination=network/transport/protocol_mock.go -package=transport -source=network/transport/protocol.go Protocol
Expand Down
6 changes: 3 additions & 3 deletions network/dag/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"crypto/elliptic"
"crypto/rand"
"errors"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"testing"
"time"

Expand All @@ -34,7 +35,6 @@ import (
"github.com/nuts-foundation/go-stoabs"
crypto2 "github.com/nuts-foundation/nuts-node/crypto"
"github.com/nuts-foundation/nuts-node/crypto/hash"
"github.com/nuts-foundation/nuts-node/vdr/doc"
"github.com/nuts-foundation/nuts-node/vdr/types"
)

Expand Down Expand Up @@ -97,14 +97,14 @@ func TestTransactionSignatureVerifier(t *testing.T) {
t.Run("referral with key ID", func(t *testing.T) {
transaction, _, publicKey := CreateTestTransaction(1)
expected, _ := ParseTransaction(transaction.Data())
err := NewTransactionSignatureVerifier(&doc.StaticKeyResolver{Key: publicKey})(nil, expected)
err := NewTransactionSignatureVerifier(&didservice.StaticKeyResolver{Key: publicKey})(nil, expected)
assert.NoError(t, err)
})
t.Run("wrong key", func(t *testing.T) {
attackerKey, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
transaction, _, _ := CreateTestTransaction(1)
expected, _ := ParseTransaction(transaction.Data())
err := NewTransactionSignatureVerifier(&doc.StaticKeyResolver{Key: attackerKey.Public()})(nil, expected)
err := NewTransactionSignatureVerifier(&didservice.StaticKeyResolver{Key: attackerKey.Public()})(nil, expected)
assert.EqualError(t, err, "failed to verify message: failed to verify signature using ecdsa")
})
t.Run("key type is incorrect", func(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/vdr/didservice"
"strings"
"sync/atomic"
"time"
Expand All @@ -42,7 +43,6 @@ import (
"github.com/nuts-foundation/nuts-node/network/transport/grpc"
"github.com/nuts-foundation/nuts-node/network/transport/v2"
"github.com/nuts-foundation/nuts-node/storage"
"github.com/nuts-foundation/nuts-node/vdr/doc"
"github.com/nuts-foundation/nuts-node/vdr/types"
"go.etcd.io/bbolt"
)
Expand Down Expand Up @@ -236,9 +236,9 @@ func (n *Network) Configure(config core.ServerConfig) error {
if config.Strictmode {
return errors.New("disabling node DID in strict mode is not allowed")
}
authenticator = grpc.NewDummyAuthenticator(doc.NewServiceResolver(n.didDocumentResolver))
authenticator = grpc.NewDummyAuthenticator(didservice.NewServiceResolver(n.didDocumentResolver))
} else {
authenticator = grpc.NewTLSAuthenticator(doc.NewServiceResolver(n.didDocumentResolver))
authenticator = grpc.NewTLSAuthenticator(didservice.NewServiceResolver(n.didDocumentResolver))
}
n.connectionStore, err = n.storeProvider.GetKVStore("connections", storage.VolatileStorageClass)
if err != nil {
Expand Down Expand Up @@ -351,7 +351,7 @@ func (n *Network) connectToKnownNodes(nodeDID did.DID) error {
}

// start connecting to published NutsComm addresses
otherNodes, err := n.didDocumentFinder.Find(doc.IsActive(), doc.ValidAt(time.Now()), doc.ByServiceType(transport.NutsCommServiceType))
otherNodes, err := n.didDocumentFinder.Find(didservice.IsActive(), didservice.ValidAt(time.Now()), didservice.ByServiceType(transport.NutsCommServiceType))
if err != nil {
return err
}
Expand Down Expand Up @@ -409,9 +409,9 @@ func (n *Network) validateNodeDID(nodeDID did.DID) error {
}

// Check if the DID document has a resolvable and valid NutsComm endpoint
serviceResolver := doc.NewServiceResolver(n.didDocumentResolver)
serviceRef := doc.MakeServiceReference(nodeDID, transport.NutsCommServiceType)
nutsCommService, err := serviceResolver.Resolve(serviceRef, doc.DefaultMaxServiceReferenceDepth)
serviceResolver := didservice.NewServiceResolver(n.didDocumentResolver)
serviceRef := didservice.MakeServiceReference(nodeDID, transport.NutsCommServiceType)
nutsCommService, err := serviceResolver.Resolve(serviceRef, didservice.DefaultMaxServiceReferenceDepth)
if err != nil {
return fmt.Errorf("unable to resolve %s service endpoint, register it on the DID document (did=%s): %v", transport.NutsCommServiceType, nodeDID, err)
}
Expand Down
Loading

0 comments on commit f2f9894

Please sign in to comment.