Skip to content

Commit

Permalink
add credentialStatus to CreateJWTVerifiableCredential (#99)
Browse files Browse the repository at this point in the history
* add credentialStatus

* pr feedback
  • Loading branch information
gerardsn authored Dec 1, 2023
1 parent 3abeed3 commit 1373a01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions vc/vc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions vc/vc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 1373a01

Please sign in to comment.