{"version":3,"file":"SdJwtVcApi.mjs","names":[],"sources":["../../../src/modules/sd-jwt-vc/SdJwtVcApi.ts"],"sourcesContent":["import type { ResolvedTypeMetadata } from '@sd-jwt/sd-jwt-vc'\nimport { AgentContext } from '../../agent'\nimport { injectable } from '../../plugins'\nimport type { Query, QueryOptions } from '../../storage/StorageService'\nimport type { SdJwtVcRecord } from './repository'\nimport type {\n  SdJwtVcHeader,\n  SdJwtVcPayload,\n  SdJwtVcPresentOptions,\n  SdJwtVcSignOptions,\n  SdJwtVcStoreOptions,\n  SdJwtVcVerifyOptions,\n} from './SdJwtVcOptions'\n\nimport { type SdJwtVc, SdJwtVcService } from './SdJwtVcService'\n\n/**\n * @public\n */\n@injectable()\nexport class SdJwtVcApi {\n  private agentContext: AgentContext\n  private sdJwtVcService: SdJwtVcService\n\n  public constructor(agentContext: AgentContext, sdJwtVcService: SdJwtVcService) {\n    this.agentContext = agentContext\n    this.sdJwtVcService = sdJwtVcService\n  }\n\n  public async sign<Payload extends SdJwtVcPayload>(options: SdJwtVcSignOptions<Payload>) {\n    return await this.sdJwtVcService.sign<Payload>(this.agentContext, options)\n  }\n\n  /**\n   *\n   * Create a compact presentation of the sd-jwt.\n   * This presentation can be send in- or out-of-band to the verifier.\n   *\n   * Also, whether to include the holder key binding.\n   */\n  public async present<Payload extends SdJwtVcPayload = SdJwtVcPayload>(\n    options: SdJwtVcPresentOptions<Payload>\n  ): Promise<string> {\n    return await this.sdJwtVcService.present(this.agentContext, options)\n  }\n\n  /**\n   *\n   * Verify an incoming sd-jwt. 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<Header extends SdJwtVcHeader, Payload extends SdJwtVcPayload>(options: SdJwtVcVerifyOptions) {\n    return await this.sdJwtVcService.verify<Header, Payload>(this.agentContext, options)\n  }\n\n  /**\n   * Fetches the type metadata for the `vct`. The default resolver only supports HTTPs,\n   * but you can register a custom resolver on the SdJwtVcModule config.\n   *\n   * If the default resolver is used and fetching the VCT directly fails, it will fallback to the legacy vct path.\n   * If both fail, an error will be thrown, unless `throwErrorOnFetchError` is set to `false`.\n   *\n   * The integrity will always be verified if the metadata was resolved. The `extends` keyword is\n   * not resolved yet.\n   */\n  public async fetchTypeMetadata(\n    sdJwtVc: SdJwtVc,\n    options?: { throwErrorOnFetchError?: boolean; throwErrorOnUnsupportedVctValue?: boolean }\n  ): Promise<ResolvedTypeMetadata | undefined> {\n    return this.sdJwtVcService.fetchTypeMetadata(this.agentContext, sdJwtVc, options)\n  }\n\n  /**\n   * Get and validate a sd-jwt-vc from a serialized JWT.\n   */\n  public fromCompact<Header extends SdJwtVcHeader, Payload extends SdJwtVcPayload>(sdJwtVcCompact: string) {\n    return this.sdJwtVcService.fromCompact<Header, Payload>(sdJwtVcCompact)\n  }\n\n  public async store(options: SdJwtVcStoreOptions) {\n    return await this.sdJwtVcService.store(this.agentContext, options)\n  }\n\n  public async getById(id: string): Promise<SdJwtVcRecord> {\n    return await this.sdJwtVcService.getById(this.agentContext, id)\n  }\n\n  public async getAll(): Promise<Array<SdJwtVcRecord>> {\n    return await this.sdJwtVcService.getAll(this.agentContext)\n  }\n\n  public async findAllByQuery(query: Query<SdJwtVcRecord>, queryOptions?: QueryOptions): Promise<Array<SdJwtVcRecord>> {\n    return await this.sdJwtVcService.findByQuery(this.agentContext, query, queryOptions)\n  }\n\n  public async deleteById(id: string) {\n    return await this.sdJwtVcService.deleteById(this.agentContext, id)\n  }\n\n  public async update(sdJwtVcRecord: SdJwtVcRecord) {\n    return await this.sdJwtVcService.update(this.agentContext, sdJwtVcRecord)\n  }\n}\n"],"mappings":";;;;;;;;;;;AAoBO,uBAAM,WAAW;CAItB,AAAO,YAAY,cAA4B,gBAAgC;AAC7E,OAAK,eAAe;AACpB,OAAK,iBAAiB;;CAGxB,MAAa,KAAqC,SAAsC;AACtF,SAAO,MAAM,KAAK,eAAe,KAAc,KAAK,cAAc,QAAQ;;;;;;;;;CAU5E,MAAa,QACX,SACiB;AACjB,SAAO,MAAM,KAAK,eAAe,QAAQ,KAAK,cAAc,QAAQ;;;;;;;;;CAUtE,MAAa,OAAqE,SAA+B;AAC/G,SAAO,MAAM,KAAK,eAAe,OAAwB,KAAK,cAAc,QAAQ;;;;;;;;;;;;CAatF,MAAa,kBACX,SACA,SAC2C;AAC3C,SAAO,KAAK,eAAe,kBAAkB,KAAK,cAAc,SAAS,QAAQ;;;;;CAMnF,AAAO,YAA0E,gBAAwB;AACvG,SAAO,KAAK,eAAe,YAA6B,eAAe;;CAGzE,MAAa,MAAM,SAA8B;AAC/C,SAAO,MAAM,KAAK,eAAe,MAAM,KAAK,cAAc,QAAQ;;CAGpE,MAAa,QAAQ,IAAoC;AACvD,SAAO,MAAM,KAAK,eAAe,QAAQ,KAAK,cAAc,GAAG;;CAGjE,MAAa,SAAwC;AACnD,SAAO,MAAM,KAAK,eAAe,OAAO,KAAK,aAAa;;CAG5D,MAAa,eAAe,OAA6B,cAA4D;AACnH,SAAO,MAAM,KAAK,eAAe,YAAY,KAAK,cAAc,OAAO,aAAa;;CAGtF,MAAa,WAAW,IAAY;AAClC,SAAO,MAAM,KAAK,eAAe,WAAW,KAAK,cAAc,GAAG;;CAGpE,MAAa,OAAO,eAA8B;AAChD,SAAO,MAAM,KAAK,eAAe,OAAO,KAAK,cAAc,cAAc;;;yBAnF5E,YAAY"}