From 1373a01223ada940e04432fc09da3598ecb61a36 Mon Sep 17 00:00:00 2001 From: Gerard Snaauw <33763579+gerardsn@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:37:29 +0100 Subject: [PATCH] add credentialStatus to CreateJWTVerifiableCredential (#99) * add credentialStatus * pr feedback --- vc/vc.go | 14 +++++++++----- vc/vc_test.go | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/vc/vc.go b/vc/vc.go index 9bc1225..11dbe88 100644 --- a/vc/vc.go +++ b/vc/vc.go @@ -388,14 +388,15 @@ func CreateJWTVerifiableCredential(ctx context.Context, template VerifiableCrede headers := map[string]interface{}{ jws.TypeKey: "JWT", } + vcMap := map[string]interface{}{ + "@context": template.Context, + "type": template.Type, + "credentialSubject": template.CredentialSubject, + } claims := map[string]interface{}{ jwt.IssuerKey: template.Issuer.String(), jwt.SubjectKey: subjectDID.String(), - "vc": map[string]interface{}{ - "@context": template.Context, - "type": template.Type, - "credentialSubject": template.CredentialSubject, - }, + "vc": vcMap, } if template.ID != nil { claims[jwt.JwtIDKey] = template.ID.String() @@ -411,6 +412,9 @@ func CreateJWTVerifiableCredential(ctx context.Context, template VerifiableCrede // so a template using ValidFrom/ValidUntil would not match the final VC return nil, errors.New("cannot use validFrom/validUntil to generate JWT-VCs") } + if template.CredentialStatus != nil { + vcMap["credentialStatus"] = template.CredentialStatus + } token, err := signer(ctx, claims, headers) if err != nil { return nil, fmt.Errorf("unable to sign JWT credential: %w", err) diff --git a/vc/vc_test.go b/vc/vc_test.go index 288bc41..0c0e779 100644 --- a/vc/vc_test.go +++ b/vc/vc_test.go @@ -409,6 +409,10 @@ func TestCreateJWTVerifiableCredential(t *testing.T) { "id": subjectDID.String(), }, }, + CredentialStatus: []any{CredentialStatus{ + ID: ssi.MustParseURI("did:example:something"), + Type: "test", + }}, Issuer: issuerDID.URI(), } captureFn := func(claims *map[string]any, headers *map[string]any) func(_ context.Context, c map[string]interface{}, h map[string]interface{}) (string, error) { @@ -437,6 +441,7 @@ func TestCreateJWTVerifiableCredential(t *testing.T) { "credentialSubject": template.CredentialSubject, "@context": template.Context, "type": template.Type, + "credentialStatus": template.CredentialStatus, }, claims["vc"]) assert.Equal(t, map[string]interface{}{"typ": "JWT"}, headers) })