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

1 lines • 6.77 kB
{"version":3,"file":"MdocApi.mjs","names":[],"sources":["../../../src/modules/mdoc/MdocApi.ts"],"sourcesContent":["import { AgentContext } from '../../agent'\nimport { injectable } from '../../plugins'\nimport type { Query, QueryOptions } from '../../storage/StorageService'\nimport { Mdoc } from './Mdoc'\nimport { MdocDcApiService } from './MdocDcApiService'\nimport type {\n MdocDcApiCreateResponseOptions,\n MdocDcApiCreateVerificationSessionOptions,\n MdocDcApiResolveRequestOptions,\n MdocDcApiVerifyResponseOptions,\n MdocDeleteVerificationSessionOptions,\n MdocSignOptions,\n MdocStoreOptions,\n MdocVerifyOptions,\n} from './MdocOptions'\nimport { MdocService } from './MdocService'\nimport type { MdocRecord, MdocVerificationSessionRecord } from './repository'\n\n/**\n * @public\n */\n@injectable()\nexport class MdocApi {\n private agentContext: AgentContext\n private mdocService: MdocService\n private mdocDcApiService: MdocDcApiService\n\n public constructor(agentContext: AgentContext, mdocService: MdocService, mdocDcApiService: MdocDcApiService) {\n this.agentContext = agentContext\n this.mdocService = mdocService\n this.mdocDcApiService = mdocDcApiService\n }\n\n /**\n * Create a new Mdoc, with a spcific doctype, namespace, and validity info.\n */\n public async sign(options: MdocSignOptions) {\n return await this.mdocService.signMdoc(this.agentContext, options)\n }\n\n /**\n *\n * Verify an incoming mdoc. It will check whether everything is valid, but also returns parts of the validation.\n *\n * For example, you might still want to continue with a flow if not all the claims are included, but the signature is valid.\n *\n */\n public async verify(mdoc: Mdoc, options: MdocVerifyOptions) {\n return await this.mdocService.verifyMdoc(this.agentContext, mdoc, options)\n }\n\n /**\n * Create a Mdoc class from a base64url encoded Mdoc Issuer-Signed structure\n */\n public fromBase64Url(base64Url: string) {\n return Mdoc.fromBase64Url(base64Url)\n }\n\n public async store(options: MdocStoreOptions) {\n return await this.mdocService.store(this.agentContext, options)\n }\n\n public async getById(id: string): Promise<MdocRecord> {\n return await this.mdocService.getById(this.agentContext, id)\n }\n\n public async getAll(): Promise<Array<MdocRecord>> {\n return await this.mdocService.getAll(this.agentContext)\n }\n\n public async findAllByQuery(query: Query<MdocRecord>, queryOptions?: QueryOptions): Promise<Array<MdocRecord>> {\n return await this.mdocService.findByQuery(this.agentContext, query, queryOptions)\n }\n\n public async deleteById(id: string) {\n return await this.mdocService.deleteById(this.agentContext, id)\n }\n\n public async update(mdocRecord: MdocRecord) {\n return await this.mdocService.update(this.agentContext, mdocRecord)\n }\n\n /**\n * Get an mdoc verification session by id, for any of the mdoc presentation protocols.\n */\n public async getVerificationSessionById(verificationSessionId: string): Promise<MdocVerificationSessionRecord> {\n return await this.mdocService.getVerificationSessionById(this.agentContext, verificationSessionId)\n }\n\n public async findVerificationSessionsByQuery(\n query: Query<MdocVerificationSessionRecord>,\n queryOptions?: QueryOptions\n ): Promise<Array<MdocVerificationSessionRecord>> {\n return await this.mdocService.findVerificationSessionsByQuery(this.agentContext, query, queryOptions)\n }\n\n /**\n * Delete an mdoc verification session. By default the ephemeral session key created for the\n * session is deleted along with it; it is not deleted at any other point in the session\n * lifecycle.\n */\n public async deleteVerificationSessionById(\n verificationSessionId: string,\n options?: MdocDeleteVerificationSessionOptions\n ) {\n return await this.mdocService.deleteVerificationSessionById(this.agentContext, verificationSessionId, options)\n }\n\n /**\n * Create an ISO 18013-7 Annex C (`org-iso-mdoc`) DC API request and the verification session\n * tracking it. The returned request can be passed to `navigator.credentials.get()` as the\n * `data` of a `org-iso-mdoc` protocol request.\n */\n public async createDcApiVerificationSession(options: MdocDcApiCreateVerificationSessionOptions) {\n return await this.mdocDcApiService.createVerificationSession(this.agentContext, options)\n }\n\n /**\n * Decrypt and verify an `org-iso-mdoc` DC API response for a verification session.\n */\n public async verifyDcApiResponse(options: MdocDcApiVerifyResponseOptions) {\n return await this.mdocDcApiService.verifyResponse(this.agentContext, options)\n }\n\n /**\n * Parse an incoming `org-iso-mdoc` DC API request, verify reader authentication where present,\n * and match the requested documents against the stored mdocs.\n */\n public async resolveDcApiRequest(options: MdocDcApiResolveRequestOptions) {\n return await this.mdocDcApiService.resolveRequest(this.agentContext, options)\n }\n\n /**\n * Create the encrypted `org-iso-mdoc` DC API response for a resolved request.\n */\n public async createDcApiResponse(options: MdocDcApiCreateResponseOptions) {\n return await this.mdocDcApiService.createResponse(this.agentContext, options)\n }\n}\n"],"mappings":";;;;;;;;;AAsBO,IAAM,UAAN,MAAM,QAAQ;CAKnB,YAAmB,cAA4B,aAA0B,kBAAoC;EAC3G,KAAK,eAAe;EACpB,KAAK,cAAc;EACnB,KAAK,mBAAmB;CAC1B;;;;CAKA,MAAa,KAAK,SAA0B;EAC1C,OAAO,MAAM,KAAK,YAAY,SAAS,KAAK,cAAc,OAAO;CACnE;;;;;;;;CASA,MAAa,OAAO,MAAY,SAA4B;EAC1D,OAAO,MAAM,KAAK,YAAY,WAAW,KAAK,cAAc,MAAM,OAAO;CAC3E;;;;CAKA,cAAqB,WAAmB;EACtC,OAAO,KAAK,cAAc,SAAS;CACrC;CAEA,MAAa,MAAM,SAA2B;EAC5C,OAAO,MAAM,KAAK,YAAY,MAAM,KAAK,cAAc,OAAO;CAChE;CAEA,MAAa,QAAQ,IAAiC;EACpD,OAAO,MAAM,KAAK,YAAY,QAAQ,KAAK,cAAc,EAAE;CAC7D;CAEA,MAAa,SAAqC;EAChD,OAAO,MAAM,KAAK,YAAY,OAAO,KAAK,YAAY;CACxD;CAEA,MAAa,eAAe,OAA0B,cAAyD;EAC7G,OAAO,MAAM,KAAK,YAAY,YAAY,KAAK,cAAc,OAAO,YAAY;CAClF;CAEA,MAAa,WAAW,IAAY;EAClC,OAAO,MAAM,KAAK,YAAY,WAAW,KAAK,cAAc,EAAE;CAChE;CAEA,MAAa,OAAO,YAAwB;EAC1C,OAAO,MAAM,KAAK,YAAY,OA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