Skip to content
Snippets Groups Projects
Commit cd65c347 authored by Alexey Lunin's avatar Alexey Lunin
Browse files

small refactor OP#250

parent d01da525
No related branches found
No related tags found
2 merge requests!93OCM key - svdx id mapping OP#252,!91feat: ocm did svdx generation for sender OP#250
Pipeline #74567 waiting for manual action
......@@ -19,12 +19,6 @@ export class CatalogClient {
{
email: email,
},
{
auth: {
username: this.catalogConfig.catalogBasicUser,
password: this.catalogConfig.catalogBasicPass,
},
},
);
return response.data.did;
} catch (e) {
......@@ -41,19 +35,10 @@ export class CatalogClient {
createAccount = async (email: string, didSvdx: string): Promise<void> => {
this.logger.debug(`createAccount`, email);
try {
await axios.post(
`${this.catalogConfig.catalogUrl}/v1/accounts`,
{
email: email,
did: didSvdx,
},
{
auth: {
username: this.catalogConfig.catalogBasicUser,
password: this.catalogConfig.catalogBasicPass,
},
},
);
await axios.post(`${this.catalogConfig.catalogUrl}/v1/accounts`, {
email: email,
did: didSvdx,
});
} catch (e) {
this.logger.debug("storeMapping failed", e);
throw e;
......
import { Injectable, Logger } from "@nestjs/common";
import {
EntityNotFoundError,
OcmError,
RequestSenderEmailVcDto,
W3cJsonLdVerifiableCredentialDto,
} from "@ocm-engine/dtos";
import { EntityNotFoundError, RequestSenderEmailVcDto } from "@ocm-engine/dtos";
import { CatalogClient } from "../clients/catalog.client";
import {
generateDidSvdx,
generateRandomDidSvdx,
getFirstDidSvdxRecord,
} from "../../agent.utils";
import { generateRandomDidSvdx } from "../../agent.utils";
import { AskarService } from "./askar.service";
import { IConfAgent } from "@ocm-engine/config";
import { IConfCatalog } from "@ocm-engine/config";
import { ConfigService } from "@nestjs/config";
import {
ClaimFormat,
......@@ -25,11 +16,15 @@ import { uuid } from "@credo-ts/core/build/utils/uuid";
@Injectable()
export class AgentOcmService {
private readonly logger = new Logger(AgentOcmService.name);
private activated = false;
constructor(
private readonly askar: AskarService,
private readonly catalogClient: CatalogClient,
private readonly configService: ConfigService,
) {}
) {
const catalogConfig = this.configService.get<IConfCatalog>("catalog")!;
this.activated = !!catalogConfig.catalogUrl;
}
requestSenderEmailVC = async (
dto: RequestSenderEmailVcDto,
......@@ -38,12 +33,13 @@ export class AgentOcmService {
did: string;
vc: object;
}> => {
this.ensureActivated();
this.logger.debug(`requestSenderEmailVC`, dto.email);
const didSvdx = await this.catalogClient.searchAccount(dto.email);
if (didSvdx) {
// TODO look up for VC in storage
const record = await this.askar.agent.genericRecords.findById(
"hin" + dto.email,
"svdx_vc_" + dto.email,
);
if (!record) {
// todo regenerate in that case?
......@@ -92,7 +88,7 @@ export class AgentOcmService {
"http://116.203.134.234/.well-known/hin-account-schema", // todo replace with vereign domain
],
type: ["VerifiableCredential"],
id: svdxDid.did + "?uuid=" + credentialRecordId, // TODO Where should we store it? In generic storage? Or create specific new one?
id: svdxDid.did + "?uuid=" + credentialRecordId,
issuer: svdxDid.did,
issuanceDate: new Date().toISOString(),
credentialSubject: {
......@@ -118,7 +114,7 @@ export class AgentOcmService {
// Save credential
await this.askar.agent.genericRecords.save({
id: "hin" + dto.email, // todo should it has prefix hin?
id: "svdx_vc_" + dto.email,
content: jsonVC,
});
......@@ -130,4 +126,12 @@ export class AgentOcmService {
vc: jsonVC,
};
};
private ensureActivated() {
if (!this.activated) {
throw new Error(
"Please provide the catalog URL on startup to activate this endpoint.",
);
}
}
}
......@@ -6,7 +6,5 @@ export const catalogConfig = registerAs(
"catalog",
(): IConfCatalog => ({
catalogUrl: process.env["CATALOG_URL"]!,
catalogBasicUser: process.env["CATALOG_BASIC_USER"]!,
catalogBasicPass: process.env["CATALOG_BASIC_PASS"]!,
}),
);
export interface IConfCatalog {
catalogUrl: string;
catalogBasicUser: string;
catalogBasicPass: string;
}
import Joi from "joi";
export const catalogSchema = Joi.object({
CATALOG_URL: Joi.string().required(),
CATALOG_BASIC_USER: Joi.string().required(),
CATALOG_BASIC_PASS: Joi.string().required(),
CATALOG_URL: Joi.string(),
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment