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:
Access to the MATTR VII APIs
A Web DID using a
P-256
keyType ONLY
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
of P-256
in the request payload.
Request
1POST https://YOUR_TENANT_URL/core/v1/dids
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
1POST https://YOUR_TENANT_URL/v2/credentials/compact/sign
1{
2 "payload": {
3 "iss": "did:web:example.nz",
4 "nbf": 1516239022,
5 "exp": 2516239922,
6 "name": "Emma Jane Tasma",
7 "code": "HS.278",
8 "certificationName": "Working at Heights",
9 "certificationLevel": "Level 4",
10 "issuerName": "Advanced Safety Training",
11 "expiry": "2026-01-01"
12 },
13 "revocable": true
14}
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
1{
2 "id": "M2Cbq-3GRgu3aXR9YmMHcA",
3 "decoded": {
4 "iss": "did:web:example.nz",
5 "exp": 2516239922,
6 "nbf": 1516239022,
7 "name": "Emma Jane Tasma",
8 "code": "HS.278",
9 "certificationName": "Working at Heights",
10 "certificationLevel": "Level 4",
11 "issuerName": "Advanced Safety Training",
12 "expiry": "2026-01-01",
13 "status": {
14 "index": 604,
15 "url": "https://YOUR_TENANT_SUBDOMAIN.vii.mattr.global/core/v2/credentials/compact/revocation-lists/c0bcfc20-1514-4899-a451-93bccf9a77a9"
16 },
17 "jti": "M2Cbq-3GRgu3aXR9YmMHcA"
18 },
19 "encoded": "CSC:/1/2KCE3IQEJB5DCMSMGZDHUUYBE2QFSAL5VMAXQNDENFSDU53FMI5G2YLUORZC2ZDJMR3WKYRNORSXG5BONZSXI3DJMZ4S4YLQOA5EIRKWHJWG6YLEORSXG5DFOICBVFP2YYZAKGS2L74K4ZDOMFWWK32FNVWWCICKMFXGKICUMFZW2YLEMNXWIZLGJBJS4MRXHBYWGZLSORUWM2LDMF2GS33OJZQW2ZLSK5XXE23JNZTSAYLUEBEGK2LHNB2HG4TDMVZHI2LGNFRWC5DJN5XEYZLWMVWGOTDFOZSWYIBUNJUXG43VMVZE4YLNMV4BQQLEOZQW4Y3FMQQFGYLGMV2HSICUOJQWS3TJNZTWMZLYOBUXE6LKGIYDENRNGAYS2MBRHIAACAAAUIBBSAS4AN4IA2DUORYHGORPF5WG6YLEFV2GK43UNFXGOLTQNRQXIZTPOJWS4ZDFOYXG2YLUORZGYYLCOMXGS3ZPMNXXEZJPOYZC6Y3SMVSGK3TUNFQWY4ZPMNXW24DBMN2C64TFOZXWGYLUNFXW4LLMNFZXI4ZPMMYGEY3GMMZDALJRGUYTILJUHA4TSLLBGQ2TCLJZGNRGGY3GHFQTON3BHED5QQCQGNQJXK7NYZDAXN3JOR6WEYYHOBMEBAUOXZHFGWFPR4LR6V3KLIFH25CNPBZB5LH2AW42YW3KSNPD2DPBKSWN3CLVMOZOJGUKNCNDSHR6X5RRGRJ562P3HEMXUQK367MBGPYA"
20}
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.