From 092443980c9de8524cdcf3e3bbaf4c38552e42ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Thu, 3 Jul 2025 15:56:37 +0200 Subject: [PATCH] did: add document resolution parameters to hint the VerificationMethods --- interfaces.go | 2 +- options.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 options.go diff --git a/interfaces.go b/interfaces.go index 6ac8da4..4878f62 100644 --- a/interfaces.go +++ b/interfaces.go @@ -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 diff --git a/options.go b/options.go new file mode 100644 index 0000000..cd7c018 --- /dev/null +++ b/options.go @@ -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) + } +}