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¶
options
-VcOptions
: options for Vc constructor.accountStore
-AccountStore
:AccountStore
instanceactiveAccount
-string
: ID of the active accountcontractLoader
-ContractLoader
:ContractLoader
instancedfs
-DfsInterface
:DfsInterface
instancedid
-Did
:Did
instance for resolving and validatingexecutor
-Executor
:Executor
instancenameResolver
-NameResolver
:NameResolver
instancesignerIdentity
-SignerIdentity
:SignerIdentity
instanceverifications
-Verifications
:Verifications
instanceweb3
-Web3
:Web3
instancelog
-Function
(optional): function to use for logging:(message, level) => {...}
logLevel
-LogLevel
(optional): messages with this level will be logged withlog
logLog
-LogLogInterface
(optional): container for collecting log messageslogLogLevel
-LogLevel
(optional): messages with this level will be pushed tologLog
config
-VcConfig
: custom configuration for Vc constructor.credentialStatusEndpoint
-string
: URL of the credential status endpoint
Returns¶
Vc
instance
Example¶
const vc = new Vc(
{
accountStore,
activeIdentity
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¶
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¶
vcId
-string
: ID to fetch VC document for. Can be either a full VC URI (starting withvc:evan:
) or just the VC ID (starting with0x
)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¶
vcData
- DocumentTemplate: Collection of mandatory and optional VC properties to store in the VC documentencryptionInfo
- 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¶
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¶
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
key
-string
: the encryption key required for encrypting and decrypting the VC
DocumentTemplate¶
Template for the VC document containing the relevant data
id
-string
: the id of the VCtype
-string
: set of unordered URIsissuer
- VcIssuer: VC issuer detailsvalidFrom
-string
: date from which the VC is validvalidUntil
-string
(optional): date until which the VC is validcredentialSubject
- VcCredentialSubject: subject details of VCcredentialStatus
- VcCredentialStatus (optional): details regarding the status of VCproof
- VcProof (optional): proof of the respective VC
VcIssuer¶
Template for the VC Issuer containing the relevant data
id
-string
: the id of the issuername
-string
(optional): name of the issuer
VcCredentialSubject¶
Template for the VC credential subject containing the relevant data
id
-string
: the id of the subjectdata
-VcCredentialSubjectPayload
(optional): data payload for subjectdescription
-string
(optional): description about subjecturi
-string
(optional): uri of subject
VcCredentialStatus¶
Template for the VC credential status containing the status data
id
-string
: the id of the VCtype
-string
: VC status type
VcProof¶
proof for VC, contains JWS and metadata
type
-string
: VC status typecreated
-string
: date when the proof was createdproofPurpose
-string
: purpose of the proofverificationmethod
-string
: method used for verificationjws
-string
: JSON Web Signature