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,EAAI,uBAAuB,0BAA0B,GAC9C,UACxB,EAAO,QAAQ,OAAO,YAAY,KAE9B,EAA4D,OAAzC,EAAK,KAAK,WAAW,iBAA2B,EAAK,KAAK,gBAAgB,KAAK,YAClG,EAAgB,EACxB,CAEJ,GACF","file":"/npm/@sd-jwt/sd-jwt-vc@0.17.1/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@sd-jwt/sd-jwt-vc@0.17.1/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __reflectGet = Reflect.get;\nvar __export = (target, all) => {\n  for (var name in all)\n    __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n  if (from && typeof from === \"object\" || typeof from === \"function\") {\n    for (let key of __getOwnPropNames(from))\n      if (!__hasOwnProp.call(to, key) && key !== except)\n        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n  }\n  return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);\nvar __async = (__this, __arguments, generator) => {\n  return new Promise((resolve, reject) => {\n    var fulfilled = (value) => {\n      try {\n        step(generator.next(value));\n      } catch (e) {\n        reject(e);\n      }\n    };\n    var rejected = (value) => {\n      try {\n        step(generator.throw(value));\n      } catch (e) {\n        reject(e);\n      }\n    };\n    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);\n    step((generator = generator.apply(__this, __arguments)).next());\n  });\n};\n\n// src/index.ts\nvar index_exports = {};\n__export(index_exports, {\n  SDJwtVcInstance: () => SDJwtVcInstance\n});\nmodule.exports = __toCommonJS(index_exports);\n\n// src/sd-jwt-vc-instance.ts\nvar import_core = require(\"@sd-jwt/core\");\nvar import_jwt_status_list = require(\"@sd-jwt/jwt-status-list\");\nvar import_utils = require(\"@sd-jwt/utils\");\nvar SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {\n  constructor(userConfig) {\n    super(userConfig);\n    /**\n     * The type of the SD-JWT-VC set in the header.typ field.\n     */\n    this.type = \"dc+sd-jwt\";\n    this.userConfig = {};\n    if (userConfig) {\n      this.userConfig = userConfig;\n    }\n  }\n  /**\n   * Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.\n   * @param disclosureFrame\n   */\n  validateReservedFields(disclosureFrame) {\n    if ((disclosureFrame == null ? void 0 : disclosureFrame._sd) && Array.isArray(disclosureFrame._sd) && disclosureFrame._sd.length > 0) {\n      const reservedNames = [\"iss\", \"nbf\", \"exp\", \"cnf\", \"vct\", \"status\"];\n      const reservedNamesInDisclosureFrame = disclosureFrame._sd.filter((key) => reservedNames.includes(key));\n      if (reservedNamesInDisclosureFrame.length > 0) {\n        throw new import_utils.SDJWTException(\"Cannot disclose protected field\");\n      }\n    }\n  }\n  /**\n   * Fetches the status list from the uri with a timeout of 10 seconds.\n   * @param uri The URI to fetch from.\n   * @returns A promise that resolves to a compact JWT.\n   */\n  statusListFetcher(uri) {\n    return __async(this, null, function* () {\n      var _a;\n      const controller = new AbortController();\n      const timeoutId = setTimeout(() => controller.abort(), 1e4);\n      try {\n        const response = yield fetch(uri, {\n          signal: controller.signal,\n          headers: { Accept: \"application/statuslist+jwt\" }\n        });\n        if (!response.ok) {\n          throw new Error(\n            `Error fetching status list: ${response.status} ${yield response.text()}`\n          );\n        }\n        if (!((_a = response.headers.get(\"content-type\")) == null ? void 0 : _a.includes(\"application/statuslist+jwt\"))) {\n          throw new Error(\"Invalid content type\");\n        }\n        return response.text();\n      } finally {\n        clearTimeout(timeoutId);\n      }\n    });\n  }\n  /**\n   * Validates the status, throws an error if the status is not 0.\n   * @param status\n   * @returns\n   */\n  statusValidator(status) {\n    return __async(this, null, function* () {\n      if (status !== 0) throw new import_utils.SDJWTException(\"Status is not valid\");\n      return Promise.resolve();\n    });\n  }\n  /**\n   * Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.\n   * @param currentDate current time in seconds\n   */\n  verify(encodedSDJwt, options) {\n    return __async(this, null, function* () {\n      const result = yield __superGet(_SDJwtVcInstance.prototype, this, \"verify\").call(this, encodedSDJwt, options).then((res) => {\n        return {\n          payload: res.payload,\n          header: res.header,\n          kb: res.kb\n        };\n      });\n      yield this.verifyStatus(result, options);\n      if (this.userConfig.loadTypeMetadataFormat) {\n        yield this.verifyVct(result);\n      }\n      return result;\n    });\n  }\n  /**\n   * Gets VCT Metadata of the raw SD-JWT-VC. Returns the type metadata format. If the SD-JWT-VC is invalid or does not contain a vct claim, an error is thrown.\n   * @param encodedSDJwt\n   * @returns\n   */\n  getVct(encodedSDJwt) {\n    return __async(this, null, function* () {\n      const { payload, header } = yield import_core.SDJwt.extractJwt(encodedSDJwt);\n      if (!payload) {\n        throw new import_utils.SDJWTException(\"JWT payload is missing\");\n      }\n      const result = {\n        payload,\n        header,\n        kb: void 0\n      };\n      return this.fetchVct(result);\n    });\n  }\n  /**\n   * Validates the integrity of the response if the integrity is passed. If the integrity does not match, an error is thrown.\n   * @param integrity\n   * @param response\n   */\n  validateIntegrity(response, url, integrity) {\n    return __async(this, null, function* () {\n      if (integrity) {\n        const arrayBuffer = yield response.arrayBuffer();\n        const alg = integrity.split(\"-\")[0];\n        const hashBuffer = yield this.userConfig.hasher(\n          arrayBuffer,\n          alg\n        );\n        const integrityHash = integrity.split(\"-\")[1];\n        const hash = Array.from(new Uint8Array(hashBuffer)).map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n        if (hash !== integrityHash) {\n          throw new Error(\n            `Integrity check for ${url} failed: is ${hash}, but expected ${integrityHash}`\n          );\n        }\n      }\n    });\n  }\n  /**\n   * Fetches the content from the url with a timeout of 10 seconds.\n   * @param url\n   * @returns\n   */\n  fetch(url, integrity) {\n    return __async(this, null, function* () {\n      var _a;\n      try {\n        const response = yield fetch(url, {\n          signal: AbortSignal.timeout((_a = this.userConfig.timeout) != null ? _a : 1e4)\n        });\n        if (!response.ok) {\n          const errorText = yield response.text();\n          throw new Error(\n            `Error fetching ${url}: ${response.status} ${response.statusText} - ${errorText}`\n          );\n        }\n        yield this.validateIntegrity(response.clone(), url, integrity);\n        return response.json();\n      } catch (error) {\n        if (error.name === \"TimeoutError\") {\n          throw new Error(`Request to ${url} timed out`);\n        }\n        throw error;\n      }\n    });\n  }\n  /**\n   * Verifies the VCT of the SD-JWT-VC. Returns the type metadata format.\n   * @param result\n   * @returns\n   */\n  verifyVct(result) {\n    return __async(this, null, function* () {\n      const typeMetadataFormat = yield this.fetchVct(result);\n      if (typeMetadataFormat.extends) {\n      }\n      return typeMetadataFormat;\n    });\n  }\n  /**\n   * Fetches VCT Metadata of the SD-JWT-VC. Returns the type metadata format. If the SD-JWT-VC does not contain a vct claim, an error is thrown.\n   * @param result\n   * @returns\n   */\n  fetchVct(result) {\n    return __async(this, null, function* () {\n      var _a, _b;\n      if (!result.payload.vct) {\n        throw new import_utils.SDJWTException(\"vct claim is required\");\n      }\n      if ((_a = result.header) == null ? void 0 : _a.vctm) {\n        return this.fetchVctFromHeader(result.payload.vct, result);\n      }\n      const fetcher = (_b = this.userConfig.vctFetcher) != null ? _b : ((uri, integrity) => this.fetch(uri, integrity));\n      return fetcher(result.payload.vct, result.payload[\"vct#Integrity\"]);\n    });\n  }\n  /**\n   * Fetches VCT Metadata from the header of the SD-JWT-VC. Returns the type metadata format. If the SD-JWT-VC does not contain a vct claim, an error is thrown.\n   * @param result\n   * @param\n   */\n  fetchVctFromHeader(vct, result) {\n    return __async(this, null, function* () {\n      var _a;\n      const vctmHeader = (_a = result.header) == null ? void 0 : _a.vctm;\n      if (!vctmHeader || !Array.isArray(vctmHeader)) {\n        throw new Error(\"vctm claim in SD JWT header is invalid\");\n      }\n      const typeMetadataFormat = vctmHeader.map((vctm) => {\n        if (!(typeof vctm === \"string\")) {\n          throw new Error(\"vctm claim in SD JWT header is invalid\");\n        }\n        return JSON.parse((0, import_utils.base64urlDecode)(vctm));\n      }).find((typeMetadataFormat2) => {\n        return typeMetadataFormat2.vct === vct;\n      });\n      if (!typeMetadataFormat) {\n        throw new Error(\"could not find VCT Metadata in JWT header\");\n      }\n      return typeMetadataFormat;\n    });\n  }\n  /**\n   * Verifies the status of the SD-JWT-VC.\n   * @param result\n   * @param options\n   */\n  verifyStatus(result, options) {\n    return __async(this, null, function* () {\n      var _a, _b, _c;\n      if (result.payload.status) {\n        if (result.payload.status.status_list) {\n          const fetcher = (_a = this.userConfig.statusListFetcher) != null ? _a : this.statusListFetcher.bind(this);\n          const statusListJWT = yield fetcher(\n            result.payload.status.status_list.uri\n          );\n          const slJWT = import_core.Jwt.fromEncode(statusListJWT);\n          yield slJWT.verify(\n            (_b = this.userConfig.statusVerifier) != null ? _b : this.userConfig.verifier,\n            options\n          ).catch((err) => {\n            throw new import_jwt_status_list.SLException(\n              `Status List JWT verification failed: ${err.message}`,\n              err.details\n            );\n          });\n          const statusList = (0, import_jwt_status_list.getListFromStatusListJWT)(statusListJWT);\n          const status = statusList.getStatus(\n            result.payload.status.status_list.idx\n          );\n          const statusValidator = (_c = this.userConfig.statusValidator) != null ? _c : this.statusValidator.bind(this);\n          yield statusValidator(status);\n        }\n      }\n    });\n  }\n};\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n  SDJwtVcInstance\n});\n"]}