Basic Implementation of W3C Verifiable Credential specification
I’ve recently implemented the basics of the W3C verifiable credential specification
A verifiable credential (VC) consists of 3 components
- Metadata
- Claim(s)
- 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