UNPKG

@gleif-it/vlei-verifier-workflows

Version:

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

77 lines (76 loc) 3.37 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.buildAidData = exports.buildCredentials = exports.getAgentSecret = exports.getIdentifierData = void 0; function getIdentifierData(jsonConfig, aidName) { var _a, _b, _c; const identifier = (_a = jsonConfig.identifiers) === null || _a === void 0 ? void 0 : _a[aidName]; // Check if identifier exists if (!identifier) { throw new Error(`Identifier not found: ${aidName}`); } if (identifier.identifiers) { return Object.assign({ type: 'multisig' }, identifier); } // Make sure agent exists if (!identifier.agent || !((_b = jsonConfig.agents) === null || _b === void 0 ? void 0 : _b[identifier.agent])) { throw new Error(`Agent not found for identifier: ${aidName}`); } const agent = jsonConfig.agents[identifier.agent]; // Make sure secret exists if (!agent.secret || !((_c = jsonConfig.secrets) === null || _c === void 0 ? void 0 : _c[agent.secret])) { throw new Error(`Secret not found for agent: ${identifier.agent}`); } const secret = jsonConfig.secrets[agent.secret]; return Object.assign(Object.assign({ type: 'singlesig' }, identifier), { agent: { name: identifier.agent, secret: secret, } }); } exports.getIdentifierData = getIdentifierData; function getAgentSecret(jsonConfig, agentName) { const agent = jsonConfig.agents[agentName]; const secret = jsonConfig.secrets[agent['secret']]; return secret; } exports.getAgentSecret = getAgentSecret; function buildCredentials(jsonConfig) { const credentials = new Map(); for (const key in jsonConfig.credentials) { const cred = jsonConfig.credentials[key]; const curCred = { type: cred.type, schema: cred.schema, rules: cred.rules, privacy: cred.privacy, attributes: cred.attributes, credSource: cred.credSource, }; credentials.set(key, curCred); } return credentials; } exports.buildCredentials = buildCredentials; function buildAidData(jsonConfig) { return __awaiter(this, void 0, void 0, function* () { const identifiers = structuredClone(jsonConfig.identifiers); for (const key of Object.keys(identifiers)) { if (identifiers[key]['agent']) { identifiers[key].agent = { name: identifiers[key]['agent'], secret: jsonConfig.secrets[jsonConfig.agents[identifiers[key]['agent']]['secret']], }; } } return identifiers; }); } exports.buildAidData = buildAidData;