Create a basic JSON-LD credential
Introduction
This guide will demonstrate how to create a verifiable credential using VII Core.
Prerequisites
You need access to the MATTR VII APIs. If you’re experiencing any difficulties, contact us.
In order to create a credential, you will need the following information:
Issuer DID
Subject DID
Credential type
JSON-LD claim names as defined by schema.org
Claim values
If you wish to use our experimental ZKP feature see the tutorial on issuing a ZKP-enabled credential.
You can only create Web Credentials using DIDs created using a
ed25519
orbls12381g2
keyType,
not DIDs with akeyType
ofP-256
Credential provider works with a single DID model, where it would take the default did for any credential issuance. Issuer cannot use different DIDs to issue different credentials.
Create a credential
Create a credential by making an API request as follows (replacing the issuer and subject IDs in the below example with DIDs from your tenant) :
Request
1POST https://YOUR_TENANT_URL/v2/credentials/web-semantic/sign
1{
2 "payload": {
3 "@context": [
4 "https://schema.org"
5 ],
6 "name": "Course credential",
7 "description": "Course credential description",
8 "type": [
9 "CourseCredential"
10 ],
11 "credentialSubject": {
12 "id": "did:key:z6MkfxQU7dy8eKxyHpG267FV23agZQu9zmokd8BprepfHALi",
13 "givenName": "Chris",
14 "familyName": "Shin",
15 "educationalCredentialAwarded": "Certificate Name"
16
17 },
18 "issuer": {
19 "id": " did:web:organization.com ",
20 "name": "tenant"
21 },
22 "expirationDate": "2024-02-07T06:44:28.952Z"
23 },
24 "tag": "identifier123",
25 "persist": false,
26 "revocable": false,
27}
28
The issuer.id
contains the DID of the issuer, this issuer attests the claims in the credential.
The @context
must include use a common data vocab https://schema.org which is referenced in the claims field.
The credentialSubject.Id
specifies an identifier bound to the credential. This is usually a decentralised identifier (DID) that's owned by the credential holder.
type
is an array of credential types. It indicates what sort of information a credential holds. This is a unique identifier that the system uses to differentiate between different types of Web Credentials. There MUST be a value of type other than VerifiableCredential in the payload.
expirationDate
field indicates the expiration date of the credential.
Response
1{
2 "id": "c6667bb7-9442-49a5-bb0b-fce269e97fc6",
3 "tag": "identifier123",
4 "credential": {
5 "@context": [
6 "https://www.w3.org/2018/credentials/v1",
7 "https://mattr.global/contexts/vc-extensions/v2",
8 "https://schema.org"
9 ],
10 "type": [
11 "VerifiableCredential",
12 "CourseCredential"
13 ],
14 "issuer": {
15 "id": "did:web:organization.com",
16 "name": "tenant"
17 },
18 "name": "Course credential",
19 "description": "Course credential description",
20 "issuanceDate": "2021-07-26T01:05:05.152Z",
21 "expirationDate": "2024-02-07T06:44:28.952Z",
22 "credentialSubject": {
23 "id": "did:key:z6MkfxQU7dy8eKxyHpG267FV23agZQu9zmokd8BprepfHALi",
24 "givenName": "Chris",
25 "familyName": "Shin",
26 "educationalCredentialAwarded": "Certificate Name"
27 },
28 "proof": {
29 "type": "Ed25519Signature2018",
30 "created": "2021-07-26T01:05:06Z",
31 "jws": "eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..o6hnrrWpArG8LQz2Ex_u66_BtuPdp3Hkz18nhNdNhJ7J1k_2lmCCwsNdmo-kNFirZdSIMzqO-V3wEjMDphVEAA",
32 "proofPurpose": "assertionMethod",
33 "verificationMethod": "did:key:z6MkndAHigYrXNpape7jgaC7jHiWwxzB3chuKUGXJg2b5RSj#z6MkndAHigYrXNpape7jgaC7jHiWwxzB3chuKUGXJg2b5RSj"
34 }
35 },
36 "issuanceDate": "2021-07-26T01:05:05.152Z"
37}
38
The returned credential object is the credential, with id and issuanceDate shown as meta-data.
https://www.w3.org/2018/credentials/v1 and https://mattr.global/contexts/vc-extensions/v2
which is the reference to the W3C credential definition is auto-injected as the first element in the context array.
VerifiableCredential
is also auto-injected as the first element in the type array. Every W3C verifiable credential must include VerifiableCredential
in the type
property.
If you wish to create a credential that supports revocation, please see the maintain a revocation list tutorial.
To hold an issued credential in a registry, please see the use a credential registry tutorial.