UNPKG

@xevolab/jades

Version:

JAdES Digital Signatures compatible with the ETSI TS 119 182-1 Standard

50 lines (49 loc) 1.82 kB
"use strict"; /* * Author : Francesco * Created at: 2024-06-29 21:20 * Edited by : Francesco * Edited at : 2025-03-25 23:22 * * Copyright (c) 2024 Xevolab S.R.L. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var encodeHeaders_1 = __importDefault(require("../utils/encodeHeaders")); var schemas_js_1 = require("../schemas/schemas.js"); /** * This class is used to manage the unprotected headers of a token. * Their validation is handled by the JSON schema. */ var UnprotectedHeaders = /** @class */ (function () { function UnprotectedHeaders(p) { this.header = {}; // Checking the unsigned headers against the schema if present if (Object.keys(p).length > 0) { var validationResult = (0, schemas_js_1.validateUnprotected)(p); if (!validationResult) throw new Error("Invalid JOSE headers; \n-> ".concat(schemas_js_1.validateUnprotected.errors.map(function (error, i) { return "".concat(i, ". ").concat(error.message); }).join(",\n-> "))); } this.header = Object.keys(p).length > 0 ? p : undefined; } /** * Get the unprotected headers of the token. * * @returns {Object} */ UnprotectedHeaders.prototype.getHeaders = function () { if (!this.header) throw new Error("Unprotected headers not set."); return this.header; }; UnprotectedHeaders.prototype.toString = function () { if (!this.header) throw new Error("Unprotected headers not set."); return (0, encodeHeaders_1.default)(this.header); }; return UnprotectedHeaders; }()); exports.default = UnprotectedHeaders; ;