Request a Verifiable Credential (VC) for an Employment Card
Request a verifiable credential for an employment card using the BlockID SDK. Following the W3C Verifiable Credentials Data Model, developers can request credentials from BlockID with 1Kosmos as the Issuer and the employment card data as the Identifier and Credential Subject.
1Kosmos provides the employment card data as a digital credential and cryptographically signs it with its private key.
Prerequisites
Users will need to define the employment card document using the information on their issued employment card. For this example, the employment card should include the following information:
id
: Employment card ID numbnerfirstName
: Employee first namelastName
: Employee last namecompanyName
: Company namecompanyAddress
: Company addressdepartment
: Department employee workstitle
: Employee job titledoe
: Expiration date of employment card, inyyyymmdd
format
Request a Verifiable Credential (VC) for an Employment Card
Parameters
dns
: tenant domain as shown in the dashboardcommunityName
: tenant community as shown in the dashboardlicenseKey
: tenant license key as shown in the dashboardtype
: set asemployment_card
info
: employment card informationuserDid
: user DIDuserPublickey
: User Public keyuserUrn
: user URN
The code includes a function to generate new userDid
, userPublickey
and userUrn
parameters - developers can set these parameters to their own userDid
, userPublickey
and userUrn
values if desired.
Request Format
All requests are plug-and-play, not copy-paste. Please ensure that you are replacing the parameters in the request format below with the actual values
Please use the following format outlined below to request a Verifiable Credential for your Employment Card:
- NodeJS
- Java
- PHP
- Add dependencies and set tenant info
const BIDTenant = require("blockid-nodejs-helpers/BIDTenant.js");
const BIDVerifiableCredential = require("blockid-nodejs-helpers/BIDVerifiableCredential.js");
const { v4: uuidv4 } = require("uuid");
const tenantInfo = {
dns: "<tenant dns>",
communityName: "<community name>",
licenseKey: "<user license key>",
};
- Define employment card information
let info = {
"id": <employment card ID>,
"firstName": <first name>,
"lastName": <last name>,
"companyName": <company name>,
"companyAddress": <company address>,
"department": <department (optional)>,
"title": <job title>,
"doe": "<employment card expiration date>" // yyytmmdd format
}
- Request VC for employment card
async function requestVCForPayload(info) {
// Fetch user public key and private key
const keySet = BIDTenant.getKeySet();
let type = "employment_card";
let userDid = uuidv4();
let userPublickey = keySet.pKey;
let userUrn = `urn:${uuidv4()}`;
let issuer = {
id: `did:${uuidv4()}`,
};
let issuedVerifiableCredential =
await BIDVerifiableCredential.requestVCForPayload(
tenantInfo,
type,
issuer,
info,
userDid,
userPublickey,
userUrn
);
console.log(
"issuedVerifiableCredential:for:::Payload:::::",
JSON.stringify(issuedVerifiableCredential)
);
return issuedVerifiableCredential;
}
requestVCForPayload(info);
- Set tenant info
BIDTenantInfo tenantInfo = new BIDTenantInfo("<tenant dns>", "<community name>", "<license key>");
- Define employment card information
String type = "employment_card";
String userPublickey = "<user public key>";
String userDid = UUID.randomUUID().toString();
String userUrn = "urn:" + UUID.randomUUID().toString();
Map<String, Object> info = new HashMap<>();
info.put("id" , "<employment card ID>");
info.put("firstName" , "<first name>");
info.put("lastName" , "<last name>");
info.put("companyName" , "<company name>");
info.put("companyAddress" , "<company address>");
info.put("department" , "<deparment (optional)");
info.put("title" , "<job title>");
info.put("doe" , "<employment card expiration date>);
Map<String, Object> issuer = new HashMap<>();
issuer.put("id", "did:" + UUID.randomUUID().toString());
- Request VC for employment card
BIDPayloadVCResponse issuedVerifiableCredential = BIDVerifiableCredential.requestVCForPayload(tenantInfo, type, issuer, info, userDid, userPublickey, userUrn);
- Add dependencies and set tenant info
<?php
require_once("./BIDTenant.php");
require_once("./BIDVerifiableCredential.php");
$bidTenant = BIDTenant::getInstance();
$tenantInfo = array("dns" => "<tenant dns>", "communityName" => "<community>", "licenseKey" => "<license key>");
$keys = $bidTenant->getKeySet();
- Define VC parameters
$type = "employment_card";
$userDid = uniqid();
$userPublickey = $keys["publicKey"];
$userUrn = "urn:" . uniqid();
$issuer = array(
"id" => "did:" . uniqid()
);
- Define employment card information
$type = "employment_card";
$userDid = uniqid();
$userPublickey = $keys["publicKey"];
$userUrn = "urn:" . uniqid();
$issuer = array(
"id" => "did:" . uniqid()
);
$info = array(
"id" => "<employment card ID number>",
"firstName" => "<first name>",
"lastName" => "<last name>",
"companyName" => "<company name>",
"companyAddress" => "<company address>",
"department" => "<department (optional)>",
"title" => "<job title (optional)>",
"doe" => "<date of employment card expiration>"
);
- Request VC for employment card
$payloadVCResponse = BIDVerifiableCredential::requestVCForPayload($tenantInfo, $type, $issuer, $info, $userDid, $userPublickey, $userUrn);
?>
Example Request
We've provided a complete example request below for reference:
Dummy information is provided in this example
- NodeJS
- Java
- PHP
const BIDVerifiableCredential = require("blockid-nodejs-helpers/BIDVerifiableCredential.js");
let tenantInfo = {
dns: "blockid-trial.1kosmos.net",
communityName: "devx",
licenseKey: "9b074532-845b-4c75-ba3e-2b8950000000",
};
let info = {
id: "E1002",
firstName: "John",
lastName: "Doe",
companyName: "ACME",
companyAddress: "123 Street",
department: "Engineering",
title: "Senior Developer",
doe: "20240520", // yyyymmdd format
};
async function requestVCForPayload(info) {
// Fetch user public key and private key
const keySet = BIDTenant.getKeySet();
let type = "employment_card";
let userPublickey = keys.pKey;
let userDid = uuidv4();
let userUrn = `urn:${uuidv4()}`;
let issuer = {
id: `did:${uuidv4()}`,
};
let issuedVerifiableCredential =
await BIDVerifiableCredential.requestVCForPayload(
tenantInfo,
type,
issuer,
info,
userDid,
userPublickey,
userUrn
);
console.log(
"issuedVerifiableCredential:for:::Payload:::::",
JSON.stringify(issuedVerifiableCredential)
);
return issuedVerifiableCredential;
}
requestVCForPayload(info);
BIDTenantInfo tenantInfo = new BIDTenantInfo("blockid-trial.1kosmos.net", "devx", "9b074532-845b-4c75-ba3e-2b89598a0000");
String type = "employment_card";
String userPublickey = "zGNlDjMb6XV7xLRZR6XF2XRdUd8eUN3ggn21ejyP5qbn6/q3LnXTBQZA2/4Y63y9/JbSGEsMVkyVH2/hW4YAVQ==";
String userDid = UUID.randomUUID().toString();
String userUrn = "urn:" + UUID.randomUUID().toString();
BIDEmploymentInfoData info = new BIDEmploymentInfoData();
info.id = "E1002";
info.firstName = "John";
info.lastName = "Doe";
info.companyName = "ACME";
info.companyAddress = "123 Street";
info.department = "Engineering";
info.title = "Senior Developer";
info.doe = "20240520";
BIDIssuerData issuer = new BIDIssuerData();
issuer.id = "did:" + UUID.randomUUID().toString();
BIDPayloadVCResponse issuedVerifiableCredential = BIDVerifiableCredential.requestVCForPayload(tenantInfo, type, issuer, info, userDid, userPublickey, userUrn);
<?php
require_once("./BIDTenant.php");
require_once("./BIDVerifiableCredential.php");
$bidTenant = BIDTenant::getInstance();
$tenantInfo = array("dns" => "blockid-trial.1kosmos.net", "communityName" => "devx", "licenseKey" => "9b074532-845b-4c75-ba3e-2b8950000000");
$keys = $bidTenant->getKeySet();
$type = "employment_card";
$userDid = uniqid();
$userPublickey = $keys["publicKey"];
$userUrn = "urn:" . uniqid();
$issuer = array(
"id" => "did:" . uniqid()
);
$info = array(
"id" => "E1002",
"firstName" => "John",
"lastName" => "Doe",
"companyName" => "ACME",
"companyAddress" => "123 Street",
"department" => "Engineering",
"title" => "Senior Developer",
"doe" => "20270620"
);
$payloadVCResponse = BIDVerifiableCredential::requestVCForPayload($tenantInfo, $type, $issuer, $info, $userDid, $userPublickey, $userUrn);
?>
Server Responses
Please review the responses below for expected output after requesting a VC verification. A successful request will include a cryptographically signed credential.
Responses include dummy data as an example of a typical response
- 200
- 400
- 401
{
"vc": {
"@context": [
"https://www.w3.org/2018/credentials/v1",
{
"EmploymentCredential": "https://schema.org#EmploymentCredential",
"firstName": "https://schema.org#firstName",
"lastName": "https://schema.org#lastName",
"companyName": "https://schema.org#companyName",
"companyAddress": "https://schema.org#companyAddress",
"department": "https://schema.org#department",
"title": "https://schema.org#title",
"doe": "https://schema.org#doe",
"employeeId": "https://schema.org#employeeId",
"publicKey": "https://schema.org#publicKey"
},
"https://w3id.org/security/suites/ed25519-2020/v1"
],
"id": "did:blockid:d69a77a0-e379-40e0-a631-b9947d15fe6a",
"type": [
"VerifiableCredential",
"EmploymentCredential"
],
"issuer": {
"id": "did:84402113-c234-4426-b92f-a84bd8884451",
},
"issuanceDate": "2022-12-14T05:23:01.698Z",
"expirationDate": "2024-05-20T00:00:00.000Z",
"credentialSubject": {
"id": "did:e453247f-3dac-4474-bc20-3e02fd2ca5c7",
"firstName": "John",
"lastName": "Doe",
"companyName": "ACME",
"companyAddress": "123 Street",
"department": "Engineering",
"title": "Senior Developer",
"doe": "20240520",
"employeeId": "E1002",
"publicKey": "zGNlDjMb6XV7xLRZR6XF2XRdUd8eUN3ggn21ejyP5qbn6/q3LnXTBQZA2/4Y63y9/JbSGEsMVkyVH2/hW4YAVQ=="
},
"proof": {
"type": "Ed25519Signature2020",
"created": "2022-12-14T05:23:01Z",
"verificationMethod": "did:key:blockid:z6MkvFNv22WzDetLgdzYidCFQJosD5Z9pDr9cmX7RtREuoji",
"proofPurpose": "assertionMethod",
"proofValue": "zR6cCfrJczc9ALp91dWy2QRFJKf7m1b6HAadUrjK43fiTF63Y1iZYa1mNwBhNBGH3C42mfzhH1NP1t3dQ4Z3QgMJ"
},
"statusUrl": "https://blockid-trial.1kosmos.net/vcs/tenant/63627082d0b7e36525e281aa/community/63627302d0b7e36525e2828d/vc/did:blockid:d69a77a0-e379-40e0-a631-b9947d15fe6a/status"
},
"vcId": "did:blockid:d69a77a0-e379-40e0-a631-b9947d15fe6a",
"download_url": "https://blockid-trial.1kosmos.net/vcs/vc/did:blockid:d69a77a0-e379-40e0-a631-b9947d15fe6a/download"
}
{
"error_code": 400,
"message":"Invalid Request"
}
{
"error_code": 401,
"message":"Unauthorized"
}