UNPKG

undersign

Version:

Create eIDAS compatible XAdES digital signatures with certificate OCSP responses and timestamps. Works with the Estonian Id-card and Mobile-Id to create BDOCs, but isn't limited to Estonia.

20 lines (16 loc) 544 B
var PEM_WRAPPER = /^-{5}BEGIN [^-]+-----\s*\n([\s\S]*)\n-----END [^-]+-----\s*$/ exports.parse = function(pem) { var content = PEM_WRAPPER.exec(pem) if (!content) throw new SyntaxError("Cannot parse PEM: " + pem) return Buffer.from(content[1], "base64") } exports.serialize = function(type, buffer) { var encoded = buffer.toString("base64") return `-----BEGIN ${type}-----\n${encoded}\n-----END ${type}-----` } exports.isPem = function(pem) { return ( typeof pem == "string" || Buffer.isBuffer(pem) && /^-----BEGIN/.exec(pem) ) }