Basic Implementation of W3C Verifiable Credential specification

Thusitha Dayaratne
1 min readMay 30, 2023

--

I’ve recently implemented the basics of the W3C verifiable credential specification

A verifiable credential (VC) consists of 3 components

  1. Metadata
  2. Claim(s)
  3. Proof(s)

In my implementation CredentialMetaData, CredentialSubject and Proof classes/interface represent the above component as follows

  • Metadata - CredentialMetaData.java
  • Claims — Credential.java
  • Proofs — Proof.java

To create a VC, first we need to create one or more CredentialSubject objects and add required claims to that as follows

Then use that object to construct a Credential object

Next we can generate the metadata that describes the issuer, issued date, VC id, VC type, expiry and other information as below

Once we have the Credential and metadata, we can generate a proof for them. The VC specification doesn’t mandate any particular proof mechanism. It listed a couple of proof mechanisms. I’ve implemented the Ed25519Signature2020 based proof.

To generate the proof, first we need to create/possess a Ed25519 key pair. Here I’ve used the Mnemonic class from Algorand SDK to generate a deterministic key.

We can use the generated key along with the credential and metadata to generate the Ed25519Signature2020 proof as follows

We combined the constructed 3 components to form a VC as follows

The JSON representation of the constructed VC can be observed using the VCUtil class

The following snippet shows a JSON representation of a sample VC

The complete code can be found on https://github.com/thusithathilina/VerifiableCredentials/blob/master/src/main/java/org/ttd/vc/Main.java

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response