UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

86 lines (85 loc) • 4.36 kB
import { injectable } from "../../plugins/index.mjs"; import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorateMetadata.mjs"; import __decorate from "../../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorate.mjs"; import "../../agent/index.mjs"; import { KeyManagementApi } from "../kms/KeyManagementApi.mjs"; import "../kms/index.mjs"; import { Mdoc } from "./Mdoc.mjs"; import { MdocRepository } from "./repository/MdocRepository.mjs"; import { MdocVerificationSessionRepository } from "./repository/MdocVerificationSessionRepository.mjs"; import "./repository/index.mjs"; import { MdocDeviceResponse } from "./MdocDeviceResponse.mjs"; //#region src/modules/mdoc/MdocService.ts let MdocService = class MdocService { constructor(mdocRepository, mdocVerificationSessionRepository) { this.mdocRepository = mdocRepository; this.mdocVerificationSessionRepository = mdocVerificationSessionRepository; } mdocFromBase64Url(hexEncodedMdoc) { return Mdoc.fromBase64Url(hexEncodedMdoc); } signMdoc(agentContext, options) { return Mdoc.sign(agentContext, options); } async verifyMdoc(agentContext, mdoc, options) { return await mdoc.verify(agentContext, options); } async createDeviceResponse(agentContext, options) { return MdocDeviceResponse.createDeviceResponse(agentContext, options); } async createPresentationDefinitionDeviceResponse(agentContext, options) { return MdocDeviceResponse.createDeviceResponseWithPresentationDefinition(agentContext, options); } /** * @deprecated Credo does not use this method itself, and it only supports part of DCQL. Every claim * of every `mso_mdoc` credential query is requested: `credential_sets`, `claim_sets` and `values` * are ignored, credential queries with the same doctype are merged, nested claim paths are * truncated, and a claim missing from the mdoc throws instead of being treated as optional. Use * `DcqlService.createPresentation` to present mdocs for a DCQL query, or * {@link MdocService.createDeviceResponse} with explicit `documentRequests`. */ async createDcqlQueryDeviceResponse(agentContext, options) { return MdocDeviceResponse.createDeviceResponseWithDcqlQuery(agentContext, options); } async verifyDeviceResponse(agentContext, options) { return MdocDeviceResponse.fromBase64Url(options.deviceResponse).verify(agentContext, options); } async store(agentContext, options) { await this.mdocRepository.save(agentContext, options.record); return options.record; } async getById(agentContext, id) { return await this.mdocRepository.getById(agentContext, id); } async getAll(agentContext) { return await this.mdocRepository.getAll(agentContext); } async findByQuery(agentContext, query, queryOptions) { return await this.mdocRepository.findByQuery(agentContext, query, queryOptions); } async deleteById(agentContext, id) { await this.mdocRepository.deleteById(agentContext, id); } async update(agentContext, mdocRecord) { await this.mdocRepository.update(agentContext, mdocRecord); } async getVerificationSessionById(agentContext, verificationSessionId) { return await this.mdocVerificationSessionRepository.getById(agentContext, verificationSessionId); } async findVerificationSessionsByQuery(agentContext, query, queryOptions) { return await this.mdocVerificationSessionRepository.findByQuery(agentContext, query, queryOptions); } /** * Delete a verification session, and by default the ephemeral session key it holds. The key is * not deleted at any other point in the session lifecycle. */ async deleteVerificationSessionById(agentContext, verificationSessionId, options) { const verificationSession = await this.mdocVerificationSessionRepository.getById(agentContext, verificationSessionId); if (options?.deleteAssociatedKey ?? true) await agentContext.resolve(KeyManagementApi).deleteKey({ keyId: verificationSession.sessionKeyId }); await this.mdocVerificationSessionRepository.delete(agentContext, verificationSession); } }; MdocService = __decorate([injectable(), __decorateMetadata("design:paramtypes", [typeof MdocRepository === "undefined" ? Object : MdocRepository, typeof MdocVerificationSessionRepository === "undefined" ? Object : MdocVerificationSessionRepository])], MdocService); //#endregion export { MdocService }; //# sourceMappingURL=MdocService.mjs.map