doc

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2022 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package doc contains DID Document related functionality that only matters to the current node. All functionality here has zero relations to the network.

Package doc is a generated GoMock package.

Index

Constants

View Source
const DefaultMaxServiceReferenceDepth = 5

DefaultMaxServiceReferenceDepth holds the default max. allowed depth for DID service references.

View Source
const NutsDIDMethodName = "nuts"

NutsDIDMethodName is the DID method name used by Nuts

Variables

View Source
var ErrDiffID = errors.New("no matching IDs")

ErrDiffID is returned when a merge is done on documents that do not share the same ID

View Source
var ErrInvalidOptions = errors.New("create request has invalid combination of options: SelfControl = true and CapabilityInvocation = false")

ErrInvalidOptions is returned when the given options have an invalid combination

View Source
var ErrNestedDocumentsTooDeep = errors.New("DID Document controller structure has too many indirections")

ErrNestedDocumentsTooDeep is returned when a DID Document contains a multiple services with the same type

Functions

func ByServiceType

func ByServiceType(serviceType string) types.Predicate

ByServiceType returns a predicate that matches on service type it only matches on DID Documents with a concrete endpoint (not starting with "did")

func CreateDocument

func CreateDocument() did.Document

CreateDocument creates an empty DID document with baseline properties set.

func CreateNewVerificationMethodForDID

func CreateNewVerificationMethodForDID(id did.DID, keyCreator nutsCrypto.KeyCreator) (*did.VerificationMethod, error)

CreateNewVerificationMethodForDID creates a new VerificationMethod of type JsonWebKey2020 with a freshly generated key for a given DID.

func DefaultCreationOptions

func DefaultCreationOptions() vdr.DIDCreationOptions

DefaultCreationOptions returns the default DIDCreationOptions when creating DID Documents.

func ExtractAssertionKeyID

func ExtractAssertionKeyID(doc did.Document) (ssi.URI, error)

ExtractAssertionKeyID returns a assertionMethod ID from the given DID document. it returns types.ErrKeyNotFound is no assertionMethod key is present.

func IsActive

func IsActive() types.Predicate

IsActive returns a predicate that matches DID Documents that are not deactivated.

func IsServiceReference

func IsServiceReference(endpoint string) bool

IsServiceReference checks whether the given endpoint string looks like a service reference (e.g. did:nuts:1234/serviceType?type=HelloWorld).

func MakeServiceReference

func MakeServiceReference(subjectDID did.DID, serviceType string) ssi.URI

MakeServiceReference creates a service reference, which can be used as query when looking up services.

func MergeDocuments

func MergeDocuments(docA did.Document, docB did.Document) (*did.Document, error)

MergeDocuments merges two DID Documents that share the same ID

func ValidAt

func ValidAt(at time.Time) types.Predicate

ValidAt returns a predicate that matches on validity period.

func ValidateServiceReference

func ValidateServiceReference(endpointURI ssi.URI) error

ValidateServiceReference checks whether the given URI matches the format for a service reference.

Types

type Creator

type Creator struct {
	// KeyStore is used for getting a fresh key and use it to generate the Nuts DID
	KeyStore nutsCrypto.KeyCreator
}

Creator implements the DocCreator interface and can create Nuts DID Documents.

func (Creator) Create

func (n Creator) Create(options vdr.DIDCreationOptions) (*did.Document, nutsCrypto.Key, error)

Create creates a Nuts DID Document with a valid DID id based on a freshly generated keypair. The key is added to the verificationMethod list and referred to from the Authentication list

type Finder

type Finder struct {
	Store types.Store
}

Finder is a helper that implements the DocFinder interface

func (Finder) Find

func (f Finder) Find(predicate ...types.Predicate) ([]did.Document, error)

type KeyResolver

type KeyResolver struct {
	Store types.Store
}

KeyResolver implements the KeyResolver interface with a types.Store as backend

func (KeyResolver) ResolveAssertionKeyID

func (r KeyResolver) ResolveAssertionKeyID(id did.DID) (ssi.URI, error)

ResolveAssertionKeyID resolves the id of the first valid AssertionMethod of an indicated DID document in the current state.

func (KeyResolver) ResolveKeyAgreementKey

func (r KeyResolver) ResolveKeyAgreementKey(id did.DID) (crypto.PublicKey, error)

ResolveKeyAgreementKey resolves the public key of the first valid KeyAgreement of an indicated DID document in the current state. If the document has no KeyAgreements, types.ErrKeyNotFound is returned.

func (KeyResolver) ResolvePublicKey

func (r KeyResolver) ResolvePublicKey(kid string, sourceTransactionsRefs []hash.SHA256Hash) (crypto.PublicKey, error)

func (KeyResolver) ResolvePublicKeyInTime

func (r KeyResolver) ResolvePublicKeyInTime(kid string, validAt *time.Time) (crypto.PublicKey, error)

func (KeyResolver) ResolveSigningKey

func (r KeyResolver) ResolveSigningKey(keyID string, validAt *time.Time) (crypto.PublicKey, error)

ResolveSigningKey resolves the PublicKey of the first valid AssertionMethod for an indicated DID document at a validAt time.

func (KeyResolver) ResolveSigningKeyID

func (r KeyResolver) ResolveSigningKeyID(holder did.DID, validAt *time.Time) (string, error)

ResolveSigningKeyID resolves the ID of the first valid AssertionMethod for a indicated DID document at a given time.

type Manipulator

