UNPKG

ctjs

Version:

CTjs is a full set of classes necessary to work with any kind of Certificate Transparency log (V1 as from RFC6962, or V2 as from RFC6962-bis). In CTjs you could find all necessary validation/verification functions for all related data shipped with full-fe

70 lines (60 loc) 2.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseClassSigned = exports.BaseClass = undefined; var _bytestreamjs = require("bytestreamjs"); var _pkijs = require("pkijs"); function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } //************************************************************************************** class BaseClass { //********************************************************************************** constructor() {} //********************************************************************************** /** * Convert current object to SeqStream data * @param {!SeqStream} stream * @returns {boolean} Result of the function */ toStream(stream) { return true; } //********************************************************************************** /** * Converts current class into SeqStream and then return ArrayBuffer from the stream * @return {ArrayBuffer} */ get buffer() { const stream = new _bytestreamjs.SeqStream(); this.toStream(stream); return stream.buffer; } //********************************************************************************** } exports.BaseClass = BaseClass; //************************************************************************************** class BaseClassSigned extends BaseClass { //********************************************************************************** constructor() { super(); this.signature = {}; } //********************************************************************************** /** * Verify existing signature given data block and public key * @param {ArrayBuffer} data The data to be verified against existing signature * @param {PublicKeyInfo} publicKey Public key using for verification * @param {String} [hashName=SHA-256] Name of hashing function, default SHA-256 * @return {Promise<Boolean>} */ verify(data, publicKey, hashName = "SHA-256") { var _this = this; return _asyncToGenerator(function* () { //region Perform verification return (0, _pkijs.getEngine)().subtle.verifyWithPublicKey(data, { valueBlock: { valueHex: _this.signature.toBER(false) } }, publicKey, { algorithmId: "" }, hashName); //endregion })(); } //********************************************************************************** } exports.BaseClassSigned = BaseClassSigned; //************************************************************************************** //# sourceMappingURL=BaseClass.js.map