{"version":3,"file":"W3cV2SdJwtVerifiablePresentation.mjs","names":[],"sources":["../../../../src/modules/vc/sd-jwt-vc/W3cV2SdJwtVerifiablePresentation.ts"],"sourcesContent":["import { CredoError } from '../../../error'\nimport { JsonTransformer, MessageValidator } from '../../../utils'\nimport { ClaimFormat } from '../models'\nimport { W3cV2Presentation } from '../models/presentation/W3cV2Presentation'\nimport { decodeSdJwt, type W3cV2SdJwt } from './W3cV2SdJwt'\n\nexport interface W3cV2SdJwtVerifiablePresentationOptions {\n  sdJwt: W3cV2SdJwt<ClaimFormat.SdJwtW3cVp>\n}\n\n/**\n * Represents a Verifiable Presentation encoded as a SD-JWT.\n *\n * @see https://www.w3.org/TR/vc-jose-cose/#securing-vps-sd-jwt\n */\nexport class W3cV2SdJwtVerifiablePresentation {\n  public constructor(options: W3cV2SdJwtVerifiablePresentationOptions) {\n    this.sdJwt = options.sdJwt\n    this.resolvedPresentation = JsonTransformer.fromJSON(options.sdJwt.prettyClaims, W3cV2Presentation, {\n      validate: false,\n    })\n\n    // Validates the SD-JWT and resolved presentation\n    this.validate()\n  }\n\n  public static fromCompact(compact: string) {\n    const sdJwt = decodeSdJwt(compact, ClaimFormat.SdJwtW3cVp)\n\n    return new W3cV2SdJwtVerifiablePresentation({\n      sdJwt,\n    })\n  }\n\n  /**\n   * The original SD-JWT.\n   */\n  public readonly sdJwt: W3cV2SdJwt<ClaimFormat.SdJwtW3cVp>\n\n  /**\n   * Resolved presentation is the fully resolved {@link W3cV2Presentation} instance.\n   */\n  public readonly resolvedPresentation: W3cV2Presentation\n\n  /**\n   * The encoded version of this presentation.\n   */\n  public get encoded() {\n    return this.sdJwt.compact\n  }\n\n  /**\n   * The {@link ClaimFormat} of the presentation.\n   *\n   * For W3C VP SD-JWT credentials this is always `vp+sd-jwt`.\n   */\n  public get claimFormat(): ClaimFormat.SdJwtW3cVp {\n    return ClaimFormat.SdJwtW3cVp\n  }\n\n  /**\n   * Validates the SD-JWT and the resolved presentation.\n   */\n  public validate() {\n    // Validate the resolved credential according to the data model\n    MessageValidator.validateSync(this.resolvedPresentation)\n\n    // Basic JWT validations to ensure compliance to the specification\n    const sdJwt = this.sdJwt\n    const header = sdJwt.header\n    const payload = sdJwt.prettyClaims\n\n    if ('typ' in header && header.typ !== 'vp+sd-jwt') {\n      throw new CredoError(`The provided W3C VP JWT does not have the correct 'typ' header.`)\n    }\n\n    if ('cyt' in header && header.cyt !== 'vp') {\n      throw new CredoError(`The provided W3C VP JWT does not have the correct 'cyt' header.`)\n    }\n\n    const iss = header.iss ?? payload.iss\n    if (iss && this.resolvedPresentation.holderId) {\n      if (this.resolvedPresentation.holderId !== iss) {\n        throw new CredoError(`The provided W3C VP SD-JWT has both 'iss' and 'holder' claims, but they differ.`)\n      }\n    }\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,IAAa,mCAAb,MAAa,iCAAiC;CAC5C,AAAO,YAAY,SAAkD;AACnE,OAAK,QAAQ,QAAQ;AACrB,OAAK,uBAAuB,gBAAgB,SAAS,QAAQ,MAAM,cAAc,mBAAmB,EAClG,UAAU,OACX,CAAC;AAGF,OAAK,UAAU;;CAGjB,OAAc,YAAY,SAAiB;AAGzC,SAAO,IAAI,iCAAiC,EAC1C,OAHY,YAAY,SAAS,YAAY,WAAW,EAIzD,CAAC;;;;;CAgBJ,IAAW,UAAU;AACnB,SAAO,KAAK,MAAM;;;;;;;CAQpB,IAAW,cAAsC;AAC/C,SAAO,YAAY;;;;;CAMrB,AAAO,WAAW;AAEhB,mBAAiB,aAAa,KAAK,qBAAqB;EAGxD,MAAM,QAAQ,KAAK;EACnB,MAAM,SAAS,MAAM;EACrB,MAAM,UAAU,MAAM;AAEtB,MAAI,SAAS,UAAU,OAAO,QAAQ,YACpC,OAAM,IAAI,WAAW,kEAAkE;AAGzF,MAAI,SAAS,UAAU,OAAO,QAAQ,KACpC,OAAM,IAAI,WAAW,kEAAkE;EAGzF,MAAM,MAAM,OAAO,OAAO,QAAQ;AAClC,MAAI,OAAO,KAAK,qBAAqB,UACnC;OAAI,KAAK,qBAAqB,aAAa,IACzC,OAAM,IAAI,WAAW,kFAAkF"}