type Manipulator struct {
	// KeyCreator is used for getting a fresh key and use it to generate the Nuts DID
	KeyCreator nutsCrypto.KeyCreator
	// Updater is used for updating DID documents after the operation has been performed
	Updater types.DocUpdater
	// Resolver is used for resolving DID Documents
	Resolver types.DocResolver
}

Manipulator contains helper methods to update a Nuts DID document.

func (Manipulator) AddVerificationMethod

func (u Manipulator) AddVerificationMethod(id did.DID) (*did.VerificationMethod, error)

AddVerificationMethod adds a new key as a VerificationMethod to the document. The key is not used yet and should be manually added to one of the VerificationRelationships

func (Manipulator) Deactivate

func (u Manipulator) Deactivate(id did.DID) error

Deactivate updates the DID Document so it can no longer be updated It removes key material, services and controllers.

func (Manipulator) RemoveVerificationMethod

func (u Manipulator) RemoveVerificationMethod(id, keyID did.DID) error

RemoveVerificationMethod is a helper function to remove a verificationMethod from a DID Document When the verificationMethod is used in an assertion or authentication method, it is also removed there.

type MockServiceResolver

type MockServiceResolver struct {
	// contains filtered or unexported fields
}

MockServiceResolver is a mock of ServiceResolver interface.

func NewMockServiceResolver

func NewMockServiceResolver(ctrl *gomock.Controller) *MockServiceResolver

NewMockServiceResolver creates a new mock instance.

func (*MockServiceResolver) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockServiceResolver) Resolve

func (m *MockServiceResolver) Resolve(query ssi.URI, maxDepth int) (did.Service, error)

Resolve mocks base method.

func (*MockServiceResolver) ResolveEx

func (m *MockServiceResolver) ResolveEx(endpoint ssi.URI, depth, maxDepth int, documentCache map[string]*did.Document) (did.Service, error)

ResolveEx mocks base method.

type MockServiceResolverMockRecorder

type MockServiceResolverMockRecorder struct {
	// contains filtered or unexported fields
}

MockServiceResolverMockRecorder is the mock recorder for MockServiceResolver.

func (*MockServiceResolverMockRecorder) Resolve

func (mr *MockServiceResolverMockRecorder) Resolve(query, maxDepth interface{}) *gomock.Call

Resolve indicates an expected call of Resolve.

func (*MockServiceResolverMockRecorder) ResolveEx

func (mr *MockServiceResolverMockRecorder) ResolveEx(endpoint, depth, maxDepth, documentCache interface{}) *gomock.Call

ResolveEx indicates an expected call of ResolveEx.

type Resolver

type Resolver struct {
	Store types.Store
}

Resolver implements the DocResolver interface with a types.Store as backend

func (Resolver) Resolve

func (d Resolver) Resolve(id did.DID, metadata *types.ResolveMetadata) (*did.Document, *types.DocumentMetadata, error)

func (Resolver) ResolveControllers

func (d Resolver) ResolveControllers(doc did.Document, metadata *types.ResolveMetadata) ([]did.Document, error)

ResolveControllers finds the DID Document controllers

type ServiceResolver

type ServiceResolver interface {
	// Resolve looks up the DID document of the specified query and then tries to find the service with the specified type.
	// The query must be in the form of a service query, e.g. `did:nuts:12345/serviceEndpoint?type=some-type`.
	// The maxDepth indicates how deep references are followed. If maxDepth = 0, no references are followed (and an error is returned if the given query resolves to a reference).
	// If the DID document or service is not found, a reference can't be resolved or the references exceed maxDepth, an error is returned.
	Resolve(query ssi.URI, maxDepth int) (did.Service, error)

	// ResolveEx tries to resolve a DID service from the given endpoint URI, following references (URIs that begin with 'did:').
	// When the endpoint is a reference it resolves it up until the (per spec) max reference depth. When resolving a reference it recursively calls itself with depth + 1.
	// The documentCache map is used to avoid resolving the same document over and over again, which might be a (slightly more) expensive operation.
	ResolveEx(endpoint ssi.URI, depth int, maxDepth int, documentCache map[string]*did.Document) (did.Service, error)
}

ServiceResolver allows looking up DID document services, following references.

func NewServiceResolver

func NewServiceResolver(documentResolver types.DocResolver) ServiceResolver

NewServiceResolver creates a ServiceResolver with the specified types.DocResolver

type StaticKeyResolver

type StaticKeyResolver struct {
	Key crypto.PublicKey
}

func (StaticKeyResolver) ResolveAssertionKeyID

func (s StaticKeyResolver) ResolveAssertionKeyID(_ did.DID) (ssi.URI, error)

func (StaticKeyResolver) ResolveKeyAgreementKey

func (s StaticKeyResolver) ResolveKeyAgreementKey(_ did.DID) (crypto.PublicKey, error)

func (StaticKeyResolver) ResolvePublicKey

func (s StaticKeyResolver) ResolvePublicKey(_ string, _ []hash.SHA256Hash) (crypto.PublicKey, error)

func (StaticKeyResolver) ResolvePublicKeyInTime

func (s StaticKeyResolver) ResolvePublicKeyInTime(_ string, _ *time.Time) (crypto.PublicKey, error)

func (StaticKeyResolver) ResolveSigningKey

func (s StaticKeyResolver) ResolveSigningKey(_ string, _ *time.Time) (crypto.PublicKey, error)

func (StaticKeyResolver) ResolveSigningKeyID

func (s StaticKeyResolver) ResolveSigningKeyID(_ did.DID, _ *time.Time) (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL