Create a Semantic Compact Credential

Introduction

This guide will demonstrate how to create a Semantic Compact Credential using MATTR VII. The semantic profile represents the credential claims inside of a W3C Verifiable Credential data model which is then signed as a Compact Credential.  

If you need a credential that is more compact at the expense of not using a semantic data model, then look at the tutorial for issuing a Compact Credential.

Prerequisites

You need the following in order to proceed with this tutorial: 

  • Access to the MATTR VII APIs

  • A Web DID using a P-256 keyType ONLY

  • A vocabulary reference/context 

  • Claim values

If you’re experiencing any difficulties, contact us

Create a Web DID 

A web DID (iss) is required when issuing a Compact Credential. This can be achieved by using the following API with keyType "P-256" in the request payload.

Request

http
Copy to clipboard.
1POST https://YOUR_TENANT_URL/core/v1/dids
json
Copy to clipboard.
1{
2  "method": "web",
3  "options": {
4    "url": "example.nz",
5    "keyType": "P-256"
6  }
7}

The created DID will then need to be hosted on the path specified in the url option.

Sign a credential 

Request

http
Copy to clipboard.
1POST https://YOUR_TENANT_URL/v2/credentials/compact-semantic/sign
json
Copy to clipboard.
1{
2  "payload": {
3    "iss": "did:web:example.nz",
4    "nbf": 1516239022,
5    "exp": 2516239922,
6    "vc": {
7      "credentialSubject": {
8        "name": "Emma Jane Tasma",
9        "code": "HS.278",
10        "certificationName": "Working at Heights",
11        "certificationLevel": "Level 4",
12        "issuerName": "Advanced Safety Training",
13        "expiry": "2026-01-01"
14      }
15    }
16  },
17  "revocable": true
18}

A separate option can be provided to specify if the credential should be revocable. If this Boolean (true/false) value is not provided, it is set to false by default. Learn more about how to revoke a credential here.

Response 

json
Copy to clipboard.
1{
2  "id": "urn:uuid:2e2fd5a2-f6cb-4793-bd70-69acaa08723b",
3  "decoded": {
4    "iss": "did:web:example.nz",
5    "exp": 2516239922,
6    "nbf": 1516239022,
7    "jti": "urn:uuid:2e2fd5a2-f6cb-4793-bd70-69acaa08723b",
8    "vc": {
9      "@context": [
10        "https://www.w3.org/2018/credentials/v1"
11      ],
12      "type": [
13        "VerifiableCredential"
14      ],
15      "credentialSubject": {
16        "name": "Emma Jane Tasma",
17        "code": "HS.278",
18        "certificationName": "Working at Heights",
19        "certificationLevel": "Level 4",
20        "issuerName": "Advanced Safety Training",
21        "expiry": "2026-01-01"
22      }
23    },
24    "status": {
25      "index": 69,
26      "url": "https://YOUR_TENANT_SUBDOMAIN.vii.mattr.global/core/v2/credentials/compact-semantic/revocation-lists/eea87efd-1fc1-4cc3-85c0-2fd490cf54a6"
27    }
28  },
29  "encoded": "CSS:/1/2KCE3IQEJB5DCMSMGZDHUUYBE2QFSAPOU4AXQNDENFSDU53FMI5G2YLUORZC2ZDJMR3WKYRNORSXG5BONZSXI3DJMZ4S4YLQOA5EIRKWHJWG6YLEORSXG5DFOICBVFP2YYZAKGS2L74K4Y3KORU7OB6YIBIC4L6VUL3MWR4TXVYGTLFKBBZDWYTWMORWQQDDN5XHIZLYOSAXQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYWI5DZOBSYC5CWMVZGSZTJMFRGYZKDOJSWIZLOORUWC3DRMNZGKZDFNZ2GSYLMKN2WE2TFMN2KMZDOMFWWK32FNVWWCICKMFXGKICUMFZW2YLEMNXWIZLGJBJS4MRXHBYWGZLSORUWM2LDMF2GS33OJZQW2ZLSK5XXE23JNZTSAYLUEBEGK2LHNB2HG4TDMVZHI2LGNFRWC5DJN5XEYZLWMVWGOTDFOZSWYIBUNJUXG43VMVZE4YLNMV4BQQLEOZQW4Y3FMQQFGYLGMV2HSICUOJQWS3TJNZTWMZLYOBUXE6LKGIYDENRNGAYS2MBRHIAACAAAUIBBQRIDPCEWQ5DUOBZTULZPNRXWCZBNORSXG5DJNZTS44DMMF2GM33SNUXGIZLWFZWWC5DUOJWGCYTTFZUW6L3DN5ZGKL3WGIXWG4TFMRSW45DJMFWHGL3DN5WXAYLDOQWXGZLNMFXHI2LDF5ZGK5TPMNQXI2LPNYWWY2LTORZS6ZLFME4DOZLGMQWTCZTDGEWTIY3DGMWTQNLDGAWTEZTEGQ4TAY3GGU2GCNSYIDOEQ7VGMYLTMHDQ662S44UAKVWTCCS5NI5GJAAOT2LSMVKLZP2MIK6UA5F5UWUIN4XYDCKIEDVEAXLCRQ2TCBRKP5ZQYW3W3W3DB4WJ"
30}

 

The returned payload will contain: 

  • An id to represent the credential, this is required when revoking a credential via the MATTR VII API. 

  • A base32 encoded credential. The encoded string representation of a Compact Credential is CSS:/1/[base32-encoded-cwt] where CSS stands for COSE_SIGN Semantic profile. 

  • The decoded version of the credential that contains the resulting vc and associated claims.

  • status object that provides the URL and index for where the credentials revocation status, if applied, is represented.