did: add document resolution parameters to hint the VerificationMethods

This commit is contained in:
Michael Muré
2025-07-03 15:56:37 +02:00
parent 9b871b5a20
commit 092443980c
2 changed files with 42 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ type DID interface {
// Document resolves the DID into a DID Document usable for e.g. signature check.
// This can be simply expanding the DID into a Document, or involve external resolution.
Document() (Document, error)
Document(opts ...ResolutionOption) (Document, error)
// String returns the string representation of the DID.
String() string

41
options.go Normal file
View File

@@ -0,0 +1,41 @@
package did
type ResolutionOpts struct {
hintVerificationMethod []string
}
func (opts *ResolutionOpts) HasVerificationMethodHint(hint string) bool {
for _, h := range opts.hintVerificationMethod {
if h == hint {
return true
}
}
return false
}
func CollectResolutionOpts(opts []ResolutionOption) ResolutionOpts {
res := ResolutionOpts{}
for _, opt := range opts {
opt(&res)
}
return res
}
type ResolutionOption func(opts *ResolutionOpts)
// WithResolutionHintVerificationMethod adds a hint for the type of verification method to be used
// when resolving and constructing the DID Document, if possible.
// Hints are expected to be VerificationMethod string types, like ed25519vm.Type.
func WithResolutionHintVerificationMethod(hint string) ResolutionOption {
return func(opts *ResolutionOpts) {
if len(hint) == 0 {
return
}
for _, s := range opts.hintVerificationMethod {
if s == hint {
return
}
}
opts.hintVerificationMethod = append(opts.hintVerificationMethod, hint)
}
}