Create a Compact Credential

Introduction

This guide will demonstrate how to create a Compact Credential using MATTR VII, these credentials use a flat data structure for compactness, and the credential is then signed using a P-256 signing key that is attached to a DID Web.

If you want a more open data model then look at the tutorial for issuing a Semantic Compact Credential.

Prerequisites

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

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 multiple key types.

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  }
6}

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/sign
json
Copy to clipboard.
1{
2    "payload": {
3        "iss": "did:web:learn.vii.au01.mattr.global",
4        "nbf": 1516239022,
5        "exp": 2516239922,
6        "name": "Emma Jane Tasma",
7        "type": "Course Credential",
8        "code": "HS.278",
9        "certificationName": "Working at Heights",
10        "certificationLevel": "Level 4",
11        "issuerName": "Advanced Safety Training",
12        "expiry": "2026-01-01"
13    },
14    "revocable": true
15}

type is an optional attribute that describes the Compact Credential type. The value must be a string which will be displayed on the issued Compact Credential card in the wallet.

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": "mHy6mksIT3y6e4uV0NDfZQ",
3    "decoded": {
4        "iss": "did:web:learn.vii.au01.mattr.global",
5        "nbf": 1516239022,
6        "type": "Course Credential",
7        "exp": 2516239922,
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        "status": {
15            "index": 0,
16            "url": "https://learn.vii.au01.mattr.global/core/v2/credentials/compact/revocation-lists/887cd140-e4d7-4518-b70f-305b23778848"
17        },
18        "jti": "mHy6mksIT3y6e4uV0NDfZQ"
19    },
20    "encoded": "CSC:/1/2KCE3IQEJB5DCMSMGZITM5QBE2QFSALWVQAXQI3ENFSDU53FMI5GYZLBOJXC45TJNEXGC5JQGEXG2YLUORZC4Z3MN5RGC3AFDJNF76FOHIAACAACOFBW65LSONSSAQ3SMVSGK3TUNFQWYBA2SX5MMMTENZQW2ZLPIVWW2YJAJJQW4ZJAKRQXG3LBMRRW6ZDFMZEFGLRSG44HCY3FOJ2GSZTJMNQXI2LPNZHGC3LFOJLW64TLNFXGOIDBOQQEQZLJM5UHI43SMNSXE5DJMZUWGYLUNFXW4TDFOZSWYZ2MMV3GK3BAGRVGS43TOVSXETTBNVSXQGCBMR3GC3TDMVSCAU3BMZSXI6JAKRZGC2LONFXGOZTFPBYGS4TZNIZDAMRWFUYDCLJQGE5AAAIAACRAEAADPB2WQ5DUOBZTULZPNRSWC4TOFZ3GS2JOMF2TAMJONVQXI5DSFZTWY33CMFWC6Y3POJSS65RSF5RXEZLEMVXHI2LBNRZS6Y3PNVYGCY3UF5ZGK5TPMNQXI2LPNYWWY2LTORZS6OBYG5RWIMJUGAWWKNDEG4WTINJRHAWWENZQMYWTGMBVMIZDGNZXHA4DIOAH3BAFBGD4XKNEWCCPPS5HXC4V2DIN6ZKYIARZG3UKFSBDQEBXFXK4V2CCUHICIHM6FZXXIMIB4X63GYFMYXJPAHHWMVXCE5GHEPWVACJXWCGNCIDBVJLI2HX7B36U3L2WRJD62AYA"
21}

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 CSC:/1/[base32-encoded-cwt]where CSC stands for COSE_SIGN Compact profile. 

  • The decoded version of the credential will contain a status object that provides the URL and index for where the credentials revocation status if applied, is represented. 

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