From 6d96423591687a069ce77e577b0fe863ffaf36a4 Mon Sep 17 00:00:00 2001 From: Filip Burlacu Date: Thu, 22 Dec 2022 21:01:14 -0500 Subject: [PATCH] chore: expose didsignjwt.ResolveSigningVM as a helper API (#3457) Signed-off-by: Filip Burlacu Signed-off-by: Filip Burlacu --- pkg/doc/util/didsignjwt/signjwt.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/doc/util/didsignjwt/signjwt.go b/pkg/doc/util/didsignjwt/signjwt.go index 34fe93ec9..15746614e 100644 --- a/pkg/doc/util/didsignjwt/signjwt.go +++ b/pkg/doc/util/didsignjwt/signjwt.go @@ -108,7 +108,7 @@ func SignJWT( // nolint: funlen,gocyclo signerProvider SignerGetter, didResolver didResolver, ) (string, error) { - vm, vmID, err := resolveSigningVM(kid, didResolver) + vm, vmID, err := ResolveSigningVM(kid, didResolver) if err != nil { return "", err } @@ -166,7 +166,15 @@ func VerifyJWT(compactJWT string, return nil } -func resolveSigningVM(kid string, didResolver didResolver) (*did.VerificationMethod, string, error) { +// ResolveSigningVM resolves a DID KeyID using the given did resolver, and returns either: +// +// - the Verification Method identified by the given key ID, or +// - the first Assertion Method in the DID doc, if the DID provided has no fragment component. +// +// Returns: +// - a verification method suitable for signing. +// - the full DID#KID identifier of the returned verification method. +func ResolveSigningVM(kid string, didResolver didResolver) (*did.VerificationMethod, string, error) { vmSplit := strings.Split(kid, "#") if len(vmSplit) > vmSectionCount {