UNPKG

@xevolab/jades

Version:

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

37 lines (36 loc) 1.06 kB
/* * Author : Francesco * Created at: 2023-06-13 20:52 * Edited by : Francesco * Edited at : 2023-06-13 21:41 * * Copyright (c) 2023 Xevolab S.R.L. */ import { createHash } from "crypto"; export function generateX5c(certs) { return certs.map(function (cert) { return cert.raw.toString("base64"); }); } export function generateX5tS256(certs) { return createHash("sha256").update(certs[0].raw).digest("base64url"); } var allowedAlgs = { SHA384: "S384", SHA512: "S512" }; ; export function generateX5o(certs, alg) { if (!allowedAlgs[alg]) throw new Error("Unsupported algorithm: ".concat(alg)); return { digAlg: allowedAlgs[alg], digVal: createHash(alg).update(certs[0].raw).digest("base64url") }; } export function generateX5ts(certs, alg) { if (!allowedAlgs[alg]) throw new Error("Unsupported algorithm: ".concat(alg)); return certs.map(function (cert) { return ({ digAlg: allowedAlgs[alg], digVal: createHash(alg).update(cert.raw).digest("base64url") }); }); }