import type { SdJwtVcCreateOptions, SdJwtVcPresentOptions, SdJwtVcReceiveOptions, SdJwtVcVerifyOptions, } from './SdJwtVcOptions' import type { SdJwtVcVerificationResult } from './SdJwtVcService' import type { SdJwtVcRecord } from './repository' import type { Query } from '@aries-framework/core' import { AgentContext, injectable } from '@aries-framework/core' import { SdJwtVcService } from './SdJwtVcService' /** * @public */ @injectable() export class SdJwtVcApi { private agentContext: AgentContext private sdJwtVcService: SdJwtVcService public constructor(agentContext: AgentContext, sdJwtVcService: SdJwtVcService) { this.agentContext = agentContext this.sdJwtVcService = sdJwtVcService } public async create = Record>( payload: Payload, options: SdJwtVcCreateOptions ): Promise<{ sdJwtVcRecord: SdJwtVcRecord; compact: string }> { return await this.sdJwtVcService.create(this.agentContext, payload, options) } /** * * Validates and stores an sd-jwt-vc from the perspective of an holder * */ public async storeCredential(sdJwtVcCompact: string, options: SdJwtVcReceiveOptions): Promise { return await this.sdJwtVcService.storeCredential(this.agentContext, sdJwtVcCompact, options) } /** * * Create a compact presentation of the sd-jwt. * This presentation can be send in- or out-of-band to the verifier. * * Within the `options` field, you can supply the indicies of the disclosures you would like to share with the verifier. * Also, whether to include the holder key binding. * */ public async present(sdJwtVcRecord: SdJwtVcRecord, options: SdJwtVcPresentOptions): Promise { return await this.sdJwtVcService.present(this.agentContext, sdJwtVcRecord, options) } /** * * Verify an incoming sd-jwt. It will check whether everything is valid, but also returns parts of the validation. * * For example, you might still want to continue with a flow if not all the claims are included, but the signature is valid. * */ public async verify< Header extends Record = Record, Payload extends Record = Record >( sdJwtVcCompact: string, options: SdJwtVcVerifyOptions ): Promise<{ sdJwtVcRecord: SdJwtVcRecord; validation: SdJwtVcVerificationResult }> { return await this.sdJwtVcService.verify(this.agentContext, sdJwtVcCompact, options) } public async getById(id: string): Promise { return await this.sdJwtVcService.getCredentialRecordById(this.agentContext, id) } public async getAll(): Promise> { return await this.sdJwtVcService.getAllCredentialRecords(this.agentContext) } public async findAllByQuery(query: Query): Promise> { return await this.sdJwtVcService.findCredentialRecordsByQuery(this.agentContext, query) } public async remove(id: string) { return await this.sdJwtVcService.removeCredentialRecord(this.agentContext, id) } public async update(sdJwtVcRecord: SdJwtVcRecord) { return await this.sdJwtVcService.updateCredentialRecord(this.agentContext, sdJwtVcRecord) } }