.. and press ENTER to ask a question on web5, how to write code and more.

Skip to main content

Issue a VC

This guide provides a step-by-step process for issuing a verifiable credential (VC), covering everything from installing the SDK to signing the credential.

Prerequisites

Install Packages

JavaScript
Kotlin
Swift
npm install @web5/credentials@1.0.0

Install Classes

JavaScript
Kotlin
Swift
import { VerifiableCredential } from "@web5/credentials";

Obtain DIDs

VCs are issued to and from subjects of Decentralized Identifiers (DID).

  • If you don't already have one, you can create a DID.
  • Also, you'll need the DID of the entity you'll like to issue the VC to.

VC Properties

Credentials are created in JSON format and contain the following properties:

  • type: Type of the credential (e.g. EmploymentCredential, EducationCredential)
  • issuer: DID of the entity who is issuing the credential
  • subject: DID of the entity that the credential is being issued to
  • expirationDate: (optional) The date when the credential expires (in ISO 8601 standard format)
  • data: JSON containing claims that are being asserted

Create VC

To create the VC, utilize the VerifiableCredential.create() method. Pass a JSON object containing the properties as shown below:

JavaScript
Kotlin
Swift

This results in:

JavaScript
Kotlin
Swift

{
"vcDataModel": {
"@context": [
"https://www.w3.org/2018/credentials/v1"
],
"type": [
"VerifiableCredential",
"EmploymentCredential"
],
"id": "urn:uuid:84953246-a77f-4c5a-a336-69a55bd92989",
"issuer": "did:dht:fhzeks5bkferfztk6m63xjkg7a4hbf7snk444g8f1h1xapt391ty",
"issuanceDate": "2023-03-31T06:08:49Z",
"credentialSubject": {
"id": "did:dht:usnoybts46xnei6brftkixe5qsbypxcye4th397bs4tyouqouyho",
"position": "Software Developer",
"startDate": "2023-04-01T12:34:56Z",
"employmentStatus": "Contractor"
},
"expirationDate": "2023-09-30T12:34:56Z"
}
}

Sign VC

The next step is signing the VC. This cryptographic process, performed by the issuer, ensures the integrity and authenticity of the VC:

JavaScript
Kotlin
Swift

Signing the credential returns a VC JWT:

eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsI...

Giving this VC JWT to the holder completes the issuance of the credential.

VC JWTs can be converted back to a JSON object by applications that need to engage with the contents of the credential.

Connect with us on Discord

Submit feedback: Open a GitHub issue

Edit this page: GitHub Repo

Contribute: Contributing Guide