Skip to content

Commit

Permalink
fix: expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 committed Apr 10, 2024
1 parent 57207b9 commit 808efa3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/service/oidc4ci/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"text/template"

"github.com/google/uuid"
util "github.com/trustbloc/did-go/doc/util/time"
"github.com/trustbloc/vc-go/verifiable"
)

Expand Down Expand Up @@ -67,6 +68,10 @@ func (c *CredentialComposer) Compose(
credential = credential.WithModifiedSubject(newSubjects)
}

if credential.Contents().Expired == nil && txCredentialConfiguration.CredentialExpiresAt != nil {
credential.SetCustomField("expirationDate", util.NewTime(*txCredentialConfiguration.CredentialExpiresAt))
}

return credential, nil
}

Expand Down
15 changes: 14 additions & 1 deletion pkg/service/oidc4ci/composer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func TestComposer(t *testing.T) {
srv := oidc4ci.NewCredentialComposer()

cred, err := verifiable.CreateCredential(verifiable.CredentialContents{
Types: []string{"VerifiableCredential"},
Context: []string{
"https://www.w3.org/2018/credentials/v1",
},
Subject: []verifiable.Subject{{ID: "xxx:yyy"}},
}, verifiable.CustomFields{})
assert.NoError(t, err)
Expand Down Expand Up @@ -49,10 +53,19 @@ func TestComposer(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, resp)

credJSON, err := resp.MarshalAsJSONLD()
assert.NoError(t, err)

parsedCred, err := verifiable.ParseCredential(credJSON,
verifiable.WithCredDisableValidation(),
verifiable.WithDisabledProofCheck(),
)
assert.NoError(t, err)

assert.EqualValues(t, "hardcoded:some-awesome-id:suffix", resp.Contents().ID)
assert.EqualValues(t, "did:example:123", resp.Contents().Issuer.ID)
assert.EqualValues(t, "some-awesome-did", resp.Contents().Subject[0].ID)
assert.EqualValues(t, expectedExpiration, resp.Contents().Expired.Time)
assert.EqualValues(t, expectedExpiration, parsedCred.Contents().Expired.Time)
})

t.Run("success with prev-id", func(t *testing.T) {
Expand Down

0 comments on commit 808efa3

Please sign in to comment.