The @verida/verifiable-credential package contains all the necessary capabilities to issue, verify and share Verifiable Credentials on the Verida Network.
A credential is issued by creating a JSON object (credentialData) containing data matching the schema of the credential to be created. This credentialData object is then passed to credentialSDK.createCredentialJWT() which populates a didJwtVc attribute containing a signed, verified DID JWT Verifiable Credential.
import Credentials from"@verida/verifiable-credentials";// Note: `context` should already be obtained by connecting to the Verida NetworkconstcredentialSDK=newCredentials();// The Verida DID that is the subject of this credential (who is being verified with this credential?)constsubjectDid='did:vda:polyamoy:0x....';constcredentialSchema='https://common.schemas.verida.io/identity/kyc/FinClusive/individual-basic/latest/schema.json'// Data for the credential that matches the credential schemaconstcredentialData= {"finClusiveId":"12345","gender":"male","firstName":"Chris","lastName":"Tester","streetAddress1":"123 Four Ave","suburb":"Adelaide","state":"SA","postcode":"5000","dateOfBirth":"2000-01-01"}consttitle='KYC Credential'constsummary='Credential issued by <signer> on <date>'constoptions= {}constcredentialRecord=awaitcredentials.createVerifiableCredentialRecord({ context: context asany, data: credentialData, subjectId: subjectDid, schema: credentialSchema, options}, title, summary);
It is possible to manually verify the didJwtVc string to extract the verifiable credential object.
import Credentials from"@verida/verifiable-credentials";// Note: `context` should already be obtained by connecting to the Verida NetworkconstcredentialSDK=newCredentials(context);constdecodedCredential=awaitcredential.verifyCredential(jwt.didJwtVc)
There is a specific process to "present" a credential, which wraps the verifiable credential data within a presentation object. The standard allows a credential holder to present multiple credentials at once.
// Note: `context` should already be obtained by connecting to the Verida NetworkconstcredentialSDK=newCredentials(context);// Create a presentation with one or more `didJwtVc` stringsconstvcPresentation=credentialSDK.createVerifiablePresentation([credential.didJwtVc])
The SharingCredential library takes a private credential object and makes it available via a public Verida URI for any third party to access. In order to protect privacy, the credential is encrypted so any third party must be supplied the encryption key in order to access the credential.
import { SharingCredential } from"@verida/verifiable-credentials";// `credential` is a credential previously created with credentialSDK.createCredentialJWT()constshareData=awaitshareCredential.issueEncryptedPresentation(credential);
Returned shareData object:
{// Encrypted credential that is stored in the public credential database located at `verida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X2zHoGEUoD3ePCmVZSvsT2CQ3DzOGq4e1XyCi3WZUrkscs/RZbx1CUp1CGe093R4DA27KnB/TPCwPEWu/nOJyo9XdkmM18pizes2InYKARTuR0ZAmNq3lBBlQox0sV+ZHoqQb2PG6EBjUKzO6jK602fGw8bNBYRSaB2R+q3X49VzbJ3JShPXL5YUJDZyM52fp+q5XvP2V8Y9EH5mPgmFa93ALg1JaN8tXaZvisy32iYu75EjtYJ2g=',
schema:'https://common.schemas.verida.io/credential/public/encrypted/v0.1.0/schema.json' },// The result object returned from the public credential database result: { ok:true, id:'876ec340-9f3c-11ec-a4d8-35d2dca04a1c', rev:'1-b1b26bc16dbac1ee0b1db2afffe7daaa' },// The DID of the Verida Account that is sharing the credential did:'did:vda:polamoy:0xB3729982A2585544FD72c99CF3773a9c6baBD55c',// The Verida URI endpoint pointing to where the encrypted credential is stored// verida://<did>/base64(<contextName>)/<databaseName>/recordId?key=<encryptionKey> veridaUri:'verida://did:vda:polamoy:0xB3729982A2585544FD72c99CF3773a9c6baBD55c/GpNDePvWU4RQud9jaZJiNwFyAS/credential_public_encrypted/876ec340-9f3c-11ec-a4d8-35d2dca04a1c?key=c8fd78a9baa44c8ade5e269e0310dcf1139d0374980110b4802b5db6e0820543',// A public URI that can be opened in a web browser that can decode a base64 encoded veridaUri, fetch the data, decrypt it and display to the viewer publicUri:'https://explorer.verida.network/credential?uri=dmVyaWRhOi8vZGlkOnZkYToweEIzNzI5OTgyQTI1ODU1NDRGRDcyYzk5Q0YzNzczYTljNmJhQkQ1NWMvR3BORGVQdldVNFJRdWQ5amFaSmlOd0Z5QVMvY3JlZGVudGlhbF9wdWJsaWNfZW5jcnlwdGVkLzg3NmVjMzQwLTlmM2MtMTFlYy1hNGQ4LTM1ZDJkY2EwNGExYz9rZXk9YzhmZDc4YTliYWE0NGM4YWRlNWUyNjllMDMxMGRjZjExMzlkMDM3NDk4MDExMGI0ODAyYjVkYjZlMDgyMDU0Mw=='}
publicUri can be shared with anyone who can then open the credential in their web browser.
veridaUri can be shared with other systems to access the underlying credential data.
The credential SDK supports the concept of Blockchain proofs that are certain attributes of a credential that are collectively signed in such a way as they can be quickly and cheaply verified on a blockchain.
For example, it is possible to issue a Verifiable Credential proving someones credit score, but then provide a blockchain proof specifying the value of the credit score. This would allow the credit score to be used in a smart contract (or issued as a Soulbound token) without requiring the full verifiable credential to be parsed on chain (which is very expensive).
Blockchain proofs are defined in the credential schema.
The Verida Wallet will automatically show the public profile icon of the Verida Account that signed the credential. You will need to set this icon for your Verida account so the icon displays correctly.
You could add the signing Verida Account to the Verida Wallet and use the mobile app to set a profile avatar and name. This will then be the default for every inbox message and credential issued across the Verida network. Alternatively, you could manually set the profile information for the application context generating the credential. See Account Profiles for more information on how to achieve this.