VC

Class Name Vc
Extends Logger
Source vc.ts
Tests vc.spec.ts

The Vc module allows to create, store, retrieve and revoke VCs on evan.network. As development of identities, and DID and VC handling on evan.network is an ongoing process, this document describes the current interoperability of VCs on evan.network and can be seen as a work-in-progress state of the current implementation.


constructor

new Vc(options, did);

Creates a new Vc instance.

Parameters

  1. options - VcOptions: options for Vc constructor.
  2. config - VcConfig: custom configuration for Vc constructor.
    • credentialStatusEndpoint - string: URL of the credential status endpoint

Returns

Vc instance

Example

const vc = new Vc(
  {
    accountStore,
    contractLoader,
    dfs,
    did,
    executor,
    nameResolver,
    signerIdentity,
    verifications,
    web3,
  },
  { credentialStatusEndpoint },
);

= Working with VC documents =

createId

Claim a new ID in the VC registry which can be used later to store a VC on-chain.

vc.createId();

Returns

Promise returns string: A new ID string

Example

const newRegisteredId = await runtime.vc.createId();
const myVcDocument = {
  // Data here,
  id: newRegisteredId
};
await runtime.vc.storeVc(myVcDocument);

createVc

Create a signed off-chain VC document

vc.createVc(vcData);

Parameters

  1. vcData - DocumentTemplate: Collection of mandatory and optional VC properties to store in the VC document

Returns

Promise returns VcDocument: The final VC document

Example

const minimalVcData = {
    id: 'randomCustomId',
    issuer: {
      did: 'someDid',
    },
    credentialSubject: {
      did: 'someOtherDid',
    },
    validFrom: new Date(Date.now()).toISOString()
};
const offchainVc = await runtime.vc.createVc(minimalVcData);

getVc

Get VC document for given VC ID.

vc.getVc(vcId, encryptionInfo);

Parameters

  1. vcId - string: ID to fetch VC document for. Can be either a full VC URI (starting with vc:evan:) or just the VC ID (starting with 0x)
  2. encryptionInfo - EncryptionInfo: (optional): Information required for decryption

Returns

Promise returns VcDocument: A VC document

Example

const storedVcDoc = await vc.getVc('0x2a838a6961be98f6a182f375bb9158848ee9760ca97a379939ccdf03fc442a23');
const otherStoredVcDoc = await vc.getVc('vc:evan:testcore:0x2a838a6961be98f6a182f375bb9158848ee9760ca97a379939ccdf03fc442a23');

// using encryption
encryptionInfo = { key: vcKey };
const EncryptedVcDoc = await vc.getVc( 'vc:evan:testcore:0x5f7514378963d3a1211a3b015c51dd9fbd1e52d66a2fbb411fcdf80fdfd7bbd4', encryptionInfo);

storeVc

vc.storeVc(vcData, encryptionInfo);

Create a new VC that holds the given data and store it on the chain. Whether a new ID should be registered with the VC registry or the given ID in the document should be used depends of if vcData.id is set. If set, the method calls createId() to generate a new ID.

Parameters

  1. vcData - DocumentTemplate: Collection of mandatory and optional VC properties to store in the VC document
  2. encryptionInfo - EncryptionInfo: (optional): Information required for encryption

Returns

Promise returns VcDocument: Returns the VC document as stored on the chain.

Example

const minimalVcData = {
    issuer: {
      did: 'someDid',
    },
    credentialSubject: {
      did: 'someOtherDid',
    },
    validFrom: new Date(Date.now()).toISOString()
};
const createdVcDoc = await runtime.vc.storeVc(minimalVcData);
const permanentVcAddress = createdVcDoc.id;
const myRegisteredId = await runtime.vc.createId();
const minimalVcData = {
    issuer: {
      did: 'someDid',
    },
    credentialSubject: {
      did: 'someOtherDid'
    },
    validFrom: new Date(Date.now()).toISOString()
};
minimalVcData.id = myRegisteredId;
const createdVcDoc = await runtime.vc.storeVc(minimalVcData);
const permanentVcAddress = createdVcDoc.id;

revokeVc

vc.revokeVc(vcId);

Sets a revoke status flag for the VC.

Parameters

  1. vcId - string: ID for VC document to be revoked.

Returns

Promise returns void: resolved when done

Example

const storedVcDoc = await vc.getVc(permanentVcAddress);
const vcId = storedVcDoc.id;

const revokeProcessed = await vc.revokeVc(vcId);

getRevokeVcStatus

vc.getRevokeVcStatus(vcId);

Gets the revoke status flag for the VC.

Parameters

  1. vcId - string: ID for VC document whose status needs to be retrieved.

Returns

Promise returns bool: true for revoked, false for not revoked

Example

const storedVcDoc = await vc.getVc(permanentVcAddress);
const vcId = storedVcDoc.id;

const vcRevokeStatus = await vc.getRevokeVcStatus(vcId);

Additional Components

Interfaces

EncryptionInfo

configuration settings required for the encryption and decryption

  1. key-string: the encryption key required for encrypting and decrypting the VC

DocumentTemplate

Template for the VC document containing the relevant data

  1. id-string: the id of the VC
  2. type-string: set of unordered URIs
  3. issuer- VcIssuer: VC issuer details
  4. validFrom-string: date from which the VC is valid
  5. validUntil-string (optional): date until which the VC is valid
  6. credentialSubject- VcCredentialSubject: subject details of VC
  7. credentialStatus- VcCredentialStatus (optional): details regarding the status of VC
  8. proof- VcProof (optional): proof of the respective VC

VcIssuer

Template for the VC Issuer containing the relevant data

  1. id-string: the id of the issuer
  2. name-string (optional): name of the issuer

VcCredentialSubject

Template for the VC credential subject containing the relevant data

  1. id-string: the id of the subject
  2. data-VcCredentialSubjectPayload (optional): data payload for subject
  3. description-string (optional): description about subject
  4. uri-string (optional): uri of subject

VcCredentialStatus

Template for the VC credential status containing the status data

  1. id-string: the id of the VC
  2. type-string: VC status type

VcProof

proof for VC, contains JWS and metadata

  1. type-string: VC status type
  2. created-string: date when the proof was created
  3. proofPurpose-string: purpose of the proof
  4. verificationmethod-string: method used for verification
  5. jws-string: JSON Web Signature