UNPKG

@gleif-it/vlei-verifier-workflows

Version:

Workflows for vLEI users and vLEI credentials for the vLEI-verifier service

97 lines (96 loc) 4.1 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.credAuthorizationStatusMapping = exports.credPresentationStatusMapping = exports.CREDENTIAL_NOT_VALID_ROOT_OF_TRUST = exports.CREDENTIAL_NOT_ROT_DELEGATED_QVI = exports.CREDENTIAL_NON_DELEGATED_QVI = exports.CREDENTIAL_INVALID_SCHEMA = exports.CREDENTIAL_REVOKED = exports.CREDENTIAL_VERIFIED = exports.CREDENTIAL_CRYPT_INVALID = exports.CREDENTIAL_CRYPT_VALID = exports.getGrantedCredential = exports.getConfig = exports.loadWorkflow = void 0; const fs = require("fs"); const yaml = require("js-yaml"); // Function to load and parse YAML file function loadWorkflow(workflowFilePath) { try { const file = fs.readFileSync(workflowFilePath, 'utf8'); return yaml.load(file); } catch (e) { console.error('Error reading YAML file:', e); return null; } } exports.loadWorkflow = loadWorkflow; function getConfig(configFilePath) { const configJson = JSON.parse(fs.readFileSync(configFilePath, 'utf-8')); return configJson; } exports.getConfig = getConfig; function getGrantedCredential(client, credId) { return __awaiter(this, void 0, void 0, function* () { const credentialList = yield client.credentials().list({ filter: { '-d': credId }, }); let credential; if (credentialList.length > 0) { credential = credentialList[0]; } return credential; }); } exports.getGrantedCredential = getGrantedCredential; exports.CREDENTIAL_CRYPT_VALID = { name: 'cred_crypt_valid', description: 'Credential is cryptographically valid', status: 'valid', }; exports.CREDENTIAL_CRYPT_INVALID = { name: 'cred_crypt_invalid', description: 'Credential is not cryptographically valid', status: 'invalid', }; exports.CREDENTIAL_VERIFIED = { name: 'cred_verified', description: 'Credential is verified and has a valid login account', status: 'success', }; exports.CREDENTIAL_REVOKED = { name: 'cred_revoked', description: 'Credential is revoked', status: 'fail', }; exports.CREDENTIAL_INVALID_SCHEMA = { name: 'cred_invalid_schema', description: 'Credential with invalid schema', status: 'fail', }; exports.CREDENTIAL_NON_DELEGATED_QVI = { name: 'cred_non_delegated_qvi', description: 'The QVI AID of the credential is not delegated', status: 'fail', }; exports.CREDENTIAL_NOT_ROT_DELEGATED_QVI = { name: 'cred_not_rot_delegated_qvi', description: 'The QVI AID of the credential is not delegated by the root of trust', status: 'fail', }; exports.CREDENTIAL_NOT_VALID_ROOT_OF_TRUST = { name: 'cred_not_valid_root_of_trust', description: 'Credential is not chained to the valid root of trust', status: 'fail', }; exports.credPresentationStatusMapping = new Map([ ['cred_crypt_valid', exports.CREDENTIAL_CRYPT_VALID], ['cred_crypt_invalid', exports.CREDENTIAL_CRYPT_INVALID], ]); exports.credAuthorizationStatusMapping = new Map([ ['cred_verified', exports.CREDENTIAL_VERIFIED], ['cred_revoked', exports.CREDENTIAL_REVOKED], ['cred_invalid_schema', exports.CREDENTIAL_INVALID_SCHEMA], ['cred_non_delegated_qvi', exports.CREDENTIAL_NON_DELEGATED_QVI], ['cred_not_rot_delegated_qvi', exports.CREDENTIAL_NOT_ROT_DELEGATED_QVI], ['cred_not_valid_root_of_trust', exports.CREDENTIAL_NOT_VALID_ROOT_OF_TRUST], ]);