didservice

package
v5.4.40 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const DefaultMaxServiceReferenceDepth = 5

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

View Source
const JWS2020ContextV1 = "https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json"

JWS2020ContextV1 contains the JSON-LD context for JWS and JWK

View Source
const NutsDIDContextV1 = "https://nuts.nl/did/v1"

NutsDIDContextV1 contains the Nuts specific JSON-LD context for a DID Document

View Source
const NutsDIDMethodName = "nuts"

NutsDIDMethodName is the DID method name used by Nuts

Variables

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(ctx context.Context, 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 ExtractFirstRelationKeyIDByType

func ExtractFirstRelationKeyIDByType(doc did.Document, relationType types.RelationType) (ssi.URI, error)

ExtractFirstRelationKeyIDByType returns the first relation key ID from the given DID document matching the relationType. Returns a types.ErrKeyNotFound if no relation key of the given relationType is present.

func GetDIDFromURL

func GetDIDFromURL(didURL string) (did.DID, error)

GetDIDFromURL returns the DID from the given URL, stripping any query parameters, path segments and fragments.

func IsActive

func IsActive() types.Predicate

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

func IsDeactivated

func IsDeactivated(document did.Document) bool

IsDeactivated returns true if the DID.Document has already been deactivated

func IsFunctionalResolveError

func IsFunctionalResolveError(target error) bool

IsFunctionalResolveError returns true if the given error indicates the DID or service not being found or invalid, e.g. because it is deactivated, referenced too deeply, etc.

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 JWS2020ContextV1URI

func JWS2020ContextV1URI() ssi.URI

JWS2020ContextV1URI returns JWS2020ContextV1 as a URI

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 NutsDIDContextV1URI

func NutsDIDContextV1URI() ssi.URI

NutsDIDContextV1URI returns NutsDIDContextV1 as a URI

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

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 DIDServiceQueryError

type DIDServiceQueryError struct {
	Err error // cause
}

DIDServiceQueryError denies the query based on validation constraints.

func (DIDServiceQueryError) Error

func (e DIDServiceQueryError) Error() string

Error implements the error interface.

func (DIDServiceQueryError) Unwrap

func (e DIDServiceQueryError) Unwrap() error

Unwrap implements the errors.Unwrap convention.

type Finder

type Finder struct {
	Store didstore.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 didstore.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) ResolveRelationKey

func (r KeyResolver) ResolveRelationKey(keyID string, validAt *time.Time, relationType types.RelationType) (crypto.PublicKey, error)

func (KeyResolver) ResolveRelationKeyID

func (r KeyResolver) ResolveRelationKeyID(id did.DID, relationType types.RelationType) (ssi.URI, 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 an 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(ctx context.Context, id did.DID, keyUsage types.DIDKeyFlags) (*did.VerificationMethod, error)

AddVerificationMethod adds a new key as a VerificationMethod to the document. The key is added to the VerficationMethod relationships specified by keyUsage.

func (Manipulator) Deactivate

func (u Manipulator) Deactivate(ctx context.Context, 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(ctx context.Context, id, keyID did.DID) error

RemoveVerificationMethod is a helper function to remove a verificationMethod from a DID Document

type Resolver

type Resolver struct {
	Store didstore.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 struct {
	Store didstore.Store
}

ServiceResolver is a wrapper around a DID store that allows resolving services, following references.

func (ServiceResolver) Resolve

func (s ServiceResolver) Resolve(query ssi.URI, maxDepth int) (did.Service, error)

func (ServiceResolver) ResolveEx

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

Jump to

Keyboard shortcuts

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