UNPKG

@gleif-it/vlei-verifier-workflows

Version:

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

117 lines (116 loc) 5.32 kB
import { VerifierClient } from 'vlei-verifier-client'; import { VleiIssuance } from '../vlei-issuance.js'; import { CredentialVerification } from '../credential-verification.js'; import { credPresentationStatusMapping, credAuthorizationStatusMapping, } from './test-data.js'; import { getAgentSecret, getIdentifierData, } from './handle-json-config.js'; import { WorkflowState } from '../workflow-state.js'; import { resolveEnvironment } from './resolve-env.js'; import { getRootOfTrust } from './test-util.js'; export class StepRunner { type = ''; } export class CreateClientStepRunner extends StepRunner { type = 'create_client'; async run(_stepName, step, configJson = null) { const agentName = step.agent_name; const secret = getAgentSecret(configJson, agentName); const result = await VleiIssuance.createClient(secret, agentName); return result; } } export class CreateAidStepRunner extends StepRunner { type = 'create_aid'; async run(_stepName, step, configJson = null) { const identifierData = getIdentifierData(configJson, step.aid); const result = await VleiIssuance.createAid(identifierData); return result; } } export class CreateRegistryStepRunner extends StepRunner { type = 'create_registry'; async run(_stepName, step, configJson = null) { const identifierData = getIdentifierData(configJson, step.aid); const result = await VleiIssuance.createRegistry(identifierData); return result; } } export class IssueCredentialStepRunner extends StepRunner { type = 'issue_credential'; async run(stepName, step, _configJson = null) { const result = await VleiIssuance.getOrIssueCredential(stepName, step.credential, step.attributes, step.issuer_aid, step.issuee_aid, step.credential_source, Boolean(step.generate_test_data), step.test_name); return result; } } export class RevokeCredentialStepRunner extends StepRunner { type = 'revoke_credential'; async run(_stepName, step, _configJson = null) { const result = await VleiIssuance.revokeCredential(step.credential, step.issuer_aid, step.issuee_aid, Boolean(step.generate_test_data), step.test_name); return result; } } export class NotifyCredentialIssueeStepRunner extends StepRunner { type = 'notify_credential_issuee'; async run(_stepName, step, _configJson = null) { const result = await VleiIssuance.notifyCredentialIssuee(step.credential, step.issuer_aid, step.issuee_aid); return result; } } export class CredentialVerificationStepRunner extends StepRunner { type = 'credential_verification'; async run(_stepName, step, _configJson = null) { const workflow_state = WorkflowState.getInstance(); const credVerification = new CredentialVerification(); const presenterAid = step.presenter_aid; const aid = workflow_state.aids.get(presenterAid); const aidInfo = workflow_state.aidsInfo.get(presenterAid); let client; if (aidInfo !== undefined && aidInfo.type !== undefined && aidInfo.type == 'multisig') { const multisigIdentifierData = aidInfo; const multisigMemberAidInfo = workflow_state.aidsInfo.get(multisigIdentifierData.identifiers[0]); client = workflow_state.clients.get(multisigMemberAidInfo.agent.name); } else { const singlesigIdentifierData = aidInfo; client = workflow_state.clients.get(singlesigIdentifierData.agent.name); } const credId = step.credential; const cred = workflow_state.credentials.get(credId); const credCesr = client !== undefined ? await client.credentials().get(cred.sad.d, true) : undefined; const vleiUser = { roleClient: client, ecrAid: aid, creds: { [credId]: { cred: cred, credCesr: credCesr } }, idAlias: presenterAid, }; for (const action of Object.values(step.actions)) { if (action.type == 'presentation') { const credStatus = credPresentationStatusMapping.get(action.expected_status); await credVerification.credentialPresentation(vleiUser, credId, credStatus); } else if (action.type == 'authorization') { const credStatus = credAuthorizationStatusMapping.get(action.expected_status); await credVerification.credentialAuthorization(vleiUser, credStatus); } else { throw new Error(`credential_verification: Invalid action: ${action.type} `); } } return true; } } export class AddRootOfTrustStepRunner extends StepRunner { type = 'add_root_of_trust'; async run(_stepName, step, configJson) { const env = resolveEnvironment(); const rot_aid = step.rot_aid; const rot_member_aid = step.rot_member_aid; const rootOfTrustData = await getRootOfTrust(configJson, rot_aid, rot_member_aid); const verifierClient = new VerifierClient(env.verifierBaseUrl); const response = await verifierClient.addRootOfTrust(rootOfTrustData.aid, rootOfTrustData.vlei, rootOfTrustData.oobi); return response; } }