xml-fiesta
Version:
Electronic signed document XML Protocol for Node & Browser
60 lines • 2.22 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var certificate_1 = require("./certificate");
var errors_1 = require("./errors");
var common_1 = require("./common");
var Signature = (function () {
function Signature(cer, signature, signedAt, email, ePassInfo) {
this.signature = signature;
if (!ePassInfo) {
ePassInfo = {};
}
var content = ePassInfo.content, algorithm = ePassInfo.algorithm, iterations = ePassInfo.iterations, keySize = ePassInfo.keySize;
this.ePassInfo = { algorithm: algorithm, iterations: iterations, keySize: keySize };
this.ePassContent = content;
this.signedAt = signedAt;
this.email = email;
if (!this.signedAt) {
throw new errors_1.ArgumentError('Signature must have signedAt');
}
if (!cer) {
throw new errors_1.ArgumentError('Signature must have cer');
}
this.certificate = new certificate_1.default(null, cer);
if (this.email == null) {
this.email = this.certificate.email();
}
this.signer = {
id: this.certificate.owner_id(),
name: this.certificate.owner(),
email: this.email,
};
}
Signature.prototype.ePass = function (format) {
if ((format === 'hex') || !format) {
return this.ePassContent;
}
if (format === 'base64') {
return common_1.hextoB64(this.ePassContent);
}
throw new errors_1.ArgumentError("unknown format " + format);
};
Signature.prototype.sig = function (format) {
if ((format === 'hex') || !format) {
return this.signature;
}
if (format === 'base64') {
return common_1.hextoB64(this.signature);
}
throw new errors_1.ArgumentError("unknown format " + format);
};
Signature.prototype.valid = function (hash) {
if (!hash) {
throw new errors_1.ArgumentError('hash is required');
}
return this.certificate.verifyString(hash, this.signature);
};
return Signature;
}());
exports.default = Signature;
//# sourceMappingURL=signature.js.map