Skip to content

Commit

Permalink
Issuing and rendering JWT-VC credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Oct 23, 2024
1 parent b00bebb commit 1c9fa23
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package api

import (
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-admin/discovery"
"github.com/nuts-foundation/nuts-admin/identity"
"github.com/nuts-foundation/nuts-admin/issuer"
"github.com/nuts-foundation/nuts-admin/model"
"net/http"
"strings"

Expand Down Expand Up @@ -52,7 +52,7 @@ func (w Wrapper) GetIssuedCredentials(ctx echo.Context, params GetIssuedCredenti
if err != nil {
return err
}
result := make([]vc.VerifiableCredential, 0)
result := make([]model.VerifiableCredential, 0)
for _, currID := range identities {
for _, issuerDID := range currID.DIDs {
credentials, err := w.IssuerService.GetIssuedCredentials(ctx.Request().Context(), issuerDID, strings.Split(params.CredentialTypes, ","))
Expand Down
8 changes: 4 additions & 4 deletions identity/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package identity

import (
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-admin/discovery"
"github.com/nuts-foundation/nuts-admin/model"
)

type Identity struct {
Expand All @@ -13,7 +13,7 @@ type Identity struct {

type IdentityDetails struct {
Identity
DIDDocuments []did.Document `json:"did_documents"`
DiscoveryServices []discovery.DIDStatus `json:"discovery_services"`
WalletCredentials []vc.VerifiableCredential `json:"wallet_credentials"`
DIDDocuments []did.Document `json:"did_documents"`
DiscoveryServices []discovery.DIDStatus `json:"discovery_services"`
WalletCredentials []model.VerifiableCredential `json:"wallet_credentials"`
}
7 changes: 5 additions & 2 deletions identity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/nuts-foundation/go-nuts-client/nuts/vcr"
"github.com/nuts-foundation/go-nuts-client/nuts/vdr"
"github.com/nuts-foundation/nuts-admin/discovery"
"github.com/nuts-foundation/nuts-admin/model"
"slices"
"strings"
)
Expand Down Expand Up @@ -62,7 +63,7 @@ func (i Service) Get(ctx context.Context, subjectID string) (*IdentityDetails, e
result := IdentityDetails{
Identity: *identity,
DiscoveryServices: make([]discovery.DIDStatus, 0),
WalletCredentials: make([]vc.VerifiableCredential, 0),
WalletCredentials: make([]model.VerifiableCredential, 0),
}

// Get DIDDocuments
Expand Down Expand Up @@ -96,10 +97,12 @@ func (i Service) Get(ctx context.Context, subjectID string) (*IdentityDetails, e
})

// Get WalletCredentials
result.WalletCredentials, err = i.credentialsInWallet(ctx, subjectID)
vcs, err := i.credentialsInWallet(ctx, subjectID)
if err != nil {
return nil, err
}
creds := model.ToModel(vcs)
result.WalletCredentials = creds

return &result, nil
}
Expand Down
5 changes: 3 additions & 2 deletions issuer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/nuts-foundation/go-nuts-client/nuts"
"github.com/nuts-foundation/go-nuts-client/nuts/vcr"
"github.com/nuts-foundation/nuts-admin/identity"
"github.com/nuts-foundation/nuts-admin/model"
"strings"
)

Expand All @@ -14,7 +15,7 @@ type Service struct {
VCRClient *vcr.Client
}

func (s Service) GetIssuedCredentials(ctx context.Context, issuer string, credentialTypes []string) ([]vc.VerifiableCredential, error) {
func (s Service) GetIssuedCredentials(ctx context.Context, issuer string, credentialTypes []string) ([]model.VerifiableCredential, error) {
var result []vc.VerifiableCredential
for _, credentialType := range credentialTypes {
credentialType = strings.TrimSpace(credentialType)
Expand All @@ -33,5 +34,5 @@ func (s Service) GetIssuedCredentials(ctx context.Context, issuer string, creden
result = append(result, searchResult.VerifiableCredential)
}
}
return result, nil
return model.ToModel(result), nil
}
19 changes: 19 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package model

import "github.com/nuts-foundation/go-did/vc"

type VerifiableCredential vc.VerifiableCredential

func ToModel(vcs []vc.VerifiableCredential) []VerifiableCredential {
var result []VerifiableCredential
for _, credential := range vcs {
currentCredential := VerifiableCredential(credential)
if credential.Format() == vc.JWTCredentialProofFormat {
currentCredential.Proof = []interface{}{
"jwt",
}
}
result = append(result, currentCredential)
}
return result
}
20 changes: 18 additions & 2 deletions web/src/admin/credentials/CredentialDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<section>
<div>
<label>ID</label>
<div>{{credential.credentialSubject.id}}</div>
<div>{{credentialSubject.id}}</div>
</div>
<div>
<label>Type</label>
Expand All @@ -14,6 +14,14 @@
<label>Issuer</label>
<div>{{credential.issuer}}</div>
</div>
<div>
<label>Issuance date</label>
<div>{{credential.issuanceDate}}</div>
</div>
<div>
<label>Expiration date</label>
<div>{{credential.expirationDate}}</div>
</div>
</section>
<section>
<header>Credential Subject</header>
Expand All @@ -33,14 +41,19 @@
</table>
</section>
</div>

</template>
<script>
export default {
props: {
credential: Object
},
computed: {
credentialSubject() {
if (Array.isArray(this.credential.credentialSubject) && this.credential.credentialSubject.length === 1) {
return this.credential.credentialSubject[0]
}
return this.credential.credentialSubject
},
credentialType() {
return this.credential.type.filter(t => t !== "VerifiableCredential").join(', ')
},
Expand All @@ -56,6 +69,9 @@ export default {
}
}, [])
}
if (Array.isArray(this.credential.credentialSubject) && this.credential.credentialSubject.length === 1) {
return flatten(this.credential.credentialSubject[0])
}
return flatten(this.credential.credentialSubject)
}
}
Expand Down
11 changes: 11 additions & 0 deletions web/src/admin/credentials/IssueCredential.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
</option>
</select>
</div>
<div>
<label for="proofFormat">Proof format</label>
<select v-model="credentialProofFormat" id="proofFormat">
<option :value="format" v-for="format in ['ldp_vc', 'jwt_vc']" :key="format"
:selected="format === credentialProofFormat">
{{ format }}
</option>
</select>
</div>

<div>
<label for="issuerDID">Issuer DID</label>
Expand Down Expand Up @@ -85,6 +94,7 @@ export default {
data() {
return {
fetchError: undefined,
credentialProofFormat: 'ldp_vc',
credentialType: undefined,
subjectDID: undefined,
holderSubjectID: undefined,
Expand Down Expand Up @@ -141,6 +151,7 @@ export default {
credentialToIssue['@context'] = credentialToIssue['@context'][0]
credentialToIssue['type'] = credentialToIssue['type'].find(t => t !== "VerifiableCredential")
credentialToIssue['expirationDate'] = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * this.daysValid).toISOString()
credentialToIssue['format'] = this.credentialProofFormat
// disable statusListRevocation2021 for now, causes issues on MS SQL Server
//credentialToIssue.withStatusList2021Revocation = true
this.fetchError = undefined
Expand Down
2 changes: 1 addition & 1 deletion web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Identities from './admin/Identities.vue'
import NewIdentity from './admin/NewIdentity.vue'
import DiscoveryServices from './admin/DiscoveryServices.vue'
import IssuedCredentials from './admin/credentials/IssuedCredentials.vue'
import WalletCredentialDetails from "./admin/Credentials/WalletCredentialDetails.vue";
import WalletCredentialDetails from "./admin/credentials/WalletCredentialDetails.vue";
import Api from './plugins/api'
import IdentityDetails from "./admin/IdentityDetails.vue";
import IssueCredential from "./admin/credentials/IssueCredential.vue";
Expand Down
1 change: 1 addition & 0 deletions web/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pre {
border: 1px solid darkgray;
padding: 12px;
border-radius: 3px;
white-space: pre-wrap;
}

textarea {
Expand Down

0 comments on commit 1c9fa23

Please sign in to comment.