Advanced VC
Onboarding Emma to a Virtual Company, issuing custom credentials, and utilizing dynamic verification policies.
In this tutorial, we will expand on the "My First VC" tutorial by now onboarding Emma to a virtual company. During the onboarding, Emma will receive an EmployeeID credential, which will be based on a custom credential template using the status property. With that, you learn about two more concepts; Custom credential templates and the status property. The credential will also have Emma's role as a property, which can then be checked with a dynamic verification policy, another new concept.
Where we start:
Using the walt.id SSI-Kit's REST API, we'll streamline access control within the company by
Establishing a Digital Identity (DID): The company will be set up as the issuer through its own Digital Identity (DID).
Creating an EmployeeID Template: This template will be used for generating verifiable credentials for employees.
Issuing a Verifiable Credential to Emma: Emma, an employee, will be issued a Verifiable Credential, making her the holder.
Authenticating with Door Access System: The system, acting as the Verifier, will:
Confirm Emma's employment status
Assess her role within the company
Grant or deny access to specific areas on the company campus based on the above.
Running the SSI-Kit
Make sure you have Docker or a JDK 16 build environment including Gradle installed on your machine
Pull the docker container directly from docker hub and run the project
This will create a folder called data in your current directory as storage for the VC, DIDs, Keys and other things which need to be stored in order to provide all the functionality.
Now with the SSI-Kit up and running, we can create the DID for the company, establishing its Digital Identity.
Establishing a Digital Identity (DID)
You have two options for creating a DID: executing a curl command or visiting the swagger docs. The custodian endpoint should be visible in the terminal after you have run the serve command, visit the endpoint to see the swagger docs.
Body Parameters
method
: [string] method of the did. Value can be one of key
, web
, ebsi
, iota
, cheqd
, jwk
Example
Create one DID for the company using the command above. In case you don't have done the My First VC tutorial and still have the DID for Emma, create another one for her. Make sure to save both, as we will be needing them later for the issuance of the EmployeID. You can also use the list DID endpoint to see all previously created DIDs.
Creating an EmployeeID Template
The SSI-Kit supports the creation of credential templates, which are blueprints that establish reusable data structures based on which credentials can be issued.
Let's create one for an EmployeeID. The template will include the following properties:
id
: Identifier for the employeename
: Name of the employeerole
: Role or designation in the companyjoiningDate
: Date of joining the company
Saving the credential template
Path Parameters
id
: The name for the credential template, which we will later reference during issuance. e.g. EmployeeID
Body Use the JSON structure from above as the body. Example
We can streamline the process of issuing a credential to Emma by utilizing the EmployeeID credential template. However, we also have the opportunity to further simplify the process using an additional feature: prefilling credential properties. This will be particularly beneficial as Emma likely won't be the only one receiving the Engineer role assignment. By creating a template where the Engineer role is prefilled, we can improve the issuance process.
EngineerEmployeeID Template
You can now also save this template and use it later for the issuance of our VC, or use the one we created before and provide the value for the role attribute during issuance.
Issuing a Verifiable Credential to Emma
In order to issue Emma's EmployeeID VC, we will use one of the credential templates. Additionally, we will include a credential status so that we have the option to revoke the credential if Emma leaves the company without needing to remove it from her ownership. For more information on credential status and the types we support, read our guide.
Body Parameters
templateId
: [string] The identifier of the template used for issuing a Verifiable Credential. In our case this would be the EmployeeID or EngineerEmployeeID template.config
: [object] Contains configuration parameters for the issuance process.issuerDid
: [string] The DID of the entity issuing the credential (University).subjectDid
: [string] The DID of the entity receiving the credential (Emma).proofType
: [string] Specifies the format and cryptographic algorithm used for the digital signature of the Verifiable Credential. E.g. LD_PROOFstatusType
: [statusType] Specifies if the credential should be issued with status and the type of the status. OptionsStatusList2021Entry
orSimpleCredentialStatus2022
credentialData
: [object] Contains the actual data of the credential being issued.credentialSubject
: [object] Holds the information about the employee as described in the EmployeeID credential template.
The id
in the credential subject we don't need to provide as this will be prefilled automatically with the DID of Emma.
Example EmployeeID:
Example EngineerEmployeeID:
Now we can use the issued VC in the company campus verification system.
Authenticating with Door Access System
To successfully authorize access, our authentication system needs to verify four crucial elements regarding the Verifiable Credential presented during the verification process:
Confirm the signature of the Verifiable Credential to ensure it's legitimate.
Ascertain the credential's validity by validating its current status, ensuring it has not expired or been revoked.
Verify that the issuer is indeed our company, thereby eliminating any fraudulent issuers.
Evaluate whether the role of the employee, as indicated on the credential, authorizes them to access the desired area.
To facilitate successful verification, we will use Verification Policies. For the initial two cases, which are relatively common, we can utilize our built-in policies, namely SignaturePolicy
and CredentialStatusPolicy
. These policies essentially verify that the signature is authentic and that the status is still valid.
For the additional cases, we will create custom policies, leveraging the Open Policy Agent (OPA) Engine and the REGO language. You can learn more about it here.
Please install the Open Policy Agent as described here, to ensure seamless verification.
Creating Custom Policies - IsCompany
Make sure to replace {issuerDID} with the DID of your issuer (company)
Creating Custom Policies - IsRole
This custom policy holds greater flexibility, as it accepts an argument containing a 'role' property. This property is then cross-verified with the role present in the Verifiable Credential. Alternatively, the role can be hardcoded, and the policy can be renamed accordingly, such as IsEngineer
, similar to the IsCompany
policy.
Saving the policies
Path parameters:
policyName
: [string] Name of the policy, e.g. IsCompany
Query parameters:
update
: [boolean] Specifies if existing policy with same name should be overridden (if mutable)downloadPolicy
: [boolean] When using an URL to reference the to created policy. Downloads and/or saves the policy definition locally, rather than keeping the reference to the original URL\
Body
name
: [string] Policy name, must not conflict with existing policiesdescription
: [string] Optional policy descriptioninput
: [JSON] Input JSON object for rego query, which can be overridden/extended on verification. Can be a JSON string or JSON filepolicy
: [URL, REGO] Whole Policy or URL to policy definition.dataPath
: [JSON path] JSON path to the data in the credential which should be verified, default: "$" (whole credential object)policyQuery
: [string] The query string in the policy engine language. Defaults to "data.system.main".policyEngine
: [string] Policy engine type, default: OPA. Options, OPAapplyToVC
: [boolean] Apply/Don't apply to verifiable credentials (default: apply)applyToVP
: [boolean] Apply/Don't apply to verifiable presentation (default: don't apply)
Using the endpoint above, you can save both policies.
Verifying the credential with all policies
Now with the custom policies created, we will use those and the two predefined ones to verify Emma's credential and enable access.
Body
policies
: [array] A list of policy definitions to verify againstpolicy
: [string] The name/id of the policyargument
: [JSON] The argument needed by the policy (optional)
credentials
: [array] An array of credentials in JWT, or LD_PROOF format
Congratulations, you've reached the finish line! 🎉 You have skillfully utilized an array of features to bring this use case to life. Now, you have the opportunity to explore further and deepen your understanding of the concepts introduced today. Happy building!
Next Steps
Credential Templates - Dive deeper into credential templates and what you can do with them
Credential Status - Learn more about the credential status property and what is enables.
Verification Policies - Explore our pre-build templates and learn more about how to build and leverage custom ones using OPA (Open Policy Agent) and the Rego language.
Last updated