Skip to main content

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 numbner
  • firstName: Employee first name
  • lastName: Employee last name
  • companyName: Company name
  • companyAddress: Company address
  • department: Department employee works
  • title: Employee job title
  • doe: Expiration date of employment card, in yyyymmdd format

Request a Verifiable Credential (VC) for an Employment Card

Parameters

  • dns: tenant domain as shown in the dashboard
  • communityName: tenant community as shown in the dashboard
  • licenseKey: tenant license key as shown in the dashboard
  • type: set as employment_card
  • info: employment card information
  • userDid: user DID
  • userPublickey: User Public key
  • userUrn: user URN
tip

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

tip

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:

  • 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);

Example Request

We've provided a complete example request below for reference:

tip

Dummy information is provided in this example

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);

Server Responses

Please review the responses below for expected output after requesting a VC verification. A successful request will include a cryptographically signed credential.

tip

Responses include dummy data as an example of a typical response

200 OK
{
"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"
}