@gleif-it/vlei-verifier-workflows
Version:
Workflows for vLEI users and vLEI credentials for the vLEI-verifier service
65 lines (64 loc) • 2.12 kB
JavaScript
export function getIdentifierData(jsonConfig, aidName) {
const identifier = jsonConfig.identifiers?.[aidName];
// Check if identifier exists
if (!identifier) {
throw new Error(`Identifier not found: ${aidName}`);
}
if (identifier.identifiers) {
return {
type: 'multisig',
...identifier,
};
}
// Make sure agent exists
if (!identifier.agent || !jsonConfig.agents?.[identifier.agent]) {
throw new Error(`Agent not found for identifier: ${aidName}`);
}
const agent = jsonConfig.agents[identifier.agent];
// Make sure secret exists
if (!agent.secret || !jsonConfig.secrets?.[agent.secret]) {
throw new Error(`Secret not found for agent: ${identifier.agent}`);
}
const secret = jsonConfig.secrets[agent.secret];
return {
type: 'singlesig',
...identifier,
agent: {
name: identifier.agent,
secret: secret,
},
};
}
export function getAgentSecret(jsonConfig, agentName) {
const agent = jsonConfig.agents[agentName];
const secret = jsonConfig.secrets[agent['secret']];
return secret;
}
export 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;
}
export async function buildAidData(jsonConfig) {
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;
}