@xevolab/jades
Version:
JAdES Digital Signatures compatible with the ETSI TS 119 182-1 Standard
45 lines (44 loc) • 1.54 kB
JavaScript
/*
* 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.
*/
import encodeHeaders from "../utils/encodeHeaders";
import { validateUnprotected } from "../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 = validateUnprotected(p);
if (!validationResult)
throw new Error("Invalid JOSE headers; \n-> ".concat(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 encodeHeaders(this.header);
};
return UnprotectedHeaders;
}());
export default UnprotectedHeaders;
;